Example #1
0
        public PromptForArgs( Options options )
        {
            // Required for Windows Form Designer support
            InitializeComponent();

            // Load a decent icon.
            // this.Icon = new Icon(typeof(Global), "RSaR.ico");

            // Display version number in titlebar.
            this.Text += string.Format( " (v{0})", this.GetType().Assembly.GetName().Version );

            // Hold a reference to the settings object.
            this.m_options = options;

            // Init control states.
            this.textboxFilespec.Text = String.Empty;

            this.checkboxRecursion.Checked = options.DoRecursion;
            this.checkboxIgnoreCase.Checked = options.RegexIgnoreCase;
            this.checkboxSingeline.Checked = options.RegexSingleline;
            this.checkboxMimicVS.Checked = options.RegexMimicVS;
            this.checkBoxIncludeHidden.Checked = options.IncludeHidden;
            this.checkBoxPause.Checked = options.Pause;

            this.textboxPattern.Text = options.RegexPattern;
            this.textboxReplacement.Text = options.ReplacementText;
            if ( options.ReplacementText != null )
                this.checkboxReplacement.Checked = true;

            // Load last user settings.
            InitializeFromIsolatedStorage();
        }
Example #2
0
        public static int Main( string[] args )
        {
            Application.EnableVisualStyles();

            Console.CancelKeyPress += new ConsoleCancelEventHandler( Console_CancelKeyPress );

            try
            {
                // Load defaults from app.config.
                s_options = new Options();

                // If args were spec'd on cmd line, use them; else show the GUI prompt.
                if ( args.Length > 0 )
                    return MainImplCmd( args );
                else
                    return MainImplGui();
            }
            catch ( ApplicationException ex )
            {
                ConsoleWriter.Error.WriteLine( Global.Options.ErrorForeground, ex.Message );

                return CommandLine.ShowUsage();
            }
            catch ( Exception ex )
            {
                ConsoleWriter.Error.WriteLine( Global.Options.ErrorForeground, ex.ToString() );

                return 1;
            }
            finally
            {
                SafeConsoleColorSetter.ResetColor();
            }
        }
Example #3
0
        public static void Parse( string[] args, Options options )
        {
            // All parameters are either /<switch>=<value> or just plain <text> format.
            Regex argpatt =
                new Regex( @"^( ([/\-](?<switch>[silvwrph][\+\-]?)(=(?<value>.*))?) | (?<text>[^/\-].*) )$",
                RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture );

            // Parse each argument, as either <text> or /<switch>=<value>.
            foreach ( string arg in args )
            {
                if ( !argpatt.IsMatch( arg ) )
                    throw new ApplicationException( String.Format( "Unrecognized command line argument: {0}", arg ) );

                Match m = argpatt.Match( arg );

                if ( m.Groups[ "text" ].Value != String.Empty )
                {
                    if ( options.FilePattern == null || options.BaseDirectory == null )
                    {
                        options.FilePattern = Path.GetFileName( arg );
                        options.BaseDirectory = Path.GetDirectoryName( arg );
                    }
                    else if ( options.RegexPattern == null )
                    {
                        options.RegexPattern = arg;
                    }
                    else throw new ApplicationException( String.Format( "Unrecognized command line argument: {0}", arg ) );
                }
                else if ( m.Groups[ "switch" ].Value != String.Empty )
                {
                    switch ( m.Groups[ "switch" ].Value[ 0 ] )
                    {
                    case 's':
                        options.DoRecursion = ( m.Groups[ "switch" ].Value.EndsWith( "-" ) ) ? false : true;
                        break;
                    case 'i':
                        options.RegexIgnoreCase = ( m.Groups[ "switch" ].Value.EndsWith( "-" ) ) ? false : true;
                        break;
                    case 'l':
                        options.RegexSingleline = ( m.Groups[ "switch" ].Value.EndsWith( "-" ) ) ? false : true;
                        break;
                    case 'v':
                        options.RegexMimicVS = ( m.Groups[ "switch" ].Value.EndsWith( "-" ) ) ? false : true;
                        break;
                    case 'p':
                        options.Pause = ( m.Groups[ "switch" ].Value.EndsWith( "-" ) ) ? false : true;
                        break;
                    case 'h':
                        options.IncludeHidden = ( m.Groups[ "switch" ].Value.EndsWith( "-" ) ) ? false : true;
                        break;
                    case 'w':
                        options.OutputWidth = UInt16.Parse( m.Groups[ "value" ].Value );
                        break;
                    case 'r':
                        options.ReplacementText = m.Groups[ "value" ].Value;
                        break;
                    default: throw new ApplicationException( String.Format( "Unrecognized command line argument: {0}", arg ) );
                    }
                }
            }//foreach

            // Validate required args and apply defaults.
            if ( String.IsNullOrEmpty( options.RegexPattern ) )
                throw new ApplicationException( "Must specify regex pattern." );

            if ( String.IsNullOrEmpty( options.BaseDirectory ) )
                options.BaseDirectory = Environment.CurrentDirectory;

            if ( String.IsNullOrEmpty( options.FilePattern ) )
                options.FilePattern = "*";
        }