Пример #1
0
        public MenuViewController(ShadowsocksController controller)
        {
            this.controller = controller;

            LoadMenu();

            controller.ToggleModeChanged       += controller_ToggleModeChanged;
            controller.ToggleRuleModeChanged   += controller_ToggleRuleModeChanged;
            controller.ConfigChanged           += controller_ConfigChanged;
            controller.PACFileReadyToOpen      += controller_FileReadyToOpen;
            controller.UserRuleFileReadyToOpen += controller_FileReadyToOpen;
            controller.Errored += controller_Errored;
            controller.UpdatePACFromGFWListCompleted += controller_UpdatePACFromGFWListCompleted;
            controller.UpdatePACFromGFWListError     += controller_UpdatePACFromGFWListError;
            controller.ShowConfigFormEvent           += Config_Click;

            _notifyIcon = new NotifyIcon();
            UpdateTrayIcon();
            _notifyIcon.Visible     = true;
            _notifyIcon.ContextMenu = contextMenu1;
            _notifyIcon.MouseClick += notifyIcon1_Click;
            //_notifyIcon.MouseDoubleClick += notifyIcon1_DoubleClick;

            updateFreeNodeChecker = new UpdateFreeNode();
            updateFreeNodeChecker.NewFreeNodeFound += updateFreeNodeChecker_NewFreeNodeFound;

            LoadCurrentConfiguration();

            Configuration cfg = controller.GetCurrentConfiguration();

            if (cfg.isDefaultConfig() || cfg.nodeFeedAutoUpdate)
            {
                updateFreeNodeChecker.CheckUpdate(controller.GetCurrentConfiguration(), !cfg.isDefaultConfig());
            }
        }
 private void ManagementClosed(object sender, FormClosedEventArgs e)
 {
     Controller.GetCurrentConfiguration().subscriptions = ConfigurationCopy.subscriptions;
     ConfigurationCopy.ArrangeConfig();
     Controller.GetCurrentConfiguration().configs   = ConfigurationCopy.configs;
     Controller.GetCurrentConfiguration().use_proxy = ConfigurationCopy.use_proxy;
 }
        private void SwitchProxyModeCallback()
        {
            if (timerTriggerLimit.Enabled)
            {
                return;
            }
            timerTriggerLimit.Start();

            _config = _controller.GetCurrentConfiguration();// Configuration.Load();
            //var config = _controller.GetConfiguration();
            switch (_config.sysProxyMode)
            {
            case (int)ProxyMode.Direct:
                _controller.ToggleMode(ProxyMode.Pac);
                break;

            case (int)ProxyMode.Pac:
                _controller.ToggleMode(ProxyMode.Global);
                break;

            case (int)ProxyMode.Global:
                _controller.ToggleMode(ProxyMode.Direct);
                break;

            case (int)ProxyMode.NoModify:
                _controller.ToggleMode(ProxyMode.Direct);
                break;

            default:
                break;
            }
            _viewController.ShownotifyIcontext();
        }
Пример #4
0
        private void ReloadStatisticsAndChooseAServer(object obj)
        {
            Logging.Debug("Reloading statistics and choose a new server....");
            var servers = _controller.GetCurrentConfiguration().configs;

            LoadStatistics();
            ChooseNewServer(servers);
        }
