private Win32.ConsoleColorFlags ParseForeColor(String color, Win32.ConsoleColorFlags background) { return(background | (Win32.ConsoleColorFlags)Enum.Parse(typeof(Win32.ConsoleColorFlags), "Foreground" + color, true)); }
// // Initialization public Settings() { // Load defaults from app.config. //todo: drive this via reflection? string val; val = ConfigurationSettings.AppSettings["OutputWidth"]; if (val == null || val == String.Empty) OutputWidth = 78; else OutputWidth = UInt16.Parse(val); val = ConfigurationSettings.AppSettings["RegexIgnoreCase"]; if (val == null || val == String.Empty) RegexIgnoreCase = false; else RegexIgnoreCase = Boolean.Parse(val); val = ConfigurationSettings.AppSettings["RegexSingleline"]; if (val == null || val == String.Empty) RegexSingleline = false; else RegexSingleline = Boolean.Parse(val); val = ConfigurationSettings.AppSettings["RegexMimicVS"]; if (val == null || val == String.Empty) RegexMimicVS = false; else RegexMimicVS = Boolean.Parse(val); val = ConfigurationSettings.AppSettings["DontRecurse"]; if (val == null || val == String.Empty) DontRecurse = false; else DontRecurse = Boolean.Parse(val); val = ConfigurationSettings.AppSettings["ActiveReplace"]; if (val == null || val == String.Empty) ActiveReplace = false; else ActiveReplace = Boolean.Parse(val); val = ConfigurationSettings.AppSettings["BackupDirectory"]; if (val == null || val == String.Empty) BackupDirectory = null; else BackupDirectory = val; val = ConfigurationSettings.AppSettings["IgnoreHiddenDirectories"]; if (val == null || val == String.Empty) IgnoreHiddenDirectories = true; else IgnoreHiddenDirectories = Boolean.Parse(val); val = ConfigurationSettings.AppSettings["IgnoreHiddenFiles"]; if (val == null || val == String.Empty) IgnoreHiddenFiles = true; else IgnoreHiddenFiles = Boolean.Parse(val); val = ConfigurationSettings.AppSettings["DirectoryExclusions"]; if (val == null || val == String.Empty) DirectoryExclusions = new String[0]; else DirectoryExclusions = val.Split( ';' ); val = ConfigurationSettings.AppSettings["FileExclusions"]; if (val == null || val == String.Empty) FileExclusions = new String[0]; else FileExclusions = val.Split( ';' ); val = ConfigurationSettings.AppSettings["SuppressError"]; if (val == null || val == String.Empty) SuppressError = FileParseError.None; else SuppressError = (FileParseError)Enum.Parse( typeof( FileParseError ), val ); // The following parameters have no defaults -- they can/must only be // specified explicitly in the UI. BaseDirectory = null; FilePattern = null; RegexPattern = null; ReplacementText = null; val = ConfigurationSettings.AppSettings["ConsoleColor"]; if ( val == null || val == String.Empty ) val = "Black, White, BrightGreen, BrightGreen, BrightWhite, Gray, BrightGreen, BrightRed"; String[] color = val.Split( ',' ); for ( int i = 0; i < 8; i++ ) { color[i] = color[i].Trim(); } Win32.ConsoleColorFlags background = (Win32.ConsoleColorFlags)Enum.Parse( typeof( Win32.ConsoleColorFlags ), "Background" + color[ 0 ], true ); this.DefaultColor = ParseForeColor( color[ 1 ], background ); this.FileDirectoryColor = ParseForeColor( color[ 2 ], background ); this.FileNameColor = ParseForeColor( color[ 3 ], background ); this.LineNumberColor = ParseForeColor( color[ 4 ], background ); this.SurroundingTextColor = ParseForeColor( color[ 5 ], background ); this.MatchedTextColor = ParseForeColor( color[ 6 ], background ); this.ErrorColor = ParseForeColor( color[ 7 ], background ); }
// // Initialization public Settings() { // Load defaults from app.config. //todo: drive this via reflection? string val; val = ConfigurationSettings.AppSettings["OutputWidth"]; if (val == null || val == String.Empty) { OutputWidth = 78; } else { OutputWidth = UInt16.Parse(val); } val = ConfigurationSettings.AppSettings["RegexIgnoreCase"]; if (val == null || val == String.Empty) { RegexIgnoreCase = false; } else { RegexIgnoreCase = Boolean.Parse(val); } val = ConfigurationSettings.AppSettings["RegexSingleline"]; if (val == null || val == String.Empty) { RegexSingleline = false; } else { RegexSingleline = Boolean.Parse(val); } val = ConfigurationSettings.AppSettings["RegexMimicVS"]; if (val == null || val == String.Empty) { RegexMimicVS = false; } else { RegexMimicVS = Boolean.Parse(val); } val = ConfigurationSettings.AppSettings["DontRecurse"]; if (val == null || val == String.Empty) { DontRecurse = false; } else { DontRecurse = Boolean.Parse(val); } val = ConfigurationSettings.AppSettings["ActiveReplace"]; if (val == null || val == String.Empty) { ActiveReplace = false; } else { ActiveReplace = Boolean.Parse(val); } val = ConfigurationSettings.AppSettings["BackupDirectory"]; if (val == null || val == String.Empty) { BackupDirectory = null; } else { BackupDirectory = val; } val = ConfigurationSettings.AppSettings["IgnoreHiddenDirectories"]; if (val == null || val == String.Empty) { IgnoreHiddenDirectories = true; } else { IgnoreHiddenDirectories = Boolean.Parse(val); } val = ConfigurationSettings.AppSettings["IgnoreHiddenFiles"]; if (val == null || val == String.Empty) { IgnoreHiddenFiles = true; } else { IgnoreHiddenFiles = Boolean.Parse(val); } val = ConfigurationSettings.AppSettings["DirectoryExclusions"]; if (val == null || val == String.Empty) { DirectoryExclusions = new String[0]; } else { DirectoryExclusions = val.Split(';'); } val = ConfigurationSettings.AppSettings["FileExclusions"]; if (val == null || val == String.Empty) { FileExclusions = new String[0]; } else { FileExclusions = val.Split(';'); } val = ConfigurationSettings.AppSettings["SuppressError"]; if (val == null || val == String.Empty) { SuppressError = FileParseError.None; } else { SuppressError = (FileParseError)Enum.Parse(typeof(FileParseError), val); } // The following parameters have no defaults -- they can/must only be // specified explicitly in the UI. BaseDirectory = null; FilePattern = null; RegexPattern = null; ReplacementText = null; val = ConfigurationSettings.AppSettings["ConsoleColor"]; if (val == null || val == String.Empty) { val = "Black, White, BrightGreen, BrightGreen, BrightWhite, Gray, BrightGreen, BrightRed"; } String[] color = val.Split(','); for (int i = 0; i < 8; i++) { color[i] = color[i].Trim(); } Win32.ConsoleColorFlags background = (Win32.ConsoleColorFlags)Enum.Parse(typeof(Win32.ConsoleColorFlags), "Background" + color[0], true); this.DefaultColor = ParseForeColor(color[1], background); this.FileDirectoryColor = ParseForeColor(color[2], background); this.FileNameColor = ParseForeColor(color[3], background); this.LineNumberColor = ParseForeColor(color[4], background); this.SurroundingTextColor = ParseForeColor(color[5], background); this.MatchedTextColor = ParseForeColor(color[6], background); this.ErrorColor = ParseForeColor(color[7], background); }