Example #1
0
 void UpdateServerItemPanelIsCollapse(bool isCollapse)
 {
     servers
     .GetServerList()
     .Where(s => s.isSelected)
     .Select(s =>
     {
         if (s.isCollapse != isCollapse)
         {
             s.ToggleIsCollapse();
         }
         return(s);
     })
     .ToList();     // force linq to execute
 }
Example #2
0
        void UpdateCboxServerNameList(int index = -1)
        {
            var oldIndex = index < 0 ? cboxServList.SelectedIndex : index;

            cboxServList.Items.Clear();

            var serverList = servers.GetServerList();

            if (serverList.Count <= 0)
            {
                cboxServList.SelectedIndex = -1;
                return;
            }

            this.serverList = new Dictionary <string, string>();
            foreach (var server in serverList)
            {
                cboxServList.Items.Add(server.name);
                this.serverList[server.name] = server.config;
            }

            servIndex = Lib.Utils.Clamp(oldIndex, 0, serverList.Count);
            cboxServList.SelectedIndex = servIndex;
            UpdateLink();
        }
Example #3
0
        public void ExportAllServersToTextFile()
        {
            if (this.servers.IsEmpty())
            {
                MessageBox.Show(I18N.ServerListIsEmpty);
                return;
            }

            var    serverList = servers.GetServerList();
            string s          = string.Empty;

            foreach (var server in serverList)
            {
                s += "v2ray://" + Lib.Utils.Base64Encode(server.config) + "\r\n\r\n";
            }

            switch (Lib.UI.ShowSaveFileDialog(
                        StrConst.ExtText,
                        s,
                        out string filename))
            {
            case Model.Data.Enum.SaveFileErrorCode.Success:
                MessageBox.Show(I18N.Done);
                break;

            case Model.Data.Enum.SaveFileErrorCode.Fail:
                MessageBox.Show(I18N.WriteFileFail);
                break;

            case Model.Data.Enum.SaveFileErrorCode.Cancel:
                // do nothing
                break;
            }
        }
Example #4
0
        public List <Controller.CoreServerCtrl> GetFilteredList()
        {
            var list     = servers.GetServerList();
            var keywords = (searchKeywords ?? "").Split(
                new char[] { ' ', ',' },
                StringSplitOptions.RemoveEmptyEntries);

            if (keywords.Length < 1)
            {
                return(list.ToList());
            }

            return(list
                   .Where(serv => serv.GetterInfoFor(
                              infos => keywords.All(
                                  kw => infos.Any(
                                      info => Lib.Utils.PartialMatch(info, kw)))))
                   .ToList());
        }
Example #5
0
 void SelectAllServerIF(Func <Controller.ServerCtrl, bool> condiction)
 {
     servers.GetServerList()
     .Select(s =>
     {
         s.SetIsSelected(condiction(s));
         return(true);
     })
     .ToList();
 }
Example #6
0
        List <Controller.ServerCtrl> GetFilteredList()
        {
            var list     = servers.GetServerList();
            var keywords = (searchKeywords ?? "").Split(
                new char[] { ' ', ',' },
                StringSplitOptions.RemoveEmptyEntries);

            if (keywords.Length < 1)
            {
                return(list.ToList());
            }

            return(list
                   .Where(
                       e => keywords.All(
                           k => e.GetSearchTextList().Any(
                               s => Lib.Utils.PartialMatch(s, k))))
                   .ToList());
        }
Example #7
0
        void SelectCurPageWhere(Func <Views.UserControls.ServerUI, bool> condiction)
        {
            var panel   = GetFlyPanel();
            var configs = panel.GetFilteredList().Select(s => s.config);

            // clear all not in current filtered list
            servers.GetServerList()
            .Where(s => !configs.Contains(s.config))
            .Select(s =>
            {
                s.SetIsSelected(false);
                return(true);
            })
            .ToList();

            panel.LoopThroughAllServerUI(s =>
            {
                s.SetSelected(condiction(s));
            });
        }
Example #8
0
        private IEnumerable <Model.Data.ServerItem> GetFilteredListByMark()
        {
            var list = servers.GetServerList();

            if (preSelectedMarkFilterIndex < 0)
            {
                return(list);
            }
            switch (preSelectedMarkFilterIndex)
            {
            case 0:
                return(list);

            case 1:
                return(list.Where(s => string.IsNullOrEmpty(s.mark)));
            }

            var markList = servers.GetMarkList();

            return(list.Where(s => s.mark == markList[preSelectedMarkFilterIndex - 2]));
        }
        private void FormBatchModifyServerInfo_Shown(object sender, EventArgs e)
        {
            this.cboxMark.Items.Clear();
            foreach (var mark in servers.GetMarkList())
            {
                this.cboxMark.Items.Add(mark);
            }

            var first = servers.GetServerList().Where(s => s.isSelected).FirstOrDefault();

            if (first == null)
            {
                return;
            }
            this.cboxInMode.SelectedIndex             = first.overwriteInboundType;
            this.tboxInIP.Text                        = first.inboundIP;
            this.tboxInPort.Text                      = first.inboundPort.ToString();
            this.cboxMark.Text                        = first.mark;
            this.cboxAutorun.SelectedIndex            = first.isAutoRun ? 0 : 1;
            this.cboxImport.SelectedIndex             = first.isInjectImport ? 0 : 1;
            this.cboxIsInjectSkipCNSite.SelectedIndex = first.isInjectSkipCNSite ? 0 : 1;
        }