Пример #5
0
 private void UpdateTitle()
 {
     this.Text = I18N.GetString("ServerLog") + "("
                 + (controller.GetCurrentConfiguration().shareOverLan ? "any" : "local") + ":" + controller.GetCurrentConfiguration().localPort.ToString()
                 + I18N.GetString(" Version") + UpdateChecker.FullVersion
                 + ")";
 }
 private void LoadCurrentConfiguration()
 {
     readonlyAllServers = controller.GetCurrentConfiguration().Servers;
     portMap            = new Dictionary <string, PortMapConfig>();
     foreach (KeyValuePair <string, PortMapConfig> kvp in controller.GetCurrentConfiguration().portMap)
     {
         portMap.Add(kvp.Key, kvp.Value.Clone());
     }
     LoadPortSetting();
     LoadSelectedServer();
 }
 private void ServerDataGrid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
     if (ServerDataGrid.SelectedCells.Count > 0 && ServerDataGrid.SelectedCells[0].Column != null)
     {
         if (ServerDataGrid.SelectedCells[0].Column.Header is string header && ServerDataGrid.SelectedCells[0].Item is Server serverObject)
         {
             var id = serverObject.Index - 1;
             if (header == I18N.GetString(@"Server"))
             {
                 var config = _controller.GetCurrentConfiguration();
                 Console.WriteLine($@"config.checkSwitchAutoCloseAll:{config.checkSwitchAutoCloseAll}");
                 if (config.checkSwitchAutoCloseAll)
                 {
                     _controller.DisconnectAllConnections();
                 }
                 _controller.SelectServerIndex(id);
             }
             else if (header == I18N.GetString(@"Enable"))
             {
                 var server = ServerLogViewModel.ServersCollection[id];
                 server.Enable = !server.Enable;
                 _controller.Save();
             }
             else if (header == I18N.GetString(@"Group"))
             {
                 var currentServer = ServerLogViewModel.ServersCollection[id];
                 var group         = currentServer.Group;
                 if (!string.IsNullOrEmpty(group))
                 {
                     var enable = !currentServer.Enable;
                     foreach (var server in ServerLogViewModel.ServersCollection)
                     {
                         if (server.Group == group)
                         {
                             if (server.Enable != enable)
                             {
                                 server.Enable = enable;
                             }
                         }
                     }
                     _controller.Save();
                 }
             }
             else
             {
                 ServerDataGrid.SelectedCells.Clear();
                 ServerDataGrid.CurrentCell = new DataGridCellInfo(serverObject, ServerDataGrid.Columns[0]);
                 ServerDataGrid.SelectedCells.Add(ServerDataGrid.CurrentCell);
             }
         }
     }
 }
Пример #8
0
 private void CopyPACURLItem_Click(object sender, EventArgs e)
 {
     try
     {
         Configuration config = controller.GetCurrentConfiguration();
         string        pacUrl;
         pacUrl = "http://127.0.0.1:" + config.localPort.ToString() + "/pac?" + "auth=" + config.localAuthPassword + "&t=" + Util.Utils.GetTimestamp(DateTime.Now);
         Clipboard.SetText(pacUrl);
     }
     catch
     {
     }
 }
Пример #9
0
        public void UpdateLogThread()
        {
            while (workerThread != null)
            {
                Configuration        config = _controller.GetCurrentConfiguration();
                ServerSpeedLogShow[] _ServerSpeedLogList = new ServerSpeedLogShow[config.configs.Count];
                for (int i = 0; i < config.configs.Count; ++i)
                {
                    _ServerSpeedLogList[i] = config.configs[i].ServerSpeedLog().Translate();
                }
                ServerSpeedLogList = _ServerSpeedLogList;

                workerEvent.WaitOne();
            }
        }
Пример #10
0
        private void GetIPAddress(int svc, out string addr, out string stat, out float speed)
        {
            var currentIndex = controller.GetCurrentConfiguration().index;

            controller.SelectServerIndex(svc);
            var webClient = new SocksWebClient {
                ProxyDetails = new ProxyDetails(controller.GetCurrentConfiguration().localPort)
            };

            try
            {
                //get location
                var regx1    = new Regex(@"\d+\.\d+\.\d+\.\d+");
                var regx2    = new Regex(@"来自:(.*?)\<");
                var response = webClient.DownloadString(@"http://1111.ip138.com/ic.asp");

                var mc1 = regx1.Match(response);
                addr = mc1.Success ? mc1.Value : "Unknow";

                var mc2 = regx2.Match(response);
                stat = mc2.Success ? mc2.Groups[1].Value : "…(⊙_⊙;)…";
            }
            catch
            {
                addr = "Unknow";
                stat = "…(⊙_⊙;)…";
            }

            try
            {
                //speed test
                var sw = System.Diagnostics.Stopwatch.StartNew();
                var dl = webClient.DownloadData("https://dl.google.com/tag/s/appguid%3D%7B8A69D345-D564-463C-AFF1-A69D9E530F96%7D%26iid%3D%7B7B1E2CBF-95F1-5FDD-C836-E5930E3E51CD%7D%26lang%3Den%26browser%3D4%26usagestats%3D0%26appname%3DGoogle%2520Chrome%26needsadmin%3Dprefers%26installdataindex%3Ddefaultbrowser/update2/installers/ChromeSetup.exe"); //http://dl.google.com/googletalk/googletalk-setup.exe
                sw.Stop();
                var len = dl.Length / 1024f;
                var sec = sw.Elapsed.Milliseconds / 1000f;
                speed = len / sec;
            }
            catch
            {
                speed = 0;
            }
            finally
            {
                webClient.Dispose();
                controller.SelectServerIndex(currentIndex);
            }
        }
