public void Save() { var cfg = JsonConvert.SerializeObject(Properties); File.WriteAllText(CfgPath, cfg); OnConfigSaved?.Invoke(); }
public bool Save() // Returns true if no correction was needed { bool correctionMade = false; // Invite Message if (string.IsNullOrEmpty(Data.EcoBotName)) { Data.EcoBotName = DefaultValues.EcoBotName; correctionMade = true; } // Discord Command Prefix if (Data.DiscordCommandPrefix != _prevConfig.DiscordCommandPrefix) { if (string.IsNullOrEmpty(Data.DiscordCommandPrefix)) { Data.DiscordCommandPrefix = DefaultValues.DiscordCommandPrefix; correctionMade = true; Logger.Info("Command prefix found empty - Resetting to default."); } Logger.Info("Command prefix changed - Restart required to take effect."); } // Channel Links foreach (ChannelLink link in _channelLinks) { if (link.MakeCorrections()) { correctionMade = true; } } // Chatlog toggle if (Data.LogChat && !_prevConfig.LogChat) { Logger.Info("Chatlog enabled"); OnChatlogEnabled?.Invoke(this, EventArgs.Empty); } else if (!Data.LogChat && _prevConfig.LogChat) { Logger.Info("Chatlog disabled"); OnChatlogDisabled?.Invoke(this, EventArgs.Empty); } // Chatlog path if (string.IsNullOrEmpty(Data.ChatlogPath)) { Data.ChatlogPath = DiscordLink.BasePath + "Chatlog.txt"; correctionMade = true; } if (Data.ChatlogPath != _prevConfig.ChatlogPath) { Logger.Info("Chatlog path changed. New path: " + Data.ChatlogPath); OnChatlogPathChanged?.Invoke(this, EventArgs.Empty); } // Eco command channel if (string.IsNullOrEmpty(Data.EcoCommandChannel)) { Data.EcoCommandChannel = DefaultValues.EcoCommandChannel; correctionMade = true; } // Invite Message if (string.IsNullOrEmpty(Data.InviteMessage)) { Data.InviteMessage = DefaultValues.InviteMessage; correctionMade = true; } _config.SaveAsync(); OnConfigSaved?.Invoke(this, EventArgs.Empty); _prevConfig = (DLConfigData)Data.Clone(); return(!correctionMade); }
public void SaveConfig() { Settings.SaveToFile(Application.persistentDataPath + configFile); OnConfigSaved?.Invoke(); }
public bool Save() // Returns true if no correction was needed { bool correctionMade = false; // Eco Bot Name if (string.IsNullOrEmpty(Data.EcoBotName)) { Data.EcoBotName = DefaultValues.EcoBotName; correctionMade = true; } // Discord Command Prefix if (Data.DiscordCommandPrefix != _prevConfig.DiscordCommandPrefix) { if (string.IsNullOrEmpty(Data.DiscordCommandPrefix)) { Data.DiscordCommandPrefix = DefaultValues.DiscordCommandPrefix; correctionMade = true; Logger.Info("Command prefix found empty - Resetting to default."); } Logger.Info("Command prefix changed - Restart required to take effect."); } // Channel Links foreach (ChannelLink link in _channelLinks) { if (link.MakeCorrections()) { correctionMade = true; } } // Chatlog toggle if (Data.LogChat && !_prevConfig.LogChat) { Logger.Info("Chatlog enabled"); OnChatlogEnabled?.Invoke(this, EventArgs.Empty); } else if (!Data.LogChat && _prevConfig.LogChat) { Logger.Info("Chatlog disabled"); OnChatlogDisabled?.Invoke(this, EventArgs.Empty); } // Chatlog path if (string.IsNullOrEmpty(Data.ChatlogPath)) { Data.ChatlogPath = DLConstants.BasePath + "Chatlog.txt"; correctionMade = true; } if (Data.ChatlogPath != _prevConfig.ChatlogPath) { Logger.Info("Chatlog path changed. New path: " + Data.ChatlogPath); OnChatlogPathChanged?.Invoke(this, EventArgs.Empty); } // Eco command channel if (string.IsNullOrEmpty(Data.EcoCommandOutputChannel)) { Data.EcoCommandOutputChannel = DefaultValues.EcoCommandOutputChannel; correctionMade = true; } // Max tracked trades per user if (Data.MaxTrackedTradesPerUser < 0) { Data.MaxTrackedTradesPerUser = DLConfig.DefaultValues.MaxTrackedTradesPerUser; } // Invite Message if (string.IsNullOrEmpty(Data.InviteMessage)) { Data.InviteMessage = DefaultValues.InviteMessage; correctionMade = true; } // Currency channels foreach (CurrencyChannelLink link in Data.CurrencyChannels) { if (link.MaxMintedCount < 0) { link.MaxMintedCount = DefaultValues.MaxMintedCurrencies; correctionMade = true; } if (link.MaxPersonalCount < 0) { link.MaxPersonalCount = DefaultValues.MaxPersonalCurrencies; correctionMade = true; } if (link.MaxTopCurrencyHolderCount < 0 || link.MaxTopCurrencyHolderCount > DLConstants.MAX_TOP_CURRENCY_HOLDER_DISPLAY_LIMIT) { link.MaxTopCurrencyHolderCount = DefaultValues.MaxTopCurrencyHolderCount; correctionMade = true; } } _config.SaveAsync(); OnConfigSaved?.Invoke(this, EventArgs.Empty); _prevConfig = (DLConfigData)Data.Clone(); return(!correctionMade); }