From 6f3a5cba2ea08ea6f442e2336b74f32f4bbc0604 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 2 Jul 2017 21:48:10 -0400 Subject: A day's worth of hell... which is turning into heaven. --- ShiftOS_TheReturn/Desktop.cs | 9 +++- ShiftOS_TheReturn/Localization.cs | 105 ++++++++++++++++++++------------------ 2 files changed, 64 insertions(+), 50 deletions(-) (limited to 'ShiftOS_TheReturn') diff --git a/ShiftOS_TheReturn/Desktop.cs b/ShiftOS_TheReturn/Desktop.cs index fac5e6b..714d457 100644 --- a/ShiftOS_TheReturn/Desktop.cs +++ b/ShiftOS_TheReturn/Desktop.cs @@ -246,7 +246,14 @@ namespace ShiftOS.Engine public static void InvokeOnWorkerThread(Action act) { - _desktop.InvokeOnWorkerThread(act); + try + { + _desktop.InvokeOnWorkerThread(act); + } + catch + { + act?.Invoke(); + } } public static void ResetPanelButtons() diff --git a/ShiftOS_TheReturn/Localization.cs b/ShiftOS_TheReturn/Localization.cs index 8adfa5a..2414bd9 100644 --- a/ShiftOS_TheReturn/Localization.cs +++ b/ShiftOS_TheReturn/Localization.cs @@ -99,63 +99,65 @@ namespace ShiftOS.Engine public static string Parse(string original, Dictionary replace) { - Dictionary localizationStrings = new Dictionary(); - - try { - localizationStrings = JsonConvert.DeserializeObject>(_provider.GetCurrentTranscript()); - } - catch - { - localizationStrings = JsonConvert.DeserializeObject>(Utils.ReadAllText(Paths.GetPath("english.local"))); //if no provider fall back to english - } - - foreach (var kv in localizationStrings.Where(x=>original.Contains(x.Key))) - { - original = original.Replace(kv.Key, kv.Value); // goes through and replaces all the localization blocks - } + Dictionary localizationStrings = new Dictionary(); - //string original2 = Parse(original); - string usernameReplace = ""; - string domainReplace = ""; - - // if the user has saved then store their username and systemname in these string variables please - if (SaveSystem.CurrentSave != null) - { try { - usernameReplace = SaveSystem.CurrentUser.Username; + localizationStrings = JsonConvert.DeserializeObject>(_provider.GetCurrentTranscript()); } catch { - usernameReplace = "user"; + localizationStrings = JsonConvert.DeserializeObject>(Utils.ReadAllText(Paths.GetPath("english.local"))); //if no provider fall back to english } - try + foreach (var kv in localizationStrings.Where(x => original.Contains(x.Key))) { - domainReplace = SaveSystem.CurrentSave.SystemName; + original = original.Replace(kv.Key, kv.Value); // goes through and replaces all the localization blocks } - catch + + //string original2 = Parse(original); + + string usernameReplace = ""; + string domainReplace = ""; + + // if the user has saved then store their username and systemname in these string variables please + if (SaveSystem.CurrentSave != null) { - domainReplace = "system"; + try + { + usernameReplace = SaveSystem.CurrentUser.Username; + } + catch + { + usernameReplace = "user"; + } + + try + { + domainReplace = SaveSystem.CurrentSave.SystemName; + } + catch + { + domainReplace = "system"; + } + } - - } - string namespaceReplace = ""; - string commandReplace = ""; + string namespaceReplace = ""; + string commandReplace = ""; - // if the user did a command in the terminal and it had a period in it then split it up into the part before the period and the part after and then store them into these two string variables please - if (TerminalBackend.latestCommmand != "" && TerminalBackend.latestCommmand.IndexOf('.') > -1) - { - namespaceReplace = TerminalBackend.latestCommmand.Split('.')[0]; - commandReplace = TerminalBackend.latestCommmand.Split('.')[1]; - } + // if the user did a command in the terminal and it had a period in it then split it up into the part before the period and the part after and then store them into these two string variables please + if (TerminalBackend.latestCommmand != "" && TerminalBackend.latestCommmand.IndexOf('.') > -1) + { + namespaceReplace = TerminalBackend.latestCommmand.Split('.')[0]; + commandReplace = TerminalBackend.latestCommmand.Split('.')[1]; + } - // if you see these then replace them with what you need to - Dictionary defaultReplace = new Dictionary() { + // if you see these then replace them with what you need to + Dictionary defaultReplace = new Dictionary() { {"%username", usernameReplace}, {"%domain", domainReplace}, {"%ns", namespaceReplace}, @@ -165,19 +167,24 @@ namespace ShiftOS.Engine #endif }; - // actually do the replacement - foreach (KeyValuePair replacement in replace.Where(x => original.Contains(x.Key))) - { - original = original.Replace(replacement.Key, Parse(replacement.Value)); - } + // actually do the replacement + foreach (KeyValuePair replacement in replace.Where(x => original.Contains(x.Key))) + { + original = original.Replace(replacement.Key, Parse(replacement.Value)); + } + + // do the replacement but default + foreach (KeyValuePair replacement in defaultReplace.Where(x => original.Contains(x.Key))) + { + original = original.Replace(replacement.Key, replacement.Value); + } - // do the replacement but default - foreach (KeyValuePair replacement in defaultReplace.Where(x => original.Contains(x.Key))) + return original; // returns the now replaced string + } + catch { - original = original.Replace(replacement.Key, replacement.Value); + return original; } - - return original; // returns the now replaced string } // a few things are defined here -- cgit v1.2.3