예제 #1
0
 private void ButtonAutorunOff_Click(object sender, System.EventArgs e)
 {
     if (InAutorun())
     {
         Autorun.Remove(APP_NAME, TARGET.USER);
         MessageBox.Show(LocalizedMessageProvider.GetMessage("DELETED_AUTORUN"),
                         LocalizedMessageProvider.GetMessage("AUTORUN"), MessageBoxButtons.OK, MessageBoxIcon.Information);
         checkBoxAutoHide.Visible   = false;
         Settings.Default.AutoStart = false;
         buttonAutorun.Text         = deleteFromAutorun;
     }
     else
     {
         Autorun.Add(APP_NAME, Application.ExecutablePath.ToString(), TARGET.USER);
         MessageBox.Show(LocalizedMessageProvider.GetMessage("ADDED_AUTORUN"),
                         LocalizedMessageProvider.GetMessage("AUTORUN"), MessageBoxButtons.OK, MessageBoxIcon.Information);
         checkBoxAutoHide.Visible   = true;
         Settings.Default.AutoStart = true;
         buttonAutorun.Text         = addToAutorun;
     }
     Settings.Default.Save();
 }
예제 #2
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            try
            {
                var isSingle = SingleInstance.IsSingle();
                if (!isSingle)
                {
                    SingleInstance.SetForeground();
                    return;
                }

                var isTrueDirectory = DirectoryCheck.IsTrueDirectory();
                if (!isTrueDirectory)
                {
                    throw new Exception(I18N.GetString("FileNotFound"));
                }

                var isAdmin = Administrator.IsAdmin();
                if (e.Args.Length == 0 && isAdmin)
                {
                    switch (MessageBox.Show($"{I18N.GetString("Setup")}", name,
                                            MessageBoxButton.YesNoCancel, MessageBoxImage.Information))
                    {
                    case MessageBoxResult.Yes:
                        Autorun.Add();
                        DesktopMenu.Add();
                        break;

                    case MessageBoxResult.No:
                        Autorun.Remove();
                        DesktopMenu.Remove();
                        V2Ray.Stop();
                        break;

                    default:
                        break;
                    }
                }
                else if (e.Args.Length == 0 && !isAdmin)
                {
                    throw new Exception(I18N.GetString("PermissionDenied"));
                }
                else if (e.Args[0] == "-start")
                {
                    V2Ray.Start();
                }
                else if (e.Args[0] == "-stop")
                {
                    V2Ray.Stop();
                }
                else if (e.Args[0] == "-config")
                {
                    var window = new MainWindow();
                    window.ShowDialog();
                }
                else
                {
                    throw new ArgumentException();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, name, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Environment.Exit(Environment.ExitCode);
            }
        }