public static void Save(Configuration config) { config.version = UpdateChecker.Version; if (config.index >= config.configs.Count) { config.index = config.configs.Count - 1; } if (config.index < -1) { config.index = -1; } if (config.index == -1 && config.strategy == null) { config.index = 0; } config.isDefault = false; try { using (StreamWriter sw = new StreamWriter(File.Open(ConfigPath.Load() + CONFIG_FILE, FileMode.Create))) { string jsonString = JsonConvert.SerializeObject(config, Formatting.Indented); sw.Write(jsonString); sw.Flush(); } } catch (IOException e) { Logging.LogUsefulException(e); } }
public static void Save(StatisticsStrategyConfiguration configuration) { try { var content = JsonConvert.SerializeObject(configuration, Formatting.Indented); File.WriteAllText(ConfigPath.Load() + ConfigFile, content); } catch (Exception e) { Logging.LogUsefulException(e); } }
public static StatisticsStrategyConfiguration Load() { try { var content = File.ReadAllText(ConfigPath.Load() + ConfigFile); var configuration = JsonConvert.DeserializeObject <StatisticsStrategyConfiguration>(content); return(configuration); } catch (FileNotFoundException) { var configuration = new StatisticsStrategyConfiguration(); Save(configuration); return(configuration); } catch (Exception e) { Logging.LogUsefulException(e); return(new StatisticsStrategyConfiguration()); } }
public static Configuration Load() { try { string configContent = File.ReadAllText(ConfigPath.Load() + CONFIG_FILE); Configuration config = JsonConvert.DeserializeObject <Configuration>(configContent); config.isDefault = false; if (config.configs == null) { config.configs = new List <Server>(); } if (config.configs.Count == 0) { config.configs.Add(GetDefaultServer()); } if (config.localPort == 0) { config.localPort = 1080; } if (config.index == -1 && config.strategy == null) { config.index = 0; } if (config.logViewer == null) { config.logViewer = new LogViewerConfig(); } if (config.proxy == null) { config.proxy = new ProxyConfig(); } if (config.hotkey == null) { config.hotkey = new HotkeyConfig(); } config.proxy.CheckConfig(); return(config); } catch (Exception e) { if (!(e is FileNotFoundException)) { Logging.LogUsefulException(e); } return(new Configuration { index = 0, isDefault = true, localPort = 1080, autoCheckUpdate = true, configs = new List <Server>() { GetDefaultServer() }, logViewer = new LogViewerConfig(), proxy = new ProxyConfig(), hotkey = new HotkeyConfig() }); } }