Example #10
0
        private void SortServerListBySpeedTestResult()
        {
            var list = servers.GetServerList().Where(s => s.isSelected).ToList();

            if (list.Count < 2)
            {
                return;
            }
            list.Sort((a, b) => a.speedTestResult.CompareTo(b.speedTestResult));
            var minIndex = list.First().index;
            var delta    = 1.0 / 2 / list.Count;

            for (int i = 1; i < list.Count; i++)
            {
                list[i].index = minIndex + delta * i;
            }

            var flyPanel = GetFlyPanel();

            flyPanel.RemoveAllConrols();
            flyPanel.RefreshUI();
        }
Example #11
0
        private void InitCtrlBatchOperation(ToolStripMenuItem stopSelected, ToolStripMenuItem restartSelected, ToolStripMenuItem speedTestOnSelected, ToolStripMenuItem modifySelected, ToolStripMenuItem packSelected)
        {
            modifySelected.Click += ApplyActionOnSelectedServers(
                () => Views.WinForms.FormBatchModifyServerSetting.GetForm());

            packSelected.Click += ApplyActionOnSelectedServers(() =>
            {
                var list = servers
                           .GetServerList()
                           .Where(s => s.isSelected)
                           .Select(s => s as VgcApis.Models.ICoreCtrl)
                           .ToList();

                if (setting.isUseV4)
                {
                    servers.PackServersIntoV4Package(list);
                }
                else
                {
                    list.Reverse();
                    servers.PackServersIntoV3Package(list);
                }
            });

            speedTestOnSelected.Click += ApplyActionOnSelectedServers(() =>
            {
                if (!Lib.UI.Confirm(I18N.TestWillTakeALongTime))
                {
                    return;
                }

                if (!servers.RunSpeedTestOnSelectedServers())
                {
                    MessageBox.Show(I18N.LastTestNoFinishYet);
                }
            });

            stopSelected.Click += ApplyActionOnSelectedServers(() =>
            {
                if (Lib.UI.Confirm(I18N.ConfirmStopAllSelectedServers))
                {
                    servers.StopAllSelectedThen();
                }
            });

            restartSelected.Click += ApplyActionOnSelectedServers(() =>
            {
                if (Lib.UI.Confirm(I18N.ConfirmRestartAllSelectedServers))
                {
                    servers.RestartAllSelectedServersThen();
                }
            });
        }
Example #12
0
        int GetAvailableProxyPort()
        {
            var servList = servers.GetServerList()
                           .Where(s => s.isServerOn);

            foreach (var serv in servList)
            {
                if (serv.IsSuitableToBeUsedAsSysProxy(
                        true, out bool isSocks, out int port))
                {
                    return(port);
                }
            }
            return(-1);
        }
Example #13
0
 public string GetUid()
 {
     if (string.IsNullOrEmpty(uid))
     {
         var uidList = servers
                       .GetServerList()
                       .Select(s => s.uid)
                       .ToList();
         do
         {
             uid = Lib.Utils.RandomHex(16);
         } while (uidList.Contains(uid));
         InvokeEventOnPropertyChange();
     }
     return(uid);
 }
Example #14
0
        void UpdateServerMenu()
        {
            var menuReplaceServer = replaceExistServerToolStripMenuItem.DropDownItems;
            var menuLoadServer    = loadServerToolStripMenuItem.DropDownItems;

            menuReplaceServer.Clear();
            menuLoadServer.Clear();

            var serverList = servers.GetServerList();

            var enable = serverList.Count > 0;

            replaceExistServerToolStripMenuItem.Enabled = enable;
            loadServerToolStripMenuItem.Enabled         = enable;

            for (int i = 0; i < serverList.Count; i++)
            {
                var name = string.Format("{0}.{1}", i + 1, serverList[i].name);
                var org  = serverList[i].config;
                menuReplaceServer.Add(new ToolStripMenuItem(name, null, (s, a) =>
                {
                    if (Lib.UI.Confirm(I18N("ReplaceServer")))
                    {
                        if (configer.ReplaceServer(org))
                        {
                            SetTitle(configer.GetAlias());
                        }
                    }
                }));

                menuLoadServer.Add(new ToolStripMenuItem(name, null, (s, a) =>
                {
                    if (!configer.IsConfigSaved() &&
                        !Lib.UI.Confirm(I18N("ConfirmLoadNewServer")))
                    {
                        return;
                    }
                    configer.LoadServer(org);
                    SetTitle(configer.GetAlias());
                }));
            }
        }
Example #15
0
        private void InitCtrlCopyToClipboard(ToolStripMenuItem copyAsV2rayLinks, ToolStripMenuItem copyAsVmessLinks, ToolStripMenuItem copyAsSubscriptions)
        {
            copyAsSubscriptions.Click += GenSelectedServerHandler(() =>
            {
                MessageBox.Show(
                    Lib.Utils.CopyToClipboard(
                        Lib.Utils.Base64Encode(
                            EncodeAllServersIntoVmessLinks())) ?
                    I18N("LinksCopied") :
                    I18N("CopyFail"));
            });

            copyAsV2rayLinks.Click += GenSelectedServerHandler(() =>
            {
                var list = servers.GetServerList()
                           .Where(s => s.isSelected)
                           .Select(s => Lib.Utils.AddLinkPrefix(
                                       Lib.Utils.Base64Encode(s.config),
                                       Model.Data.Enum.LinkTypes.v2ray))
                           .ToList();

                MessageBox.Show(
                    Lib.Utils.CopyToClipboard(
                        string.Join(Environment.NewLine, list)) ?
                    I18N("LinksCopied") :
                    I18N("CopyFail"));
            });

            copyAsVmessLinks.Click += GenSelectedServerHandler(() =>
            {
                MessageBox.Show(
                    Lib.Utils.CopyToClipboard(
                        EncodeAllServersIntoVmessLinks()) ?
                    I18N("LinksCopied") :
                    I18N("CopyFail"));
            });
        }