Example #1
0
 private void MainFormDragDrop(object sender, DragEventArgs e)
 {
     try {
         string filePath = ((string[])e.Data.GetData(DataFormats.FileDrop, false))[0];
         if (filePath.EndsWith(Constants.ExtensionReg, StringComparison.OrdinalIgnoreCase))
         {
             textBox4.Text = filePath;
             textBox4.Focus();
             textBox4.SelectAll();
         }
         else
         {
             if (string.IsNullOrWhiteSpace(textBox3.Text) || !Directory.Exists(textBox3.Text) || textBox3.Text == workingFolderPathTemp)
             {
                 textBox3.Text = Path.GetDirectoryName(filePath);
                 textBox3.SelectAll();
                 workingFolderPathTemp = textBox3.Text;
             }
             if (string.IsNullOrWhiteSpace(textBox5.Text) || textBox5.Text == shortcutNameTemp)
             {
                 textBox5.Text = Application.ProductName + Constants.Space + Path.GetFileNameWithoutExtension(filePath);
                 textBox5.SelectAll();
                 shortcutNameTemp = textBox5.Text;
             }
             textBox1.Text = filePath;
             textBox1.Focus();
             textBox1.SelectAll();
         }
     } catch (Exception exception) {
         Debug.WriteLine(exception);
         ErrorLog.WriteLine(exception);
         dialog = new MessageForm(this, exception.Message, Program.GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageForm.Buttons.OK, MessageForm.BoxIcon.Error);
         dialog.ShowDialog();
     }
 }
Example #2
0
 private void SelectRegFile(object sender, EventArgs e)
 {
     try {
         if (!string.IsNullOrEmpty(textBox4.Text))
         {
             string directoryPath = Path.GetDirectoryName(textBox4.Text);
             if (Directory.Exists(directoryPath))
             {
                 openFileDialog2.InitialDirectory = directoryPath;
             }
             if (File.Exists(textBox4.Text))
             {
                 openFileDialog2.FileName = Path.GetFileName(textBox4.Text);
             }
         }
     } catch (Exception exception) {
         Debug.WriteLine(exception);
         ErrorLog.WriteLine(exception);
     }
     try {
         if (openFileDialog2.ShowDialog() == DialogResult.OK)
         {
             textBox4.Text = openFileDialog2.FileName;
         }
     } catch (Exception exception) {
         Debug.WriteLine(exception);
         ErrorLog.WriteLine(exception);
         dialog = new MessageForm(this, exception.Message, Program.GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageForm.Buttons.OK, MessageForm.BoxIcon.Error);
         dialog.ShowDialog();
     } finally {
         textBox4.Focus();
         textBox4.SelectAll();
     }
 }
Example #3
0
 private void EditRegFile(object sender, EventArgs e)
 {
     if (string.IsNullOrWhiteSpace(textBox4.Text) || !textBox4.Text.EndsWith(Constants.ExtensionReg, StringComparison.OrdinalIgnoreCase))
     {
         dialog = new MessageForm(this, Properties.Resources.MessageRegFileNotSet, null, MessageForm.Buttons.OK, MessageForm.BoxIcon.Exclamation);
         dialog.ShowDialog();
         textBox4.Focus();
         textBox4.SelectAll();
         return;
     }
     if (!File.Exists(textBox4.Text))
     {
         dialog = new MessageForm(this, Properties.Resources.MessageRegFileNotFound, null, MessageForm.Buttons.OK, MessageForm.BoxIcon.Exclamation);
         dialog.ShowDialog();
         textBox4.Focus();
         textBox4.SelectAll();
         return;
     }
     try {
         Process process = new Process();
         process.StartInfo.FileName  = Constants.NotepadExeFileName;
         process.StartInfo.Arguments = ArgumentParser.EscapeArgument(textBox4.Text);
         process.Start();
     } catch (Exception exception) {
         Debug.WriteLine(exception);
         ErrorLog.WriteLine(exception);
         dialog = new MessageForm(this, exception.Message, Program.GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageForm.Buttons.OK, MessageForm.BoxIcon.Error);
         dialog.ShowDialog();
     }
 }
