示例#1
0
        static void Main(string[] args)
        {
            bool registryProcessed = false;

            try
            {
                registryProcessed = SetRegistry.CheckCommandLineArgs(args);  // If specified in the args, updates the registry
            }
            catch (Exception ex)
            {
                registryProcessed = true;
                MessageBox.Show(ex.Message, "Error updating the registry", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (!registryProcessed)
            {
                SearchAndReplaceParameters searchAndReplaceParameters = new SearchAndReplaceParameters(args);

                if (searchAndReplaceParameters.NoUI)
                {
                    SearchAndReplace.SearchAndReplaceInFile(searchAndReplaceParameters);
                }
                else
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new FormJSearchAndReplace(searchAndReplaceParameters));
                }
            }
        }
        private void buttonOk_Click(object sender, EventArgs e)
        {
            if (checkBoxEnableRightClick.Checked)
            {
                StringBuilder args = new StringBuilder();

                //
                // Options to be passed to the SearchAndReplace application when running elevated to register
                //

                args.Append(SetRegistry.SetRegistryCommandLineArg).Append(" ");

                // Right click options
                if (!string.IsNullOrEmpty(textBoxRightClick.Text.Trim()))
                {
                    args.AppendFormat("-rightclicktext {0} ", textBoxRightClick.Text.Trim());
                }

                if (radioButtonReplaceExisting.Checked)
                {
                    args.Append("-replaceexisting ");
                }
                else if (radioButtonAddToExisting.Checked)
                {
                    args.Append("-addtoexisting ");
                    if (checkBoxMakeDefault.Checked)
                    {
                        args.Append("-makedefault ");
                    }
                }
                else
                {
                    throw new Exception("Need to implement registry option related to right click options.");
                }

                // File extensions
                if (radioButtonAllFiles.Checked)
                {
                    throw new Exception("TODO: implement handling all files in the registry.");
                }
                else if (radioButtonFileExtensions.Checked)
                {
                    string[] fileExtensions = textBoxFileExtensions.Text.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    args.AppendFormat("-extensions \"{1}\" ", string.Join(" ", fileExtensions));
                }
                else
                {
                    throw new Exception("Need to implement registry option related to file extensions.");
                }

                //
                // Options to be passed to the SearchAndReplace application when running from right click
                //

                //SearchAndReplaceParameters searchAndReplaceParameters = userControlSearchAndReplaceOptions.get

                SetRegistry.StartProcessElevatedPrivileges(args.ToString().Trim(), true);
            }

            Close();
        }