示例#1
0
        static void Main()
        {
            Utils.ReleaseMemory(true);
            using (Mutex mutex = new Mutex(false, "Global\\V2RayShell_" + Application.StartupPath.GetHashCode()))
            {
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                Application.ThreadException += Application_ThreadException;
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                Application.ApplicationExit += Application_ApplicationExit;

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                var processesName = Process.GetCurrentProcess().MainModule?.ModuleName ?? "V2RayShell.exe";
                var processesNameWithoutExtension = Path.GetFileNameWithoutExtension(processesName);
                if (!mutex.WaitOne(0, false))
                {
                    Process[] oldProcesses = Process.GetProcessesByName(processesNameWithoutExtension);
                    if (oldProcesses.Length > 0)
                    {
                        Process oldProcess = oldProcesses[0];
                    }
                    MessageBox.Show(I18N.GetString("Find V2RayShell icon in your notify tray.") + "\n" +
                                    I18N.GetString("If you want to start multiple V2RayShell, make a copy in another directory."),
                                    I18N.GetString("V2RayShell is already running."));
                    return;
                }

                Logging.OpenLogFile();
                //check
                if (V2Ray.CoreExsis)
                {
                    if (V2Ray.Version != null)
                    {
                        Logging.Info("V2RayCore version : " + V2Ray.Version);
                    }
                    else
                    {
                        throw new Exception(I18N.GetString("v2ray.exe -version parse fail!"));
                    }
                }
                else
                {
                    //need do sth
                    var download = new DownloadProgress();
                    var result   = download.ShowDialog();
                    if (result == DialogResult.Abort || result == DialogResult.Cancel)
                    {
                        MessageBox.Show(I18N.GetString("download fail!"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    Logging.Info("V2RayCore version : " + V2Ray.Version);
                }

                var controller     = new V2RayShellController();
                var viewController = new MenuViewController(controller);
                Hotkeys.HotKeys.Init(controller, viewController);
                controller.StartAsync();
                Application.Run();
            }
        }
示例#2
0
        public static void InitInstance(V2RayShellController controller, MenuViewController menu)
        {
            if (Instance != null)
            {
                return;
            }

            Instance = new HotkeyCallbacks(controller, menu);
        }
示例#3
0
 public SubscribeConfigForm(V2RayShellController controller)
 {
     InitializeComponent();
     UpdateTexts();
     Icon        = Resources.v2ray;
     _controller = controller;
     _controller.ConfigChanged += controller_ConfigChanged;
     LoadCurrentConfiguration();
 }
示例#4
0
        public static void Init(V2RayShellController controller, MenuViewController menu)
        {
            _hotKeyManager             = new HotKeyManager();
            _hotKeyManager.KeyPressed += HotKeyManagerPressed;

            HotkeyCallbacks.InitInstance(controller, menu);

            var keys = controller.GetConfigurationCopy()?.hotkey ?? new HotkeyConfig();

            LoadConfiguration(keys);
        }
示例#5
0
 public ConfigForm(V2RayShellController controller)
 {
     InitializeComponent();
     PerformLayout();
     UpdateTexts();
     Icon                      = Resources.v2ray;
     this.controller           = controller;
     controller.ConfigChanged += (s, e) =>
     {
         LoadCurrentConfiguration();
     };
     LoadCurrentConfiguration();
 }
示例#6
0
        public HotkeySettingsForm(V2RayShellController controller)
        {
            InitializeComponent();
            UpdateTexts();
            Icon = Resources.v2ray;

            _controller = controller;
            _controller.ConfigChanged += controller_ConfigChanged;

            LoadCurrentConfiguration();

            // get all textboxes belong to this form
            _allTextBoxes = tableLayoutPanel1.GetChildControls <TextBox>();
            if (!_allTextBoxes.Any())
            {
                throw new Exception("Cannot get all textboxes");
            }
        }
示例#7
0
 private HotkeyCallbacks(V2RayShellController controller, MenuViewController menu)
 {
     _controller     = controller;
     _menuController = menu;
 }