From 145a1622f03feeba3266304e198ca1a10249b651 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 9 Jul 2018 14:35:22 -0400 Subject: [PATCH] Brute force config saving --- TGS.Server/Instance/Chat.cs | 19 +++++++++++++------ TGS.Server/Instance/Compiler.cs | 1 + TGS.Server/Instance/DreamDaemon.cs | 4 ++++ TGS.Server/Instance/Repository.cs | 4 ++++ TGS.Server/InstanceConfig.cs | 4 +++- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/TGS.Server/Instance/Chat.cs b/TGS.Server/Instance/Chat.cs index 75ebc44ea6..205241bfd4 100644 --- a/TGS.Server/Instance/Chat.cs +++ b/TGS.Server/Instance/Chat.cs @@ -102,20 +102,23 @@ namespace TGS.Server /// Properly shuts down all /// void DisposeChat() + { + SaveChatConfig(); + foreach (var ChatProvider in ChatProviders) + ChatProvider.Dispose(); + ChatProviders = null; + } + + void SaveChatConfig() { var infosList = new List>(); foreach (var ChatProvider in ChatProviders) - { infosList.Add(ChatProvider.ProviderInfo().DataFields); - ChatProvider.Dispose(); - } - ChatProviders = null; - var rawdata = JsonConvert.SerializeObject(infosList, Formatting.Indented); - Config.ChatProviderData = Interface.Helpers.EncryptData(rawdata, out string entrp); Config.ChatProviderEntropy = entrp; + Config.Save(); } /// @@ -166,6 +169,7 @@ namespace TGS.Server catch { Config.ChatProviderData = UninitializedString; + Config.Save(); } } //if we get here we want to retry @@ -186,7 +190,10 @@ namespace TGS.Server { foreach (var ChatProvider in ChatProviders) if (info.Provider == ChatProvider.ProviderInfo().Provider) + { + SaveChatConfig(); return ChatProvider.SetProviderInfo(info); + } return "Error: Invalid provider: " + info.Provider.ToString(); } } diff --git a/TGS.Server/Instance/Compiler.cs b/TGS.Server/Instance/Compiler.cs index db03e40940..3596a1068a 100644 --- a/TGS.Server/Instance/Compiler.cs +++ b/TGS.Server/Instance/Compiler.cs @@ -663,6 +663,7 @@ namespace TGS.Server lock (CompilerLock) { Config.ProjectName = projectName; + Config.Save(); } } diff --git a/TGS.Server/Instance/DreamDaemon.cs b/TGS.Server/Instance/DreamDaemon.cs index e59b1d4f27..69b03306df 100644 --- a/TGS.Server/Instance/DreamDaemon.cs +++ b/TGS.Server/Instance/DreamDaemon.cs @@ -237,6 +237,7 @@ namespace TGS.Server lock (watchdogLock) { Config.Port = new_port; + Config.Save(); RequestRestart(); } } @@ -665,6 +666,7 @@ namespace TGS.Server { needReboot = Config.Security != level; Config.Security = level; + Config.Save(); } if (needReboot) RequestRestart(); @@ -681,6 +683,7 @@ namespace TGS.Server public void SetAutostart(bool on) { Config.Autostart = on; + Config.Save(); } /// @@ -757,6 +760,7 @@ namespace TGS.Server if (diff) { Config.Webclient = on; + Config.Save(); RequestRestart(); } } diff --git a/TGS.Server/Instance/Repository.cs b/TGS.Server/Instance/Repository.cs index a36eda4bb1..df92b1a5a2 100644 --- a/TGS.Server/Instance/Repository.cs +++ b/TGS.Server/Instance/Repository.cs @@ -1093,6 +1093,7 @@ namespace TGS.Server public void SetCommitterName(string newName) { Config.CommitterName = newName; + Config.Save(); } /// @@ -1105,6 +1106,7 @@ namespace TGS.Server public void SetCommitterEmail(string newEmail) { Config.CommitterEmail = newEmail; + Config.Save(); } /// @@ -1403,6 +1405,7 @@ namespace TGS.Server } } Config.AutoUpdateInterval = newInterval; + Config.Save(); } /// @@ -1458,6 +1461,7 @@ namespace TGS.Server public void SetPushTestmergeCommits(bool newValue) { Config.PushTestmergeCommits = newValue; + Config.Save(); } } } diff --git a/TGS.Server/InstanceConfig.cs b/TGS.Server/InstanceConfig.cs index e64f8edec3..5cf13fcaf0 100644 --- a/TGS.Server/InstanceConfig.cs +++ b/TGS.Server/InstanceConfig.cs @@ -218,7 +218,9 @@ namespace TGS.Server /// public void Save() { - var data = JsonConvert.SerializeObject(this, Formatting.Indented); + string data; + lock(this) + data = JsonConvert.SerializeObject(this, Formatting.Indented); var path = Path.Combine(Directory, JSONFilename); File.WriteAllText(path, data); }