added kernel settings

This commit is contained in:
Djeeberjr 2023-06-07 21:29:10 +02:00
parent 86793bfdc1
commit 6fcbcfce8d
2 changed files with 123 additions and 0 deletions

67
src/bin/KSettings.hx Normal file
View File

@ -0,0 +1,67 @@
package bin;
import kernel.KernelSettings;
import lib.CLIAppBase;
class KSettings extends CLIAppBase {
public function new() {
registerSyncSubcommand("get", (args)->{
var key = args[0];
if (key == null) {
handle.writeLine("Key not specified");
return false;
}
var value = switch (key){
case "hostname":
KernelSettings.hostname;
case "sitecontroller":
Std.string(KernelSettings.siteController);
default:
null;
}
if (value == null) {
handle.writeLine("Key not found or not set");
return false;
}
handle.writeLine(value);
return true;
}," <key>");
registerSyncSubcommand("set", (args)->{
var key = args[0];
if (key == null) {
handle.writeLine("Key not specified");
return false;
}
var value = args[1];
if (value == null) {
handle.writeLine("Value not specified");
return false;
}
switch (key){
case "hostname":
KernelSettings.hostname = value;
case "sitecontroller":
KernelSettings.siteController = Std.parseInt(value);
default:
handle.writeLine("Key not found");
return false;
}
return true;
}," <key> <value>");
registerSyncSubcommand("list", (args)->{
handle.writeLine("hostname");
handle.writeLine("sitecontroller");
return true;
});
}
}

View File

@ -0,0 +1,56 @@
package kernel;
import cc.OS;
import kernel.net.Package.NetworkID;
import lib.KVStore;
import cc.Settings;
class KernelSettings {
private static inline function setAllowStartup(value: Bool) {
Settings.set("shell.allow_startup", value);
}
private static inline function setAllowStartupFromFloppy(value: Bool) {
Settings.set("shell.allow_disk_startup", value);
}
private static function set(name: String, value: Dynamic) {
var kvstore = new KVStore("kernel");
kvstore.set(name, value);
kvstore.save();
}
private static function get(name: String): Null<Dynamic> {
var kvstore = new KVStore("kernel");
return kvstore.get(name);
}
public static var hostname(get,set): String;
private static var _hostname:String = get("hostname");
private static inline function get_hostname():String {
return _hostname;
}
private static inline function set_hostname(value:String):String {
OS.setComputerLabel(value);
set("hostname", value);
_hostname = value;
return value;
}
public static var siteController(get,set): NetworkID;
private static var _siteController:NetworkID = get("siteController");
private static function get_siteController():NetworkID {
return _siteController;
}
private static function set_siteController(value:NetworkID):NetworkID {
if (value == null) {
return get_siteController();
}
set("siteController", value);
_siteController = value;
return value;
}
}