示例#1
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 AnkhConfig();
         SetDefaultsFromRegistry(_instance);
     }
 }
示例#2
0
        /// <summary>
        /// Loads the Ankh configuration file from the given path.
        /// </summary>
        /// <returns>A Config object.</returns>
        public AnkhConfig GetNewConfigInstance()
        {
            AnkhConfig instance = new AnkhConfig();

            SetDefaultsFromRegistry(instance);
            SetSettingsFromRegistry(instance);

            return instance;
        }
示例#3
0
        /// <summary>
        /// Loads the Ankh configuration file from the given path.
        /// </summary>
        /// <returns>A Config object.</returns>
        public AnkhConfig GetNewConfigInstance()
        {
            AnkhConfig instance = new AnkhConfig();

            SetDefaultsFromRegistry(instance);
            SetSettingsFromRegistry(instance);

            return(instance);
        }
示例#4
0
        /// <summary>
        /// Saves the supplied Config object
        /// </summary>
        /// <param name="config"></param>
        public void SaveConfig(AnkhConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            lock (_lock)
            {
                AnkhConfig defaultConfig = new AnkhConfig();
                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
                        {
                            if (value.GetType() == typeof(List <ExtToolDefinition>))
                            {
                                List <ExtToolDefinition> myExtToolList = value as List <ExtToolDefinition>;
                                reg.CreateSubKey(pd.Name);
                                RegistryKey extToolReg = OpenHKCUKey("Configuration");
                                extToolReg = extToolReg.OpenSubKey(pd.Name, true);

                                if (extToolReg != null)
                                {
                                    foreach (string extToolDef in extToolReg.GetValueNames())
                                    {
                                        extToolReg.DeleteValue(extToolDef, false);
                                    }

                                    foreach (ExtToolDefinition extTool in myExtToolList)
                                    {
                                        extToolReg.SetValue(extTool.extension, extTool.exePath);
                                    }
                                }
                            }
                            else
                            {
                                reg.SetValue(pd.Name, pd.Converter.ConvertToInvariantString(value));
                            }
                        }
                    }
                }
            }
        }
示例#5
0
        void SetDefaultsFromRegistry(AnkhConfig config)
        {
            using (RegistryKey reg = OpenHKLMCommonKey("Configuration"))
            {
                if (reg != null)
                {
                    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 { }
                        }
                    }
                }
            }


            using (RegistryKey reg = OpenHKLMKey("Configuration"))
            {
                if (reg != null)
                {
                    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 { }
                        }
                    }
                }
            }
        }
示例#6
0
        void SetSettingsFromRegistry(AnkhConfig 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 { }
                }
            }
        }
示例#7
0
        /// <summary>
        /// Saves the supplied Config object
        /// </summary>
        /// <param name="config"></param>
        public void SaveConfig(AnkhConfig config)
        {
            if (config == null)
                throw new ArgumentNullException("config");

            lock (_lock)
            {
                AnkhConfig defaultConfig = new AnkhConfig();
                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));
                    }
                }
            }
        }
示例#8
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 AnkhConfig();
         SetDefaultsFromRegistry(_instance);
     }
 }
示例#9
0
 void IAnkhConfigurationService.LoadConfig()
 {
     _instance = GetNewConfigInstance();
 }
示例#10
0
 void IAnkhConfigurationService.LoadConfig()
 {
     _instance = GetNewConfigInstance();
 }
示例#11
0
        void SetSettingsFromRegistry(AnkhConfig 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 (pd.Name == "DiffExePaths")
                    {
                        RegistryKey diffRegKey = OpenHKCUKey("Configuration");
                        diffRegKey = diffRegKey.OpenSubKey(pd.Name);

                        if (diffRegKey != null)
                        {
                            config.DiffExePaths.Clear();

                            foreach (string regKeyName in diffRegKey.GetValueNames())
                            {
                                string regValue = diffRegKey.GetValue(regKeyName) as string;

                                try
                                {
                                    ExtToolDefinition extToolDef = new ExtToolDefinition();
                                    extToolDef.extension = regKeyName;
                                    extToolDef.exePath   = regValue;

                                    config.DiffExePaths.Add(extToolDef);
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                    else if (pd.Name == "MergeExePaths")
                    {
                        RegistryKey mergeRegKey = OpenHKCUKey("Configuration");
                        mergeRegKey = mergeRegKey.OpenSubKey(pd.Name);

                        if (mergeRegKey != null)
                        {
                            config.MergeExePaths.Clear();

                            foreach (string regKeyName in mergeRegKey.GetValueNames())
                            {
                                string regValue = mergeRegKey.GetValue(regKeyName) as string;

                                try
                                {
                                    ExtToolDefinition extToolDef = new ExtToolDefinition();
                                    extToolDef.extension = regKeyName;
                                    extToolDef.exePath   = regValue;

                                    config.MergeExePaths.Add(extToolDef);
                                }
                                catch
                                {
                                }
                            }
                        }
                    }


                    else if (value != null)
                    {
                        try
                        {
                            pd.SetValue(config, pd.Converter.ConvertFromInvariantString(value));
                        }
                        catch { }
                    }
                }
            }
        }