diff --git a/src/bin/KSettings.hx b/src/bin/KSettings.hx new file mode 100644 index 0000000..6fa3d08 --- /dev/null +++ b/src/bin/KSettings.hx @@ -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; + }," "); + + 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; + }," "); + + registerSyncSubcommand("list", (args)->{ + handle.writeLine("hostname"); + handle.writeLine("sitecontroller"); + return true; + }); + } +} \ No newline at end of file diff --git a/src/kernel/KernelSettings.hx b/src/kernel/KernelSettings.hx new file mode 100644 index 0000000..788d36e --- /dev/null +++ b/src/kernel/KernelSettings.hx @@ -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 { + 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; + } +}