public static void LoadConfigFromFile() { var dir = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (string.IsNullOrWhiteSpace(dir)) { return; } var filePath = Path.Combine(dir, ConfigFileName); if (!File.Exists(filePath)) { return; } var str = HttpHandlers.WriteSafeReadAllLines(filePath); if (!string.IsNullOrWhiteSpace(str)) { //var a = JObject.Parse(str); //var url = (string) a["serverUrl"]; //if (!string.IsNullOrWhiteSpace(url)) //{ // ServerUrl = url; //} var des = (ProgramConfigJSON)JsonConvert.DeserializeObject(str, typeof(ProgramConfigJSON)); configJSON = des; ServerUrl = configJSON.serverURL; if (!string.IsNullOrWhiteSpace(configJSON.account)) { Account = configJSON.account; } if (!string.IsNullOrWhiteSpace(configJSON.password)) { Password = configJSON.password; } } }
public static void SaveConfig2File() { if (configJSON == null) { configJSON = new ProgramConfigJSON(); } configJSON.serverURL = ServerUrl; var str = JsonConvert.SerializeObject(configJSON, Formatting.Indented); var dir = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (string.IsNullOrWhiteSpace(dir)) { return; } var filePath = Path.Combine(dir, ConfigFileName); File.WriteAllText(filePath, str); }