public void ResetConsoleProperties(bool usePerAppSettings = true)
        {
            Dictionary <string, ConsoleSettings> allConsoleSettings = ConsoleSettings.GetPerAppSettings();
            string appKeyName = Target.Replace("\\", "_");

            if (usePerAppSettings && allConsoleSettings.ContainsKey(appKeyName))
            {
                ConsoleProperties = allConsoleSettings[appKeyName].ToConsoleProperties();
            }
            else
            {
                ConsoleProperties = allConsoleSettings["DEFAULT"].ToConsoleProperties();
            }
        }
Exemple #2
0
        public static Dictionary <string, ConsoleSettings> GetPerAppSettings()
        {
            ConsoleSettings defaultSettings = GetDefaultSettings();
            Dictionary <string, ConsoleSettings> allConsoleSettings = new Dictionary <string, ConsoleSettings>(StringComparer.OrdinalIgnoreCase)
            {
                { "DEFAULT", defaultSettings }
            };
            RegistryKey consoleKey = Registry.CurrentUser.OpenSubKey(DEFAULT_CONSOLE_KEY);

            foreach (string subKeyName in consoleKey.GetSubKeyNames())
            {
                ConsoleSettings appSettings = GetSettings(String.Format(@"{0}\{1}", DEFAULT_CONSOLE_KEY, subKeyName), defaultSettings);
                allConsoleSettings.Add(subKeyName, appSettings);
            }

            consoleKey.Close();
            return(allConsoleSettings);
        }
Exemple #3
0
        private static ConsoleSettings GetSettings(string keyPath, ConsoleSettings defaultSettings = null)
        {
            ConsoleSettings consoleSettings = new ConsoleSettings();
            RegistryKey     registryKey     = Registry.CurrentUser.OpenSubKey(keyPath);

            foreach (PropertyInfo property in typeof(ConsoleSettings).GetProperties())
            {
                var registryValue = registryKey.GetValue(property.Name);
                if (registryValue != null)
                {
                    if (property.PropertyType.Equals(typeof(Coordinate)))
                    {
                        Coordinate coord = new Coordinate((short)((int)registryValue & 0x0000FFFF), (short)((int)registryValue >> 16));
                        property.SetValue(consoleSettings, coord);
                    }
                    else
                    {
                        property.SetValue(consoleSettings, Convert.ChangeType(registryValue, property.PropertyType));
                    }
                }
                else if (defaultSettings != null)
                {
                    property.SetValue(consoleSettings, property.GetValue(defaultSettings));
                }
            }

            for (int i = 0; i < COLOR_TABLE_SIZE; i++)
            {
                var registryValue = registryKey.GetValue(String.Format("ColorTable{0:D2}", i));
                if (registryValue != null)
                {
                    consoleSettings.ColorTable[i] = (uint)Convert.ChangeType(registryValue, typeof(uint));
                }
                else if (defaultSettings != null)
                {
                    consoleSettings.ColorTable[i] = defaultSettings.ColorTable[i];
                }
            }

            registryKey.Close();
            return(consoleSettings);
        }