Пример #11
0
        private void GetCurrServerInfo(out int currIndex, out int serverCount)
        {
            var currConfig = _controller.GetCurrentConfiguration();

            currIndex   = currConfig.index;
            serverCount = currConfig.configs.Count;
        }
        public MenuViewController(ShadowsocksController controller)
        {
            this.controller = controller;

            LoadMenu();

            controller.ToggleModeChanged       += controller_ToggleModeChanged;
            controller.ToggleRuleModeChanged   += controller_ToggleRuleModeChanged;
            controller.ConfigChanged           += controller_ConfigChanged;
            controller.PACFileReadyToOpen      += controller_FileReadyToOpen;
            controller.UserRuleFileReadyToOpen += controller_FileReadyToOpen;
            controller.Errored += controller_Errored;
            controller.UpdatePACFromGFWListCompleted += controller_UpdatePACFromGFWListCompleted;
            controller.UpdatePACFromGFWListError     += controller_UpdatePACFromGFWListError;
            controller.ShowConfigFormEvent           += Config_Click;

            _notifyIcon = new NotifyIcon();
            UpdateTrayIcon();
            _notifyIcon.Visible     = true;
            _notifyIcon.ContextMenu = contextMenu1;
            _notifyIcon.MouseClick += notifyIcon1_Click;
            //_notifyIcon.MouseDoubleClick += notifyIcon1_DoubleClick;

            LoadCurrentConfiguration();

            Configuration cfg = controller.GetCurrentConfiguration();
        }
        private void ManagementClosed(object sender, FormClosedEventArgs e)
        {
            ConfigurationCopy.ArrangeConfig();

            var realConfig = Controller.GetCurrentConfiguration();

            var lastServer          = realConfig.configs[realConfig.index];
            var lastSubscriptionUrl = "";
            var lastId = -1;

            if (realConfig.strategy == null)
            {
                lastSubscriptionUrl = lastServer.subscription_url;
                lastId = lastServer.id;
            }

            realConfig.subscriptions = ConfigurationCopy.subscriptions;
            realConfig.configs       = ConfigurationCopy.configs;

            if (lastSubscriptionUrl != "")
            {
                var newIndex = realConfig.configs.FindIndex(it => it.subscription_url == lastSubscriptionUrl && it.id == lastId);
                if (newIndex < 0)
                {
                    newIndex = 0;
                }
                if (realConfig.index != newIndex)
                {
                    Controller.SelectServerIndex(newIndex);
                }
            }
        }
Пример #14
0
        private void UpdateTexts()
        {
            this.Text = I18N.GetString("Global Settings") + "("
                        + (controller.GetCurrentConfiguration().shareOverLan ? "any" : "local") + ":" + controller.GetCurrentConfiguration().localPort.ToString()
                        + I18N.GetString(" Version") + UpdateChecker.FullVersion
                        + ")";

            checkShareOverLan.Text = I18N.GetString(checkShareOverLan.Text);
            ProxyPortLabel.Text    = I18N.GetString("Proxy Port");
            ReconnectLabel.Text    = I18N.GetString("Reconnect Times");
            TTLLabel.Text          = I18N.GetString("TTL");

            checkAutoStartup.Text = I18N.GetString(checkAutoStartup.Text);
            checkRandom.Text      = I18N.GetString(checkRandom.Text);
            CheckAutoBan.Text     = I18N.GetString("AutoBan");

            Socks5ProxyGroup.Text = I18N.GetString("Socks5 Proxy");
            CheckSocks5Proxy.Text = I18N.GetString("Socks5 Proxy On");
            LabelS5Server.Text    = I18N.GetString("Server IP");
            LabelS5Port.Text      = I18N.GetString("Server Port");
            LabelS5Server.Text    = I18N.GetString("Server IP");
            LabelS5Port.Text      = I18N.GetString("Server Port");
            LabelS5Username.Text  = I18N.GetString("Username");
            LabelS5Password.Text  = I18N.GetString("Password");

            LabelRandom.Text = I18N.GetString("Balance");
            for (int i = 0; i < RandomComboBox.Items.Count; ++i)
            {
                RandomComboBox.Items[i] = I18N.GetString(RandomComboBox.Items[i].ToString());
            }

            OKButton.Text       = I18N.GetString("OK");
            MyCancelButton.Text = I18N.GetString("Cancel");
        }
        private void LoadLanguage()
        {
            Title = $@"{I18N.GetString(@"Edit Servers")}({(_controller.GetCurrentConfiguration().shareOverLan ? I18N.GetString(@"Any") : I18N.GetString(@"Local"))}:{_controller.GetCurrentConfiguration().localPort} {I18N.GetString(@"Version")}:{UpdateChecker.FullVersion})";

            foreach (var c in Utils.FindVisualChildren <Label>(this))
            {
                c.Content = I18N.GetString(c.Content.ToString());
            }

            foreach (var c in Utils.FindVisualChildren <Button>(this))
            {
                c.Content = I18N.GetString(c.Content.ToString());
            }

            foreach (var c in Utils.FindVisualChildren <CheckBox>(this))
            {
                c.Content = I18N.GetString(c.Content.ToString());
            }

            foreach (var c in Utils.FindVisualChildren <GroupBox>(this))
            {
                c.Header = I18N.GetString(c.Header.ToString());
            }

            TextBlock1.Text = I18N.GetString(TextBlock1.Text);
        }
