コード例 #1
0
        public void updateFreeServersTest()
        {
            ShadowsocksController controller = new ShadowsocksController();
            FreeServers           servers    = new FreeServers(controller);

            Debug.WriteLine(System.Environment.CurrentDirectory);
            Debug.WriteLine(System.IO.Directory.GetCurrentDirectory());
            Debug.WriteLine(System.AppDomain.CurrentDomain.BaseDirectory);
            Debug.WriteLine(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase);

            Debug.WriteLine("Before Total Count -> " + controller.GetConfigurationCopy().configs.Count);

            servers.updateFreeServers();
            System.Threading.Thread.Sleep(5000); // wait for thread worked.
            Debug.WriteLine("Len\tServer\tPort\tPassword\tMethod");
            foreach (Server server in controller.GetConfigurationCopy().configs)
            {
                Debug.WriteLine(string.Format("{4}\t{0}\t{1}\t{2}\t{3}"
                                              , server.server
                                              , server.server_port
                                              , server.password
                                              , server.method
                                              , server.server.Length));
            }

            Debug.WriteLine("Total Count -> " + controller.GetConfigurationCopy().configs.Count);
            Assert.IsTrue(controller.GetConfigurationCopy().configs.Count > 2);
        }
コード例 #2
0
        static void Main()
        {
            // Check OS since we are using dual-mode socket
            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 Shadowsocks icon in your notify tray.")
                                    + Environment.NewLine
                                    + I18N.GetString("If you want to start multiple Shadowsocks, make a copy in another directory."),
                                    I18N.GetString("Shadowsocks 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
                _controller     = new ShadowsocksController();
                _freeServers    = new FreeServers(_controller);
                _viewController = new MenuViewController(_controller);
                // Free Servers Timer
                _freeServerTimer           = new System.Timers.Timer(1000 * 60 * 3); // 3分钟检查一次
                _freeServerTimer.AutoReset = true;
                _freeServerTimer.Elapsed  += ElapsedEventHandler;
                _freeServers.updateFreeServers(); // update now
                _freeServerTimer.Start();
                /////////////////////
                HotKeys.Init();
                _controller.Start();
                Application.Run();
            }
        }