Example #4
0
 private void SelectFolder(object sender, EventArgs e)
 {
     try {
         if (!string.IsNullOrEmpty(textBox3.Text))
         {
             if (Directory.Exists(textBox3.Text))
             {
                 folderBrowserDialog.SelectedPath = textBox3.Text;
             }
         }
     } catch (Exception exception) {
         Debug.WriteLine(exception);
         ErrorLog.WriteLine(exception);
     }
     try {
         if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
         {
             if (textBox3.Text != folderBrowserDialog.SelectedPath)
             {
                 textBox3.Text         = folderBrowserDialog.SelectedPath;
                 workingFolderPathTemp = textBox3.Text;
             }
         }
     } catch (Exception exception) {
         Debug.WriteLine(exception);
         ErrorLog.WriteLine(exception);
         dialog = new MessageForm(this, exception.Message, Program.GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageForm.Buttons.OK, MessageForm.BoxIcon.Error);
         dialog.ShowDialog();
     } finally {
         textBox3.Focus();
         textBox3.SelectAll();
     }
 }
Example #5
0
 private void OpenHelp(object sender, HelpEventArgs e)
 {
     try {
         Process.Start(Properties.Resources.Website.TrimEnd('/').ToLowerInvariant() + '/' + Application.ProductName.ToLowerInvariant() + '/');
     } catch (Exception exception) {
         Debug.WriteLine(exception);
         ErrorLog.WriteLine(exception);
     }
 }
 private void CopyLink(object sender, EventArgs e)
 {
     try {
         Clipboard.SetText(((LinkLabel)((MenuItem)sender).GetContextMenu().SourceControl).Text);
     } catch (Exception exception) {
         Debug.WriteLine(exception);
         ErrorLog.WriteLine(exception);
     }
 }
 private void CopyAbout(object sender, EventArgs e)
 {
     try {
         Clipboard.SetText(stringBuilder.ToString());
     } catch (Exception exception) {
         Debug.WriteLine(exception);
         ErrorLog.WriteLine(exception);
     }
 }
Example #8
0
 private void OpenHelp(object sender, HelpEventArgs hlpevent)
 {
     try {
         Process.Start(Properties.Resources.Website.TrimEnd('/').ToLowerInvariant() + '/' + Application.ProductName.ToLowerInvariant() + '/');
     } catch (Exception exception) {
         Debug.WriteLine(exception);
         ErrorLog.WriteLine(exception);
         dialog = new MessageForm(this, exception.Message, Program.GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageForm.Buttons.OK, MessageForm.BoxIcon.Error);
         dialog.ShowDialog();
     }
 }
Example #9
0
 private void OpenRegedit(object sender, EventArgs e)
 {
     try {
         Process process = new Process();
         process.StartInfo.FileName = Constants.RegeditExeFileName;
         process.Start();
     } catch (Exception exception) {
         Debug.WriteLine(exception);
         ErrorLog.WriteLine(exception);
         dialog = new MessageForm(this, exception.Message, Program.GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageForm.Buttons.OK, MessageForm.BoxIcon.Error);
         dialog.ShowDialog();
     }
 }
Example #10
0
        private static ContextMenu BuildLabelAndCheckBoxContextMenu()
        {
            ContextMenu contextMenu = new ContextMenu();

            contextMenu.MenuItems.Add(new MenuItem(Properties.Resources.MenuItemCopy, new EventHandler((sender, e) => {
                try {
                    Clipboard.SetText(((MenuItem)sender).GetContextMenu().SourceControl.Text);
                } catch (Exception exception) {
                    Debug.WriteLine(exception);
                    ErrorLog.WriteLine(exception);
                }
            })));
            return(contextMenu);
        }