Пример #16
0
        public ServerLogForm(ShadowsocksController controller)
        {
            this.controller = controller;
            this.Icon       = Icon.FromHandle(Resources.ssw128.GetHicon());
            InitializeComponent();
            this.Width = 760;

            Configuration config = controller.GetCurrentConfiguration();

            if (config.configs.Count < 8)
            {
                this.Height = 300;
            }
            else if (config.configs.Count < 20)
            {
                this.Height = 300 + (config.configs.Count - 8) * 16;
            }
            else
            {
                this.Height = 500;
            }
            UpdateTexts();
            UpdateLog();

            this.contextMenu1 = new ContextMenu(new MenuItem[] {
                this.clearItem = CreateMenuItem("&Clear", new EventHandler(this.ClearItem_Click)),
            });
            ServerDataGrid.ContextMenu = contextMenu1;
            controller.ConfigChanged  += controller_ConfigChanged;
        }
Пример #17
0
        public LogForm(ShadowsocksController controller)
        {
            this.controller = controller;

            InitializeComponent();
            Icon = Icon.FromHandle(Resources.ssw128.GetHicon());

            var nLogConfig = NLogConfig.LoadXML();

            try
            {
                this.filename = nLogConfig.GetLogFileName();
            }
            catch (Exception)
            {
                // failed to get the file name
            }
            if (string.IsNullOrEmpty(this.filename))
            {
                LogMessageTextBox.AppendText("Cannot get the log file name from NLog config file. Please check if the nlog config file exists with corresponding XML nodes.");
            }

            LogViewerConfig config = controller.GetCurrentConfiguration().logViewer;

            topMostTrigger              = config.topMost;
            wrapTextTrigger             = config.wrapText;
            toolbarTrigger              = config.toolbarShown;
            LogMessageTextBox.BackColor = config.BackgroundColor;
            LogMessageTextBox.ForeColor = config.TextColor;
            LogMessageTextBox.Font      = config.Font;

            controller.TrafficChanged += controller_TrafficChanged;

            UpdateTexts();
        }
