示例#1
0
        private void ServerMoveUpCallback()
        {
            int currIndex;
            int serverCount;

            GetCurrServerInfo(out currIndex, out serverCount);
            if (currIndex - 1 < 0)
            {
                // revert to last server
                currIndex = serverCount - 1;
            }
            else
            {
                currIndex -= 1;
            }
            _controller.SelectServerIndex(currIndex);
        }
示例#2
0
        private async void OKButton_Click(object sender, EventArgs e)
        {
            if (!SaveOldSelectedServer())
            {
                return;
            }
            if (_modifiedConfiguration.configs.Count == 0)
            {
                MessageBox.Show(I18N.GetString("Please add at least one server"));
                return;
            }

            OKButton.Enabled = false;
            OKButton.Text    = I18N.GetString("Busy...");
            controller.SaveServers(_modifiedConfiguration.configs, _modifiedConfiguration.localPort, _modifiedConfiguration.corePort);
            await controller.SelectServerIndex(ServersListBox.SelectedIndex);

            Close();
        }
示例#3
0
        private async void OKButton_Click(object sender, EventArgs e)
        {
            if (!SaveOld())
            {
                return;
            }

            OKButton.Enabled = false;
            OKButton.Text    = I18N.GetString("Busy...");

            try
            {
                var currentSvc = _controller.GetCurrentServer();
                _controller.SaveSubscribes(_modifiedConfiguration.subscribes);
                if (_lastSelectedIndex > -1)
                {
                    var item = _modifiedConfiguration.subscribes[_lastSelectedIndex];
                    var wc   = new WebClient();
                    if (item.useProxy)
                    {
                        wc.Proxy = new WebProxy(IPAddress.Loopback.ToString(), _modifiedConfiguration.localPort);
                    }
                    var cts = new System.Threading.CancellationTokenSource();
                    // ReSharper disable once AccessToDisposedClosure
                    cts.Token.Register(() => wc?.CancelAsync());
                    cts.CancelAfter(10000);
                    var downloadString = await wc.DownloadStringTaskAsync(item.url);

                    wc.Dispose();
                    var lst = new List <ServerObject>();
                    if (downloadString.Contains("vmess://"))
                    {
                        var mcg = Regex.Matches(downloadString, @"vmess://(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})", RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
                        foreach (Match s in mcg)
                        {
                            if (ServerObject.TryParse(s.Value, out ServerObject svc))
                            {
                                svc.@group = item.name;
                                lst.Add(svc);
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            var debase64 = downloadString.DeBase64();
                            var split    = debase64.Split('\r', '\n');
                            foreach (var s in split)
                            {
                                if (ServerObject.TryParse(s, out ServerObject svc))
                                {
                                    svc.@group = item.name;
                                    lst.Add(svc);
                                }
                            }
                        }
                        catch
                        {
                            MessageBox.Show(I18N.GetString("Invalid Base64 string."), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    if (lst.Any())
                    {
                        _modifiedConfiguration.configs.RemoveAll(c => c.@group == oldNames[_lastSelectedIndex]);
                        _modifiedConfiguration.configs.AddRange(lst);
                    }
                }
                _controller.SaveServers(_modifiedConfiguration.configs, _modifiedConfiguration.localPort, _modifiedConfiguration.corePort);
                var newIdx = _modifiedConfiguration.configs.IndexOf(currentSvc);
                if (newIdx == -1)
                {
                    await _controller.SelectServerIndex(0);
                }
                else if (newIdx != _modifiedConfiguration.index)
                {
                    await _controller.SelectServerIndex(newIdx);
                }
            }
            catch (Exception exception)
            {
                Logging.LogUsefulException(exception);
            }
            Close();
        }