private static WDSwapConfiguration GetDefault()
        {
            var result = new WDSwapConfiguration();

            result.FocusedDesktopColors.Background = "#FAFAFA";
            result.FocusedDesktopColors.Foreground = "#000000";
            result.FocusedDesktopColors.Border     = "#FAFAFA";

            result.ActiveDesktopColors.Background = "#000000";
            result.ActiveDesktopColors.Foreground = "#FAFAFA";
            result.ActiveDesktopColors.Border     = "#FAFAFA";

            result.InactiveDesktopColors.Background = "#A3A3A3";
            result.InactiveDesktopColors.Foreground = "#EAEAEA";
            result.InactiveDesktopColors.Border     = "#EAEAEA";

            return(result);
        }
        public static WDSwapConfiguration LoadConfiguration()
        {
            EnsureConfigFileExists();

            var     parser = new FileIniDataParser();
            IniData data   = parser.ReadFile(ConfigFilePath);

            //return GetConfigFromIniData(data);
            try
            {
                return(WDSwapConfiguration.FromIni(data));
            }
            catch (Exception ex)
            {
                _Logger.Error("An error occurred while trying to read the configuration file",
                              "An error occurred while trying to read the configuration file. This usually means that the file itself was not formatted correctly. Please review the error and attempt to repair the file, or else re-load the defaults");
                _Logger.Error(ex.Message, ex.ToString());

                var alert = MessageBox.Show("There was an error reading the configuration file. Loading default configuration. If this continues, please try to repair the configuration file or else re-load the defaults.", "ERROR!", MessageBoxButtons.OK);

                return(GetDefault());
            }
        }
Example #3
0
        public static WDSwapConfiguration FromIni(IniData iniData)
        {
            var  result  = new WDSwapConfiguration();
            Type resType = result.GetType();

            foreach (var section in iniData.Sections)
            {
                var configProp = resType.GetProperty(section.SectionName, BindingFlags.Public | BindingFlags.Instance);
                if (configProp == null)
                {
                    continue;
                }

                var configPropObj = configProp.GetValue(result);

                foreach (var key in section.Keys)
                {
                    var keyProp = configProp.PropertyType.GetProperty(key.KeyName, BindingFlags.Public | BindingFlags.Instance);

                    if (keyProp == null)
                    {
                        continue;
                    }



                    keyProp.SetValue(configPropObj, ChangeType(key.Value, keyProp.PropertyType));
                }
            }

            result.ActiveDesktopColors.SelfCheck();
            result.InactiveDesktopColors.SelfCheck();
            result.FocusedDesktopColors.SelfCheck();

            return(result);
        }