Example #11
0
 private void OnLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         try {
             Process.Start(((LinkLabel)sender).Text);
             linkLabel.LinkVisited = true;
         } catch (Exception exception) {
             Debug.WriteLine(exception);
             ErrorLog.WriteLine(exception);
             dialog = new MessageForm(this, exception.Message, Program.GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageForm.Buttons.OK, MessageForm.BoxIcon.Error);
             dialog.ShowDialog();
         }
     }
 }
Example #12
0
 private void CreateShortcut(object sender, EventArgs e)
 {
     if (string.IsNullOrWhiteSpace(textBox5.Text))
     {
         dialog = new MessageForm(this, Properties.Resources.MessageShortcutNameNotSet, null, MessageForm.Buttons.OK, MessageForm.BoxIcon.Exclamation);
         dialog.ShowDialog();
         textBox5.Focus();
         textBox5.SelectAll();
         return;
     }
     try {
         string shortcutFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), textBox5.Text);
         if (!shortcutFilePath.EndsWith(Constants.ExtensionLnk, StringComparison.OrdinalIgnoreCase))
         {
             shortcutFilePath += Constants.ExtensionLnk;
         }
         if (File.Exists(shortcutFilePath))
         {
             dialog = new MessageForm(this, Properties.Resources.MessageShortcutAlreadyExists, null, MessageForm.Buttons.YesNo, MessageForm.BoxIcon.Warning, MessageForm.DefaultButton.Button2);
             if (dialog.ShowDialog() != DialogResult.Yes)
             {
                 textBox5.Focus();
                 textBox5.SelectAll();
                 return;
             }
         }
         List <string>   arguments       = BuildArguments();
         ProgramShortcut programShortcut = new ProgramShortcut()
         {
             ShortcutFilePath = shortcutFilePath,
             TargetPath       = Application.ExecutablePath,
             WorkingFolder    = Application.StartupPath,
             Arguments        = string.Join(Constants.Space, arguments),
             IconLocation     = textBox1.Text
         };
         programShortcut.Create();
     } catch (ApplicationException exception) {
         Debug.WriteLine(exception);
         ErrorLog.WriteLine(exception);
         dialog = new MessageForm(this, exception.Message, null, MessageForm.Buttons.OK, MessageForm.BoxIcon.Exclamation);
         dialog.ShowDialog();
     } catch (Exception exception) {
         Debug.WriteLine(exception);
         ErrorLog.WriteLine(exception);
         dialog = new MessageForm(this, exception.Message, Program.GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageForm.Buttons.OK, MessageForm.BoxIcon.Error);
         dialog.ShowDialog();
     }
 }
Example #13
0
 private void SelectApplication(object sender, EventArgs e)
 {
     try {
         if (!string.IsNullOrEmpty(textBox1.Text))
         {
             string directoryPath = Path.GetDirectoryName(textBox1.Text);
             if (Directory.Exists(directoryPath))
             {
                 openFileDialog1.InitialDirectory = directoryPath;
             }
             if (File.Exists(textBox1.Text))
             {
                 openFileDialog1.FileName = Path.GetFileName(textBox1.Text);
             }
         }
     } catch (Exception exception) {
         Debug.WriteLine(exception);
         ErrorLog.WriteLine(exception);
     }
     try {
         if (openFileDialog1.ShowDialog() == DialogResult.OK)
         {
             textBox1.Text = openFileDialog1.FileName;
             if (string.IsNullOrWhiteSpace(textBox3.Text) || !Directory.Exists(textBox3.Text) || textBox3.Text == workingFolderPathTemp)
             {
                 textBox3.Text = Path.GetDirectoryName(textBox1.Text);
                 textBox3.SelectAll();
                 workingFolderPathTemp = textBox3.Text;
             }
             if (string.IsNullOrWhiteSpace(textBox5.Text) || textBox5.Text == shortcutNameTemp)
             {
                 textBox5.Text = Application.ProductName + Constants.Space + Path.GetFileNameWithoutExtension(textBox1.Text);
                 textBox5.SelectAll();
                 shortcutNameTemp = textBox5.Text;
             }
         }
     } catch (Exception exception) {
         Debug.WriteLine(exception);
         ErrorLog.WriteLine(exception);
         dialog = new MessageForm(this, exception.Message, Program.GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageForm.Buttons.OK, MessageForm.BoxIcon.Error);
         dialog.ShowDialog();
     } finally {
         textBox1.Focus();
         textBox1.SelectAll();
     }
 }