Пример #18
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtEmail.Text.IsNullOrEmpty() || txtPasswd.Text.IsNullOrEmpty())
            {
                return;
            }
            btnLogin.Text    = "登录中,请稍候...";
            btnLogin.Enabled = false;

            var       client = new DefaultClient();
            TokenData tokenData;

            try
            {
                tokenData = client.Execute(new TokenRequest()
                {
                    Email = txtEmail.Text.Trim(), Passwd = txtPasswd.Text
                });
                client.Token = tokenData.token;

                //获取用户信息
                var user = client.Execute(new GetUserRequest(tokenData.user_id));
                if (user.enable != 1)
                {
                    throw new UserFriendlyException("你的账号已经到期,请先充值后再畅游世界"); //todo:how to charge
                }
                if (user.transfer_enable < user.u + user.d)
                {
                    throw new UserFriendlyException("哦,你的流量都用完了,请先充值吧!");
                }

                //获取节点
                var nodes  = client.Execute(new GetNodesRequest());
                var config = _controller.GetCurrentConfiguration();
                config.configs = nodes.Select(n => new Server()
                {
                    server      = n.server,
                    server_port = user.port,
                    method      = user.method,
                    password    = user.passwd,
                    timeout     = 10,
                    auth        = false
                }).ToList();
                config.enabled         = true;
                config.autoCheckUpdate = false;
                config.index           = new Random().Next(1, config.configs.Count);
                Configuration.Save(config);

                ShadowsocksControllerExtension.SetUser(user);

                Close();
            }
            catch (Exception ex)
            {
                btnLogin.Text    = "登录";
                btnLogin.Enabled = true;

                MessageBox.Show($"出错了:{ex.Message}");
            }
        }
Пример #19
0
        public void ReloadServers()
        {
            // make a copy to avoid locking
            var newServerStatus = new Dictionary <Server, ServerStatus>(_serverStatus);

            foreach (var server in _controller.GetCurrentConfiguration().configs)
            {
                if (!newServerStatus.ContainsKey(server))
                {
                    var status = new ServerStatus();
                    status.server                = server;
                    status.lastFailure           = DateTime.MinValue;
                    status.lastRead              = DateTime.Now;
                    status.lastWrite             = DateTime.Now;
                    status.latency               = new TimeSpan(0, 0, 0, 0, 10);
                    status.lastTimeDetectLatency = DateTime.Now;
                    newServerStatus[server]      = status;
                }
                else
                {
                    // update settings for existing server
                    newServerStatus[server].server = server;
                }
            }
            _serverStatus = newServerStatus;

            ChooseNewServer();
        }
Пример #20
0
        private void LoadConfig()
        {
            config = controller.GetCurrentConfiguration();
            var idx = UrlListBox.SelectedIndex;

            UrlListBox.Items.Clear();

            foreach (var item in config.onlineConfigSource)
            {
                UrlListBox.Items.Add(item);
            }

            if (idx >= UrlListBox.Items.Count)
            {
                idx = 0;
            }
            if (idx < 0 && UrlListBox.Items.Count > 0)
            {
                idx = 0;
            }
            if (UrlListBox.Items.Count == 0)
            {
                return;
            }
            UrlListBox.SelectedIndex = idx;
            SelectItem();
        }
Пример #21
0
        public static string GetValidLoginUrl()
        {
            ShadowsocksController controller = new ShadowsocksController();
            Configuration         config     = controller.GetCurrentConfiguration();

            if (config.isDefaultConfig())
            {
                string testUrl = Configuration.GetDefaultUrl(0);
                if (ConnectTest.canUrlConnect(testUrl + "/mod_mu/func/ping", "ret", false))
                {
                    return(testUrl);
                }
                else
                {
                    testUrl = Configuration.GetDefaultUrl(1);
                    if (ConnectTest.canUrlConnect(testUrl + "/mod_mu/func/ping", "ret", false))
                    {
                        return(testUrl);
                    }
                }
            }
            else
            {
                string testUrl = config.ApiUrl;
                if (ConnectTest.canUrlConnect(testUrl + "/mod_mu/func/ping", "ret", false))
                {
                    return(testUrl);
                }
                else if (ConnectTest.canUrlConnect(testUrl + "/mod_mu/func/ping", "ret", true))
                {
                    return(testUrl);
                }
                else
                {
                    testUrl = Configuration.GetDefaultUrl(0);
                    if (ConnectTest.canUrlConnect(testUrl + "/mod_mu/func/ping", "ret", false))
                    {
                        return(testUrl);
                    }
                    else if (ConnectTest.canUrlConnect(testUrl + "/mod_mu/func/ping", "ret", true))
                    {
                        return(testUrl);
                    }
                    else
                    {
                        testUrl = Configuration.GetDefaultUrl(1);
                        if (ConnectTest.canUrlConnect(testUrl + "/mod_mu/func/ping", "ret", false))
                        {
                            return(testUrl);
                        }
                        else if (ConnectTest.canUrlConnect(testUrl + "/mod_mu/func/ping", "ret", true))
                        {
                            return(testUrl);
                        }
                    }
                }
            }
            return("");
        }
