From a44acae268693fe85998a2d67cf8fa52fb8cd6f5 Mon Sep 17 00:00:00 2001 From: Eric Hocking Date: Tue, 12 Feb 2019 12:04:17 -0500 Subject: [PATCH 1/7] add Settings Interface --- .../Aura OS/System/Utils/ISettings.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Aura Operating System/Aura OS/System/Utils/ISettings.cs diff --git a/Aura Operating System/Aura OS/System/Utils/ISettings.cs b/Aura Operating System/Aura OS/System/Utils/ISettings.cs new file mode 100644 index 000000000..ac8f63474 --- /dev/null +++ b/Aura Operating System/Aura OS/System/Utils/ISettings.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; + +namespace Aura_OS.System.Utils +{ + public interface ISettings + { + void Load(string path); + + void Save(); + + string GetString(string key); + + void SetString(string key, string value); + + bool? GetBool(string key); + + void SetBool(string key, bool value); + + int? GetInt(string key); + + void SetInt(string key, int value); + + long? GetLong(string key); + + void SetLong(string key, long value); + + IDictionary getConfig(); + } +} From 6654f3eacb01db86583f047ed82ee34678816cfa Mon Sep 17 00:00:00 2001 From: Eric Hocking Date: Tue, 12 Feb 2019 12:21:20 -0500 Subject: [PATCH 2/7] add JsonSettings Wrapper --- .../Aura OS/System/Utils/JsonSettings.cs | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 Aura Operating System/Aura OS/System/Utils/JsonSettings.cs diff --git a/Aura Operating System/Aura OS/System/Utils/JsonSettings.cs b/Aura Operating System/Aura OS/System/Utils/JsonSettings.cs new file mode 100644 index 000000000..d471b990b --- /dev/null +++ b/Aura Operating System/Aura OS/System/Utils/JsonSettings.cs @@ -0,0 +1,86 @@ +using System.Collections.Generic; +using System.IO; +using Newtonsoft.Json; + +namespace Aura_OS.System.Utils +{ + public class JsonSettings : ISettings + { + private Dictionary config = new Dictionary(); + private string path; + + public void Load(string path) + { + this.path = path; + + if (Kernel.SystemExists) + { + if (File.Exists(path)) + { + var fileContents = File.ReadAllText(path); + config = JsonConvert.DeserializeObject>(fileContents); + } + } + } + + public void Save() + { + if (Kernel.SystemExists) + { + string json = JsonConvert.SerializeObject(config, Formatting.Indented); + File.WriteAllText(path, json); + } + } + + public string GetString(string key) + { + string value; + if (config.TryGetValue(key, out value)) + { + return value; + } + + return null; + } + + public void SetString(string key, string value) + { + config[key] = value; + } + + public bool? GetBool(string key) + { + return GetString(key) != null ? bool.Parse(GetString(key)) : new bool?(); + } + + public void SetBool(string key, bool value) + { + config[key] = value.ToString(); + } + + public int? GetInt(string key) + { + return GetString(key) != null ? int.Parse(GetString(key)) : new int?(); + } + + public void SetInt(string key, int value) + { + config[key] = value.ToString(); + } + + public long? GetLong(string key) + { + return GetString(key) != null ? long.Parse(GetString(key)) : new long?(); + } + + public void SetLong(string key, long value) + { + config[key] = value.ToString(); + } + + public IDictionary getConfig() + { + return config; + } + } +} From 3ba97f7f207dc877c023af850fd6652cbace9d68 Mon Sep 17 00:00:00 2001 From: Eric Hocking Date: Tue, 12 Feb 2019 13:04:41 -0500 Subject: [PATCH 3/7] Add ConfSettings wrapper Added ConfSettings for support of existing .conf setting files. --- .../Aura OS/System/Utils/ConfSettings.cs | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 Aura Operating System/Aura OS/System/Utils/ConfSettings.cs diff --git a/Aura Operating System/Aura OS/System/Utils/ConfSettings.cs b/Aura Operating System/Aura OS/System/Utils/ConfSettings.cs new file mode 100644 index 000000000..86b3c2690 --- /dev/null +++ b/Aura Operating System/Aura OS/System/Utils/ConfSettings.cs @@ -0,0 +1,131 @@ +using System.Collections.Generic; +using System.Linq; +using System.IO; + +namespace Aura_OS.System.Utils +{ + public class ConfSettings : ISettings + { + + private Dictionary config = new Dictionary(); + private string path; + + public void Load(string path) + { + this.path = path; + + if (Kernel.SystemExists) + { + if (File.Exists(path)) + { + config = File.ReadLines(path).Where(IsConfigurationLine).Select(line => line.Split('=')).ToDictionary(line => line[0], line => line[1]); + } + } + } + + private static bool IsConfigurationLine(string line) + { + return !line.StartsWith("#") && line.Contains("="); + } + + public void Save() + { + if (Kernel.SystemExists) + { + string[] fileContent = File.ReadAllLines(path); + List tempConfig = new List(); + + int counter = -1; + int index = 0; + bool exists = false; + + foreach (string line in fileContent) + { + tempConfig.Add(line); + } + + // loop throuh dictonary + foreach (var setting in config) + { + // see if the current setting exists in the config file + foreach(string element in tempConfig) + { + counter = counter + 1; + if (element.Contains(setting.Key)) + { + index = counter; + exists = true; + } + } + + if (exists) + { + // update the value + tempConfig[index] = setting.Key + "=" + setting.Value; + } + else + { + // add to temp config + tempConfig.Add(setting.Key + "=" + setting.Value); + } + } + + // now update file content and save + fileContent = tempConfig.ToArray(); + File.WriteAllLines(path, fileContent); + } + } + + public string GetString(string key) + { + string value; + if (config.TryGetValue(key, out value)) + { + return value; + } + + return null; + } + + public void SetString(string key, string value) + { + config[key] = value; + } + + public bool? GetBool(string key) + { + return GetString(key) != null ? bool.Parse(GetString(key)) : new bool?(); + } + + public void SetBool(string key, bool value) + { + config[key] = value.ToString(); + } + + public int? GetInt(string key) + { + return GetString(key) != null ? int.Parse(GetString(key)) : new int?(); + } + + public void SetInt(string key, int value) + { + config[key] = value.ToString(); + } + + public long? GetLong(string key) + { + return GetString(key) != null ? long.Parse(GetString(key)) : new long?(); + } + + public void SetLong(string key, long value) + { + config[key] = value.ToString(); + } + + public IDictionary getConfig() + { + return config; + } + + } +} From 64380d6a49674ef2eeecc447bc1b4601b318ce8b Mon Sep 17 00:00:00 2001 From: Eric Hocking Date: Tue, 12 Feb 2019 13:23:47 -0500 Subject: [PATCH 4/7] add XML settings wrapper --- .../Aura OS/System/Utils/XmlSettings.cs | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 Aura Operating System/Aura OS/System/Utils/XmlSettings.cs diff --git a/Aura Operating System/Aura OS/System/Utils/XmlSettings.cs b/Aura Operating System/Aura OS/System/Utils/XmlSettings.cs new file mode 100644 index 000000000..355cf074a --- /dev/null +++ b/Aura Operating System/Aura OS/System/Utils/XmlSettings.cs @@ -0,0 +1,99 @@ +using System.Collections.Generic; +using System.Xml.Linq; +using System.Linq; +using System.IO; + +namespace Aura_OS.System.Utils +{ + class XmlSettings : ISettings + { + private Dictionary config = new Dictionary(); + private string path; + + public void Load(string path) + { + this.path = path; + + if (Kernel.SystemExists) + { + if (File.Exists(path)) + { + XDocument doc = XDocument.Load(path); + + foreach (XElement element in doc.Descendants().Where(p => p.HasElements == false)) + { + int keyInt = 0; + string keyName = element.Name.LocalName; + + while (config.ContainsKey(keyName)) + { + keyName = element.Name.LocalName + "_" + keyInt++; + } + + config[keyName] = element.Value; + } + } + } + } + + public void Save() + { + if (Kernel.SystemExists) + { + XElement settings = new XElement("settings", config.Select(setting => new XElement(setting.Key, setting.Value))); + settings.Save(path); + } + } + + public string GetString(string key) + { + string value; + if (config.TryGetValue(key, out value)) + { + return value; + } + + return null; + } + + public void SetString(string key, string value) + { + config[key] = value; + } + + public bool? GetBool(string key) + { + return GetString(key) != null ? bool.Parse(GetString(key)) : new bool?(); + } + + public void SetBool(string key, bool value) + { + config[key] = value.ToString(); + } + + public int? GetInt(string key) + { + return GetString(key) != null ? int.Parse(GetString(key)) : new int?(); + } + + public void SetInt(string key, int value) + { + config[key] = value.ToString(); + } + + public long? GetLong(string key) + { + return GetString(key) != null ? long.Parse(GetString(key)) : new long?(); + } + + public void SetLong(string key, long value) + { + config[key] = value.ToString(); + } + + public IDictionary getConfig() + { + return config; + } + } +} From 7e795565350e2644aae1da2ac5a79fbe6709e62d Mon Sep 17 00:00:00 2001 From: Eric Hocking Date: Tue, 12 Feb 2019 13:27:30 -0500 Subject: [PATCH 5/7] add Lang class to load a language file --- .../Aura OS/System/Translation/Lang.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Aura Operating System/Aura OS/System/Translation/Lang.cs diff --git a/Aura Operating System/Aura OS/System/Translation/Lang.cs b/Aura Operating System/Aura OS/System/Translation/Lang.cs new file mode 100644 index 000000000..985936c32 --- /dev/null +++ b/Aura Operating System/Aura OS/System/Translation/Lang.cs @@ -0,0 +1,47 @@ +using System.Collections.Generic; +using System.Linq; +using System.IO; + +namespace Aura_OS.System.Translation +{ + public class Lang + { + public Dictionary lines = new Dictionary(); + + private string name; + private string path; + + public Lang(string name) + { + this.name = name; + path = @"0:\System\langs\" + name + ".conf"; + + if (Kernel.SystemExists) + { + if (File.Exists(path)) + { + Load(); + } + } + } + + public void Load() + { + lines = File.ReadLines(this.path).Where(IsConfigurationLine).Select(line => line.Split('=')).ToDictionary(line => line[0], line => line[1]); + } + + private static bool IsConfigurationLine(string line) + { + return !line.StartsWith("#") && line.Contains("="); + } + + public string Get(string line) + { + string value; + if (lines.TryGetValue(line, out value)) { + return value; + } else { + return null; + } + } + } From 7d70af22803157cb4acd6f9a016cd3e3578424d5 Mon Sep 17 00:00:00 2001 From: Eric Hocking Date: Tue, 12 Feb 2019 13:28:47 -0500 Subject: [PATCH 6/7] add in a language manager class --- .../Aura OS/System/Translation/LangManager.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Aura Operating System/Aura OS/System/Translation/LangManager.cs diff --git a/Aura Operating System/Aura OS/System/Translation/LangManager.cs b/Aura Operating System/Aura OS/System/Translation/LangManager.cs new file mode 100644 index 000000000..21f7da188 --- /dev/null +++ b/Aura Operating System/Aura OS/System/Translation/LangManager.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; + +namespace Aura_OS.System.Translation +{ + public class LangManager + { + private Dictionary Languages = new Dictionary(); + + private string DefaultLang = "en_US"; + + public void addLang(string name, Lang lang) + { + if (!Languages.ContainsKey(name)) + { + Languages.Add(name, lang); + } + } + + public Lang GetLang(string name) + { + Lang value; + if (Languages.TryGetValue(name, out value)) + { + return value; + } + else + { + return Languages[DefaultLang]; + } + } + + public Dictionary getLangs() + { + return Languages; + } + } +} From 9ac9a02c78d11a6d0e8897213c56afbcceb39872 Mon Sep 17 00:00:00 2001 From: Eric Hocking Date: Tue, 12 Feb 2019 13:39:25 -0500 Subject: [PATCH 7/7] update kernal to load languages --- Aura Operating System/Aura OS/Kernel.cs | 28 +++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/Aura Operating System/Aura OS/Kernel.cs b/Aura Operating System/Aura OS/Kernel.cs index 611448a69..982c95f6d 100644 --- a/Aura Operating System/Aura OS/Kernel.cs +++ b/Aura Operating System/Aura OS/Kernel.cs @@ -10,7 +10,7 @@ using System; using Cosmos.System.FileSystem; using Sys = Cosmos.System; -using Lang = Aura_OS.System.Translation; +using Aura_OS.System.Translation; using Aura_OS.System; using Aura_OS.System.Users; using Aura_OS.System.Computer; @@ -44,6 +44,7 @@ public class Kernel : Sys.Kernel public static bool Logged = false; public static string ComputerName = "aura-pc"; public static string UserDir = @"0:\Users\" + userLogged + "\\"; + public static string SystemDir = @"0:\System\"; public static bool SystemExists = false; public static bool JustInstalled = false; public static CosmosVFS vFS = new CosmosVFS(); @@ -55,7 +56,8 @@ public class Kernel : Sys.Kernel public static Config LocalNetworkConfig; public static Debugger debugger; public static string current_volume = @"0:\"; - + public static LangManager Lang = new LangManager(); + #endregion #region Before Run @@ -74,8 +76,11 @@ protected override void BeforeRun() { try { + // initialize languages we support + addLanguages(); + CommandManager.RegisterAllCommands(); - + //AConsole = new System.Shell.VGA.VGAConsole(null); Encoding.RegisterProvider(CosmosEncodingProvider.Instance); @@ -114,12 +119,12 @@ protected override void BeforeRun() if (!JustInstalled) { - Settings config = new Settings(@"0:\System\settings.conf"); + Settings config = new Settings("settings.conf"); langSelected = config.GetValue("language"); #region Language - - Lang.Keyboard.Init(); + + Keyboard.Init(); #endregion @@ -145,6 +150,17 @@ protected override void BeforeRun() Crash.StopKernel(ex); } } + + /// + /// Adds all the languages that we support + /// + protected void addLanguages() + { + Lang.addLang("en_US", new Lang("en_US")); + Lang.addLang("fr_FR", new Lang("fr_FR")); + Lang.addLang("nl_NL", new Lang("nl_NL")); + Lang.addLang("it_IT", new Lang("it_IT")): + } #endregion