Example #14
0
 private void Launch(object sender, EventArgs e)
 {
     try {
         List <string> arguments = BuildArguments();
         Process       process   = new Process();
         process.StartInfo.FileName         = Application.ExecutablePath;
         process.StartInfo.Arguments        = string.Join(Constants.Space, arguments);
         process.StartInfo.WorkingDirectory = Application.StartupPath;
         process.Start();
         SaveSettings();
     } catch (ApplicationException exception) {
         Debug.WriteLine(exception);
         ErrorLog.WriteLine(exception);
         dialog = new MessageForm(this, exception.Message, null, MessageForm.Buttons.OK, MessageForm.BoxIcon.Exclamation);
         dialog.ShowDialog();
     } catch (Exception exception) {
         Debug.WriteLine(exception);
         ErrorLog.WriteLine(exception);
         dialog = new MessageForm(this, exception.Message, Program.GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageForm.Buttons.OK, MessageForm.BoxIcon.Error);
         dialog.ShowDialog();
     }
 }
Example #15
0
        public static void Main(string[] args)
        {
            if (Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                MessageBox.Show(Properties.Resources.MessageApplicationCannotRun, GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Settings settings = new Settings();

            if (!settings.DisableThemes)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                settings.RenderWithVisualStyles = Application.RenderWithVisualStyles;
            }
            ArgumentParser argumentParser = new ArgumentParser();

            try {
                argumentParser.Arguments = args;
            } catch (Exception exception) {
                Debug.WriteLine(exception);
                ErrorLog.WriteLine(exception);
                MessageBox.Show(exception.Message, GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (argumentParser.HasArguments)
            {
                if (argumentParser.IsHelp)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine1.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine2.Replace("\\t", "\t"));
                    stringBuilder.AppendLine(Properties.Resources.HelpLine3.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine4.Replace("\\t", "\t"));
                    stringBuilder.AppendLine(Properties.Resources.HelpLine5.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine6.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine7.Replace("\\t", "\t"));
                    stringBuilder.AppendLine(Properties.Resources.HelpLine8.Replace("\\t", "\t"));
                    stringBuilder.AppendLine(Properties.Resources.HelpLine9.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine10.Replace("\\t", "\t")).AppendLine();
                    stringBuilder.AppendLine(Properties.Resources.HelpLine11.Replace("\\t", "\t"));
                    MessageBox.Show(stringBuilder.ToString(), GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionHelp, MessageBoxButtons.OK, MessageBoxIcon.Question);
                }
                else if (argumentParser.IsThisTest)
                {
                    try {
                        Application.Run(new ArgumentParserForm());
                    } catch (Exception exception) {
                        Debug.WriteLine(exception);
                        ErrorLog.WriteLine(exception);
                        MessageBox.Show(exception.Message, GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        MessageBox.Show(Properties.Resources.MessageApplicationError, GetTitle(), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    try {
                        LauncherAsRegistry launcherAsRegistry = new LauncherAsRegistry()
                        {
                            ApplicationFilePath = argumentParser.ApplicationFilePath,
                            Arguments           = argumentParser.ApplicationArguments,
                            WorkingFolderPath   = argumentParser.WorkingFolderPath,
                            OneInstance         = argumentParser.OneInstance,
                            RegFilePath         = argumentParser.RegFilePath
                        };
                        launcherAsRegistry.Launch();
                    } catch (Exception exception) {
                        Debug.WriteLine(exception);
                        ErrorLog.WriteLine(exception);
                        MessageBox.Show(exception.Message, GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                try {
                    SingleMainForm.Run(new MainForm(settings));
                } catch (Exception exception) {
                    Debug.WriteLine(exception);
                    ErrorLog.WriteLine(exception);
                    MessageBox.Show(exception.Message, GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Properties.Resources.CaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    MessageBox.Show(Properties.Resources.MessageApplicationError, GetTitle(), MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Example #16
0
        public ArgumentParserForm()
        {
            Icon = Properties.Resources.Icon;

            textBoxClicks      = 0;
            textBoxClicksTimer = new Timer();

            argumentParser = new ArgumentParser();

            InitializeComponent();
            Text = Program.GetTitle() + Constants.Space + Constants.EnDash + Constants.Space + Text;

            statusBarPanel = new StatusBarPanel()
            {
                BorderStyle = StatusBarPanelBorderStyle.Sunken,
                AutoSize    = StatusBarPanelAutoSize.Spring,
                Alignment   = HorizontalAlignment.Left
            };
            statusBar.Panels.Add(statusBarPanel);

            statusBarPanelCapsLock = new StatusBarPanel()
            {
                BorderStyle = StatusBarPanelBorderStyle.Sunken,
                Alignment   = HorizontalAlignment.Center,
                Width       = 42
            };
            statusBar.Panels.Add(statusBarPanelCapsLock);

            statusBarPanelNumLock = new StatusBarPanel()
            {
                BorderStyle = StatusBarPanelBorderStyle.Sunken,
                Alignment   = HorizontalAlignment.Center,
                Width       = 42
            };
            statusBar.Panels.Add(statusBarPanelNumLock);

            statusBarPanelInsert = new StatusBarPanel()
            {
                BorderStyle = StatusBarPanelBorderStyle.Sunken,
                Alignment   = HorizontalAlignment.Center,
                Width       = 42
            };
            statusBar.Panels.Add(statusBarPanelInsert);

            statusBarPanelScrollLock = new StatusBarPanel()
            {
                BorderStyle = StatusBarPanelBorderStyle.Sunken,
                Alignment   = HorizontalAlignment.Center,
                Width       = 42
            };
            statusBar.Panels.Add(statusBarPanelScrollLock);

            statusBar.ContextMenu = new ContextMenu();
            statusBar.ContextMenu.MenuItems.Add(new MenuItem(Properties.Resources.MenuItemCopy, new EventHandler((sender, e) => {
                if (!string.IsNullOrEmpty(statusBarPanel.Text))
                {
                    try {
                        Clipboard.SetText(statusBarPanel.Text);
                    } catch (Exception exception) {
                        Debug.WriteLine(exception);
                        ErrorLog.WriteLine(exception);
                    }
                }
            })));
            statusBar.ContextMenu.Popup += new EventHandler((sender, e) => {
                ((ContextMenu)sender).MenuItems[0].Visible = !string.IsNullOrEmpty(statusBarPanel.Text);
            });

            SubscribeEvents();

            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("/i ");
            stringBuilder.Append(ArgumentParser.EscapeArgument(Constants.ExampleApplicationFilePath));
            stringBuilder.Append(" /a ");
            stringBuilder.Append(ArgumentParser.EscapeArgument(Constants.ExampleApplicationArguments));
            stringBuilder.Append(" /w ");
            stringBuilder.Append(ArgumentParser.EscapeArgument(Constants.ExampleWorkingFolderPath));
            stringBuilder.Append(" /o /r ");
            stringBuilder.Append(ArgumentParser.EscapeArgument(Constants.ExampleRegFilePath));
            textBox1.Text = stringBuilder.ToString();

            textBoxInput.Text = Constants.ExampleApplicationArguments;
        }