/// <summary> /// Loads from registry /// </summary> /// <param name="appname"></param> /// <param name="provideDefaults"></param> /// <returns></returns> public static Settings FromRegistry(string appname, bool provideDefaults = true) { Reg.SubKey = RegistrySubKeyBase + appname; try { var data = Reg.Read("settings"); if (data == null) { return(provideDefaults ? Default : null); } return(JsonConvert.DeserializeObject <Settings>(Reg.Read("settings"))); } catch { if (provideDefaults) { return(Default); } throw new System.Exception("Failed to deserialize settings from registry."); } }
/// <summary> /// saves settings to registry for later /// </summary> /// <param name="appname"></param> public void SaveToRegistry(string appname) { Reg.SubKey = RegistrySubKeyBase + appname; Reg.Write("settings", JsonConvert.SerializeObject(this)); }