Example #1
0
        void SetSettingsFromRegistry(VisualGitConfig config)
        {
            using (RegistryKey reg = OpenHKCUKey("Configuration"))
            {
                if (reg == null)
                    return;

                foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(config))
                {
                    string value = reg.GetValue(pd.Name, null) as string;

                    if (value != null)
                        try
                        {
                            pd.SetValue(config, pd.Converter.ConvertFromInvariantString(value));
                        }
                        catch { }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Saves the supplied Config object
        /// </summary>
        /// <param name="config"></param>
        public void SaveConfig(VisualGitConfig config)
        {
            if (config == null)
                throw new ArgumentNullException("config");

            lock (_lock)
            {
                VisualGitConfig defaultConfig = new VisualGitConfig();
                SetDefaultsFromRegistry(defaultConfig);

                using (RegistryKey reg = OpenHKCUKey("Configuration"))
                {
                    PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(defaultConfig);
                    foreach (PropertyDescriptor pd in pdc)
                    {
                        object value = pd.GetValue(config);

                        // Set the value only if it is already set previously, or if it's different from the default
                        if (!pd.ShouldSerializeValue(config) && !pd.ShouldSerializeValue(defaultConfig))
                        {
                            reg.DeleteValue(pd.Name, false);
                        }
                        else
                            reg.SetValue(pd.Name, pd.Converter.ConvertToInvariantString(value));
                    }
                }
            }
        }
Example #3
0
 void IVisualGitConfigurationService.LoadConfig()
 {
     _instance = GetNewConfigInstance();
 }
Example #4
0
 /// <summary>
 /// Loads the default config file. Used as a fallback if the
 /// existing config file cannot be loaded.
 /// </summary>
 /// <returns></returns>
 public void LoadDefaultConfig()
 {
     lock (_lock)
     {
         _instance = new VisualGitConfig();
         SetDefaultsFromRegistry(_instance);
     }
 }
Example #5
0
        /// <summary>
        /// Loads the VisualGit configuration file from the given path.
        /// </summary>
        /// <returns>A Config object.</returns>
        public VisualGitConfig GetNewConfigInstance()
        {
            VisualGitConfig instance = new VisualGitConfig();

            SetDefaultsFromRegistry(instance);
            SetSettingsFromRegistry(instance);

            return instance;
        }