Пример #22
0
        private void UpdateTexts()
        {
            this.Text = I18N.GetString("Edit Servers") + "("
                        + (controller.GetCurrentConfiguration().shareOverLan ? "any" : "local") + ":" + controller.GetCurrentConfiguration().localPort.ToString()
                        + " " + I18N.GetString("Version") + UpdateChecker.FullVersion
                        + ")";

            AddButton.Text    = I18N.GetString("&Add");
            DeleteButton.Text = I18N.GetString("&Delete");
            UpButton.Text     = I18N.GetString("Up");
            DownButton.Text   = I18N.GetString("Down");

            const string mark_str = "* ";

            IPLabel.Text          = mark_str + I18N.GetString("Server IP");
            ServerPortLabel.Text  = mark_str + I18N.GetString("Server Port");
            labelUDPPort.Text     = I18N.GetString("UDP Port");
            PasswordLabel.Text    = mark_str + I18N.GetString("Password");
            EncryptionLabel.Text  = mark_str + I18N.GetString("Encryption");
            TCPProtocolLabel.Text = mark_str + I18N.GetString(TCPProtocolLabel.Text);
            labelObfs.Text        = mark_str + I18N.GetString(labelObfs.Text);
            labelRemarks.Text     = I18N.GetString("Remarks");

            checkAdvSetting.Text    = I18N.GetString(checkAdvSetting.Text);
            TCPoverUDPLabel.Text    = I18N.GetString(TCPoverUDPLabel.Text);
            UDPoverTCPLabel.Text    = I18N.GetString(UDPoverTCPLabel.Text);
            labelProtocolParam.Text = I18N.GetString(labelProtocolParam.Text);
            labelObfsParam.Text     = I18N.GetString(labelObfsParam.Text);
            ObfsUDPLabel.Text       = I18N.GetString(ObfsUDPLabel.Text);
            LabelNote.Text          = I18N.GetString(LabelNote.Text);
            CheckTCPoverUDP.Text    = I18N.GetString(CheckTCPoverUDP.Text);
            CheckUDPoverUDP.Text    = I18N.GetString(CheckUDPoverUDP.Text);
            CheckObfsUDP.Text       = I18N.GetString(CheckObfsUDP.Text);
            checkSSRLink.Text       = I18N.GetString(checkSSRLink.Text);
            for (int i = 0; i < TCPProtocolComboBox.Items.Count; ++i)
            {
                TCPProtocolComboBox.Items[i] = I18N.GetString(TCPProtocolComboBox.Items[i].ToString());
            }

            ServerGroupBox.Text = I18N.GetString("Server");

            OKButton.Text          = I18N.GetString("OK");
            MyCancelButton.Text    = I18N.GetString("Cancel");
            LinkUpdate.MaximumSize = new Size(ServersListBox.Width, ServersListBox.Height);
            LinkUpdate.Text        = String.Format(I18N.GetString("New version {0} {1} available"), UpdateChecker.Name, updateChecker.LatestVersionNumber);
        }
 public StatisticsStrategy(ShadowsocksController controller)
 {
     _controller = controller;
     var servers = controller.GetCurrentConfiguration().configs;
     var randomIndex = new Random().Next() % servers.Count();
     _currentServer = servers[randomIndex];  //choose a server randomly at first
     _timer = new Timer(ReloadStatisticsAndChooseAServer);
 }
