added kernel settings
This commit is contained in:
parent
86793bfdc1
commit
6fcbcfce8d
67
src/bin/KSettings.hx
Normal file
67
src/bin/KSettings.hx
Normal 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;
|
||||
});
|
||||
}
|
||||
}
|
56
src/kernel/KernelSettings.hx
Normal file
56
src/kernel/KernelSettings.hx
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user