Example #1
0
        /// <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.");
            }
        }
Example #2
0
 /// <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));
 }