Пример #24
0
        public static bool isValidCurrentServer()
        {
            ShadowsocksController controller = new ShadowsocksController();
            Configuration         config     = controller.GetCurrentConfiguration();
            int i = config.index;

            return(ConnectTest.isValidServerPort(config.configs[i].server, config.configs[i].server_port));
        }
        public ServerLogForm(ShadowsocksController controller)
        {
            this.controller = controller;
            this.Icon       = Icon.FromHandle(Resources.ssw128.GetHicon());
            InitializeComponent();
            this.Width = 810;
            int dpi_mul = Util.Utils.GetDpiMul();

            Configuration config = controller.GetCurrentConfiguration();

            if (config.configs.Count < 8)
            {
                this.Height = 300 * dpi_mul / 4;
            }
            else if (config.configs.Count < 20)
            {
                this.Height = (300 + (config.configs.Count - 8) * 16) * dpi_mul / 4;
            }
            else
            {
                this.Height = 500 * dpi_mul / 4;
            }
            UpdateTexts();
            UpdateLog();

            this.contextMenu1 = new ContextMenu(new MenuItem[] {
                CreateMenuItem("Auto &size", new EventHandler(this.autosizeItem_Click)),
                this.topmostItem = CreateMenuItem("Always On &Top", new EventHandler(this.topmostItem_Click)),
                new MenuItem("-"),
                CreateMenuItem("Copy current link", new EventHandler(this.copyLinkItem_Click)),
                CreateMenuItem("Copy all enable links", new EventHandler(this.copyEnableLinksItem_Click)),
                new MenuItem("-"),
                CreateMenuItem("Clear &MaxSpeed", new EventHandler(this.ClearMaxSpeed_Click)),
                this.clearItem = CreateMenuItem("&Clear", new EventHandler(this.ClearItem_Click)),
            });
            ServerDataGrid.ContextMenu = contextMenu1;
            controller.ConfigChanged  += controller_ConfigChanged;

            for (int i = 0; i < ServerDataGrid.Columns.Count; ++i)
            {
                ServerDataGrid.Columns[i].Width = ServerDataGrid.Columns[i].Width * dpi_mul / 4;
            }

            ServerDataGrid.RowTemplate.Height = 20 * dpi_mul / 4;
            //ServerDataGrid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
            int width = 0;

            for (int i = 0; i < ServerDataGrid.Columns.Count; ++i)
            {
                if (!ServerDataGrid.Columns[i].Visible)
                {
                    continue;
                }
                width += ServerDataGrid.Columns[i].Width;
            }
            this.Width = width + SystemInformation.VerticalScrollBarWidth + (this.Width - this.ClientSize.Width) + 1;
            ServerDataGrid.AutoResizeColumnHeadersHeight();
        }
Пример #26
0
        //按下快捷键时被调用的方法
        public void CallBack()
        {
            //MessageBox.Show("快捷键被调用!,Switch Mode");


            if (controller.GetCurrentConfiguration().sysProxyMode == (int)ProxyMode.Global)
            {
                controller.ToggleMode(ProxyMode.Direct);
            }
            else if (controller.GetCurrentConfiguration().sysProxyMode == (int)ProxyMode.Direct)
            {
                controller.ToggleMode(ProxyMode.Pac);
            }
            else if (controller.GetCurrentConfiguration().sysProxyMode == (int)ProxyMode.Pac)
            {
                controller.ToggleMode(ProxyMode.Global);
            }
        }
Пример #27
0
        public StatisticsStrategy(ShadowsocksController controller)
        {
            _controller = controller;
            var servers     = controller.GetCurrentConfiguration().configs;
            var randomIndex = new Random().Next() % servers.Count;

            _currentServer = servers[randomIndex];  //choose a server randomly at first
            _timer         = new Timer(ReloadStatisticsAndChooseAServer);
        }
Пример #28
0
        private void LogForm_Load(object sender, EventArgs e)
        {
            var config = _controller.GetCurrentConfiguration().logViewer;

            logTextBox.Font = config.Font;
            wrapTextToolStripMenuItem.Checked    = config.WrapText;
            alwaysOnTopToolStripMenuItem.Checked = config.AlwaysOnTop;

            ReadLog();
        }
Пример #29
0
        private void DisconnectCurrent_Click(object sender, EventArgs e)
        {
            Configuration config = controller.GetCurrentConfiguration();

            for (int id = 0; id < config.configs.Count; ++id)
            {
                Server server = config.configs[id];
                server.GetConnections().CloseAll();
            }
        }
