public XsocksApplicationContext(XsocksController controller)
        {
            Application.ApplicationExit += OnApplicationExit;

            BuildMenu();

            _controller = controller;
            controller.EnableStatusChanged += ControllerEnableStatusChanged;
            controller.ConfigChanged += ControllerConfigChanged;
            controller.PacFileReadyToOpen += ControllerFileReadyToOpen;
            controller.UserRuleFileReadyToOpen += ControllerFileReadyToOpen;
            controller.ShareOverLanStatusChanged += ControllerShareOverLanStatusChanged;
            controller.EnableGlobalChanged += ControllerEnableGlobalChanged;
            controller.Errored += ControllerErrored;
            controller.UpdatePacFromGfwListCompleted += ControllerUpdatePACFromGFWListCompleted;
            controller.UpdatePacFromGfwListError += ControllerUpdatePACFromGFWListError;

            _trayIcon = new NotifyIcon
            {
                Visible = true
            };
            _trayIcon.MouseDoubleClick += TrayIconDoubleClick;
            _trayIcon.ContextMenu = _trayIconContextMenu;
            UpdateTrayIcon();

            LoadCurrentConfiguration();

            if (controller.GetConfiguration().IsDefault)
            {
                _isFirstRun = true;
                ShowConfigForm();
            }
        }
Esempio n. 2
0
        private static void Main()
        {
            Utils.ReleaseMemory();
            using (Mutex mutex = new Mutex(false, "Global\\" + "71904632-A427-497F-AB91-241CD477EC1F"))
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                if (!mutex.WaitOne(0, false))
                {
                    MessageBox.Show("Xsocks is already running.\nFind Xsocks icon in notify tray.",
                        "Xsocks", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                Directory.SetCurrentDirectory(Application.StartupPath);
            #if !DEBUG
                Logging.OpenLogFile();
            #endif
                XsocksController controller = new XsocksController();
                controller.Start();
                Application.Run(new XsocksApplicationContext(controller));
            }
        }
 private void ControllerFileReadyToOpen(object sender, XsocksController.PathEventArgs e)
 {
     string argument = @"/select, " + e.Path;
     Process.Start("explorer.exe", argument);
 }