Ejemplo n.º 1
0
 public JToken FetchRalletsNotification(bool onStartup = false)
 {
     Debug.WriteLine("Rallets FetchRalletsNotification");
     // 第一次启动的时候, 清空代理设置,但是不会修改到配置
     if (onStartup)
     {
         SystemProxy.Disable();
     }
     //var enabled = controller.GetFreshConfiguration().enabled;
     try
     {
         JObject notification = Request.one().Post("rallets_notification", encrypt: true);
         if (notification.ok())
         {
             controller.AssignAndReloadConfigsIfDiff(notification["configs"]);
             MenuViewController.one().UpdateView(notification);
         }
         else
         {
             if (onStartup || loggedIn)
             {
                 Logout();
                 MenuViewController.one().loginForm.showWarningTitle((String)notification.SelectToken("message"));
             }
         }
         ParseSystemNotification(notification["systemNotification"]);
         return(notification);
     }
     catch (RalletsException ex)
     {
         Debug.WriteLine(ex.ToString());
     }
     return(null);
 }
Ejemplo n.º 2
0
        public static void Stop()
        {
            V2Ray.OnExit();
            Pac.OnExit();

            SystemProxy.Disable();
            Application.Exit();
        }
Ejemplo n.º 3
0
 private void PACServer_FileChanged(object sender, EventArgs e)
 {
     if (Setting.Instance.Mode != ProxyMode.PAC)
     {
         return;
     }
     SystemProxy.Disable(); //Reset System Proxy
     Start();
 }
Ejemplo n.º 4
0
        public static void Stop()
        {
            SystemProxy.Disable();
            var processes = Process.GetProcessesByName("wv2ray");

            foreach (var item in processes)
            {
                item.Kill();
            }
        }
Ejemplo n.º 5
0
        private static void Application_ApplicationExit(object sender, EventArgs e)
        {
            Application.ApplicationExit   -= Application_ApplicationExit;
            SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
            Application.ThreadException   -= Application_ThreadException;
            HotKeys.Destroy();

            ViewManager viewManager = ViewManager.instance;

            if (viewManager.MainController != null)
            {
                viewManager.closeMainController();
            }
            SystemProxy.Disable();
        }
Ejemplo n.º 6
0
        public static void SwitchProxyMode(ProxyMode mode)
        {
            switch (mode)
            {
            case ProxyMode.Global:
                SystemProxy.EnableGlobal($"http://127.0.0.1:{Setting.HttpPort}");
                break;

            case ProxyMode.PAC:
                SystemProxy.EnablePac(Pac.PacScriptURL);
                break;

            case ProxyMode.Disable:
                SystemProxy.Disable();
                break;

            case ProxyMode.KeepSystemProxy:
            default:
                break;
            }
            NotifyIcon.SwitchProxyMode(mode);
            Setting.Mode = mode;
            Setting.Save();
        }
Ejemplo n.º 7
0
 public void Stop()
 {
     pacServer?.Stop();
     remoteClient?.Stop();
     SystemProxy.Disable();
 }
Ejemplo n.º 8
0
        static void Main()
        {
            // Check OS since we are using dual-mode socket
            if (!Utils.CheckFIPSAuthentication())
            {
                return;
            }
            if (!Utils.IsWinVistaOrHigher())
            {
                MessageBox.Show(I18N.GetString("Unsupported operating system, use Windows Vista at least."),
                                "Shadowsocks Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Utils.ReleaseMemory(true);
            using (Mutex mutex = new Mutex(false, $"Global\\Shadowsocks_{Application.StartupPath.GetHashCode()}"))
            {
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                // handle UI exceptions
                Application.ThreadException += Application_ThreadException;
                // handle non-UI exceptions
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                Application.ApplicationExit   += Application_ApplicationExit;
                SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                if (!mutex.WaitOne(0, false))
                {
                    Process[] oldProcesses = Process.GetProcessesByName("Shadowsocks");
                    if (oldProcesses.Length > 0)
                    {
                        Process oldProcess = oldProcesses[0];
                    }
                    MessageBox.Show(I18N.GetString("Find Rallets icon in your notify tray.")
                                    + Environment.NewLine
                                    + I18N.GetString("If you want to start multiple Rallets, make a copy in another directory."),
                                    I18N.GetString("Rallets is already running."));
                    return;
                }
                Directory.SetCurrentDirectory(Application.StartupPath);
#if DEBUG
                Logging.OpenLogFile();

                // truncate privoxy log file while debugging
                string privoxyLogFilename = Utils.GetTempPath("privoxy.log");
                if (File.Exists(privoxyLogFilename))
                {
                    using (new FileStream(privoxyLogFilename, FileMode.Truncate)) { }
                }
#else
                Logging.OpenLogFile();
#endif
                Test(); // TODO
                _controller     = ShadowsocksController.one();
                _viewController = MenuViewController.one();
                NotificationRunner.one().Start();
                HotKeys.Init();
                _controller.Start();
                // 程序退出前把代理设置清除
                Application.ApplicationExit += new EventHandler((s, e) => {
                    SystemProxy.Disable();
                });
                Application.Run();
            }
        }