/// <summary> /// Save config to path /// </summary> /// <param name="cfg"></param> public void Save(Config cfg) { if(cfg!=null) { string str = JsonConvert.SerializeObject(cfg, Formatting.Indented); try { File.WriteAllText(path, str, Encoding.UTF8); } catch (Exception ex) { Debug.WriteLine(ex) ; } } }
/// <summary> /// Load config /// </summary> /// <returns></returns> public Config Load() { Config cfg = new Config(); if (File.Exists(path)) { try { string str = File.ReadAllText(path, Encoding.UTF8); cfg = JsonConvert.DeserializeObject<Config>(str); } catch (Exception ex) { Debug.WriteLine(ex); } } return cfg; }