public ShadowsocksController()
        {
            _config      = Configuration.Load();
            polipoRunner = new PolipoRunner();
            polipoRunner.Start(_config);
            local = new Local(_config);
            try
            {
                local.Start();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            try
            {
                pacServer = new PACServer();
                pacServer.PACFileChanged += pacServer_PACFileChanged;
                pacServer.Start(_config);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            UpdateSystemProxy();
            StartReleasingMemory();
        }
        protected void SaveConfig(Configuration newConfig)
        {
            Configuration.Save(newConfig);
            // some logic in configuration updated the config when saving, we need to read it again
            _config = Configuration.Load();

            pacServer.Stop();
            local.Stop();

            // don't put polipoRunner.Start() before pacServer.Stop()
            // or bind will fail when switching bind address from 0.0.0.0 to 127.0.0.1
            // though UseShellExecute is set to true now
            // http://stackoverflow.com/questions/10235093/socket-doesnt-close-after-application-exits-if-a-launched-process-is-open
            polipoRunner.Stop();
            polipoRunner.Start(_config);

            local = new Local(_config);
            local.Start();
            pacServer.Start(_config);

            if (ConfigChanged != null)
            {
                ConfigChanged(this, new EventArgs());
            }

            Util.Util.ReleaseMemory();
        }
        protected void Reload()
        {
            // some logic in configuration updated the config when saving, we need to read it again
            _config = Configuration.Load();

            if (polipoRunner == null)
            {
                polipoRunner = new PolipoRunner();
            }
            if (pacServer == null)
            {
                pacServer = new PACServer();
                pacServer.PACFileChanged += pacServer_PACFileChanged;
            }

            pacServer.Stop();

            if (local != null)
            {
                local.Stop();
            }

            // don't put polipoRunner.Start() before pacServer.Stop()
            // or bind will fail when switching bind address from 0.0.0.0 to 127.0.0.1
            // though UseShellExecute is set to true now
            // http://stackoverflow.com/questions/10235093/socket-doesnt-close-after-application-exits-if-a-launched-process-is-open
            polipoRunner.Stop();
            try
            {
                polipoRunner.Start(_config);

                local = new Local(_config);
                local.Start();
                pacServer.Start(_config);
            }
            catch (Exception e)
            {
                // translate Microsoft language into human language
                // i.e. An attempt was made to access a socket in a way forbidden by its access permissions => Port already in use
                if (e is SocketException)
                {
                    SocketException se = (SocketException)e;
                    if (se.SocketErrorCode == SocketError.AccessDenied)
                    {
                        e = new Exception(I18N.GetString("Port already in use"), e);
                    }
                }
                Logging.LogUsefulException(e);
                ReportError(e);
            }

            if (ConfigChanged != null)
            {
                ConfigChanged(this, new EventArgs());
            }

            UpdateSystemProxy();
            Util.Util.ReleaseMemory();
        }
예제 #4
0
        protected void Reload()
        {
            // some logic in configuration updated the config when saving, we need to read it again
            _config = Configuration.Load();

            if (polipoRunner == null)
            {
                polipoRunner = new PolipoRunner();
            }
            if (pacServer == null)
            {
                pacServer = new PACServer();
                pacServer.PACFileChanged += pacServer_PACFileChanged;
            }

            pacServer.Stop();

            if (local != null)
            {
                local.Stop();
            }

            // don't put polipoRunner.Start() before pacServer.Stop()
            // or bind will fail when switching bind address from 0.0.0.0 to 127.0.0.1
            // though UseShellExecute is set to true now
            // http://stackoverflow.com/questions/10235093/socket-doesnt-close-after-application-exits-if-a-launched-process-is-open
            polipoRunner.Stop();
            try
            {
                polipoRunner.Start(_config);

                local = new Local(_config);
                local.Start();
                pacServer.Start(_config);
            }
            catch (Exception e)
            {
                Logging.LogUsefulException(e);
                ReportError(e);
            }

            if (ConfigChanged != null)
            {
                ConfigChanged(this, new EventArgs());
            }

            UpdateSystemProxy();
            Util.Util.ReleaseMemory();
        }
        protected void Reload()
        {
            // some logic in configuration updated the config when saving, we need to read it again
            _config = Configuration.Load();

            if (polipoRunner == null)
            {
                polipoRunner = new PolipoRunner();
            }
            if (pacServer == null)
            {
                pacServer = new PACServer();
                pacServer.PACFileChanged += pacServer_PACFileChanged;
            }

            pacServer.Stop();

            if (local != null)
            {
                local.Stop();
            }

            // don't put polipoRunner.Start() before pacServer.Stop()
            // or bind will fail when switching bind address from 0.0.0.0 to 127.0.0.1
            // though UseShellExecute is set to true now
            // http://stackoverflow.com/questions/10235093/socket-doesnt-close-after-application-exits-if-a-launched-process-is-open
            polipoRunner.Stop();
            try
            {
                polipoRunner.Start(_config);

                local = new Local(_config);
                local.Start();
                pacServer.Start(_config);
            }
            catch (Exception e)
            {
                Logging.LogUsefulException(e);
                ReportError(e);
            }

            if (ConfigChanged != null)
            {
                ConfigChanged(this, new EventArgs());
            }

            UpdateSystemProxy();
            Util.Util.ReleaseMemory();
        }