Пример #30
0
        public frmMain(ShadowsocksController sc)
        {
            InitializeComponent();

            //初始化QQWry
            var qqwryPath = Environment.CurrentDirectory + "\\qqwry.dat";

            if (qqwry == null && File.Exists(qqwryPath))
            {
                qqwry = new QQWry(qqwryPath);
            }
            controller = sc;

            #region i18N
            if (System.Globalization.CultureInfo.CurrentCulture.IetfLanguageTag.ToLowerInvariant().StartsWith("zh"))
            {
                Text = "Ping测试";
                dgvMain.Columns[0].HeaderText = "地址";
                dgvMain.Columns[1].HeaderText = "IP地址";
                dgvMain.Columns[2].HeaderText = "备注";
                dgvMain.Columns[3].HeaderText = "物理地址";
                dgvMain.Columns[4].HeaderText = "最大Ping值";
                dgvMain.Columns[5].HeaderText = "最小Ping值";
                dgvMain.Columns[6].HeaderText = "平均Ping值";
                dgvMain.Columns[7].HeaderText = "失败次数";
                dgvMain.Columns[8].HeaderText = "下行速度";
                dgvMain.Columns[9].HeaderText = "测速";
                tssStatusLabel.Text           = "当前状态:";
                tssStatus.Text = "准备就绪";
            }
            #endregion

            LoadConfiguration(controller.GetCurrentConfiguration());

            if (dgvMain.Rows.Count <= 5)
            {
                foreach (var row in dgvMain.Rows)
                {
                    var t = new Thread(Ping)
                    {
                        IsBackground = true
                    };
                    t.Start(row);
                }
            }
            else
            {
                ChangeStatus("Busy...");
                var t = new Thread(Go)
                {
                    IsBackground = true
                };
                t.Start(dgvMain.Rows);
            }
        }
Пример #31
0
        private void UpdateTexts()
        {
            this.Text = I18N.GetString("Edit Servers") + "("
                        + (controller.GetCurrentConfiguration().shareOverLan ? "any" : "local") + ":" + controller.GetCurrentConfiguration().localPort.ToString()
                        + I18N.GetString(" Version") + UpdateChecker.FullVersion
                        + ")";

            AddButton.Text    = I18N.GetString("&Add");
            DeleteButton.Text = I18N.GetString("&Delete");
            UpButton.Text     = I18N.GetString("Up");
            DownButton.Text   = I18N.GetString("Down");

            IPLabel.Text         = I18N.GetString("Server IP");
            ServerPortLabel.Text = I18N.GetString("Server Port");
            PasswordLabel.Text   = I18N.GetString("Password");
            EncryptionLabel.Text = I18N.GetString("Encryption");
            ProxyPortLabel.Text  = I18N.GetString("Proxy Port");
            RemarksLabel.Text    = I18N.GetString("Remarks");

            LabelExpertSetting.Text = I18N.GetString(LabelExpertSetting.Text);
            TCPoverUDPLabel.Text    = I18N.GetString(TCPoverUDPLabel.Text);
            UDPoverTCPLabel.Text    = I18N.GetString(UDPoverTCPLabel.Text);
            ObfsTCPLabel.Text       = I18N.GetString(ObfsTCPLabel.Text);
            ObfsUDPLabel.Text       = I18N.GetString(ObfsUDPLabel.Text);
            LabelNote.Text          = I18N.GetString(LabelNote.Text);
            CheckTCPoverUDP.Text    = I18N.GetString(CheckTCPoverUDP.Text);
            CheckUDPoverUDP.Text    = I18N.GetString(CheckUDPoverUDP.Text);
            CheckObfsTCP.Text       = I18N.GetString(CheckObfsTCP.Text);
            CheckObfsUDP.Text       = I18N.GetString(CheckObfsUDP.Text);
            LabelLink.Text          = I18N.GetString(LabelLink.Text);

            ServerGroupBox.Text = I18N.GetString("Server");

            ReconnectLabel.Text = I18N.GetString("Reconnect Times");
            TTLLabel.Text       = I18N.GetString("TTL");
            CheckAutoBan.Text   = I18N.GetString("AutoBan");

            Socks5ProxyGroup.Text = I18N.GetString("Socks5 Proxy");
            CheckSocks5Proxy.Text = I18N.GetString("Socks5 Proxy On");
            LabelS5Server.Text    = I18N.GetString("Server IP");
            LabelS5Port.Text      = I18N.GetString("Server Port");
            LabelS5Server.Text    = I18N.GetString("Server IP");
            LabelS5Port.Text      = I18N.GetString("Server Port");
            LabelS5Username.Text  = I18N.GetString("Username");
            LabelS5Password.Text  = I18N.GetString("Password");

            LabelRandom.Text = I18N.GetString("Balance");
            for (int i = 0; i < RandomComboBox.Items.Count; ++i)
            {
                RandomComboBox.Items[i] = I18N.GetString(RandomComboBox.Items[i].ToString());
            }

            OKButton.Text       = I18N.GetString("OK");
            MyCancelButton.Text = I18N.GetString("Cancel");
        }