Esempio n. 1
0
        public void RefreshProxyList()
        {
            var proxies = CmdUtil.GetProxies();
            var rules   = Program.SqliteDbScope.Rules;

            foreach (var proxy in proxies)
            {
                var matchedRule = rules.FirstOrDefault(r => r.EqualsWithKeys(proxy));
                proxy.Id = matchedRule?.Id;
            }

            var pendingAdds    = proxies.Where(x => x.Id == null);
            var pendingUpdates = proxies.Where(x => x.Id != null && !x.Equals(rules.First(r => r.Id == x.Id)));

            Program.SqliteDbScope.AddRange(pendingAdds);
            Program.SqliteDbScope.UpdateRange(pendingUpdates);

            listViewProxies.Items.Clear();
            rules = Program.SqliteDbScope.Rules;
            foreach (var rule in rules)
            {
                var imageIndex = proxies.Any(p => p.EqualsWithKeys(rule)) ? 1 : 0;
                var item = new ListViewItem {
                    ImageIndex = imageIndex, Tag = rule.Id
                }.Then(vitem =>
                {
                    vitem.SubItems.AddRange(new[] { rule.Type, rule.ListenOn, rule.ListenPort.ToString(), rule.ConnectTo, rule.ConnectPort.ToString(), rule.Comment });
                });
                listViewProxies.Items.Add(item);
            }
        }
Esempio n. 2
0
        private void button_submit_Click(object sender, EventArgs e)
        {
            var type        = comboBox_type.Text.Trim();
            var listenOn    = textBox_listenOn.Text.Trim().ToLower();
            var connectTo   = textBox_connectTo.Text.Trim().ToLower();
            var listenPort  = textBox_listenPort.Text.Trim();
            var connectPort = textBox_connectPort.Text.Trim();

            if (!int.TryParse(listenPort, out var _listenPort) || _listenPort < 0 || _listenPort > 65535)
            {
                MessageBox.Show($"The listen port is invalid.", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (!int.TryParse(connectPort, out var _connectPort) || _connectPort < 0 || _connectPort > 65535)
            {
                MessageBox.Show($"The connect port is invalid.", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (type == AutoTypeString)
            {
                type = GetPassType(listenOn, connectTo);
            }

            if (!new[] { "v4tov4", "v4tov6", "v6tov4", "v6tov6" }.Contains(type))
            {
                MessageBox.Show($"Unknow type for ({listenOn} -> {connectTo}).", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (_updateLiveViewItem != null)
            {
                var rule = Program.SqliteDbScope.GetRule(type, listenOn, _listenPort);
                rule.ConnectTo   = connectTo;
                rule.ConnectPort = _connectPort;
                Program.SqliteDbScope.Update(rule);
                CmdUtil.AddProxy("set", type, listenOn, _listenPort, connectTo, _connectPort);

                _updateLiveViewItem.ImageIndex = 1;
                var subItems = _updateLiveViewItem.SubItems;
                subItems[1].Text = type;
                subItems[2].Text = listenOn;
                subItems[3].Text = _listenPort.ToString();
                subItems[4].Text = connectTo;
                subItems[5].Text = _connectPort.ToString();
            }
            else
            {
                CmdUtil.AddProxy("add", type, listenOn, _listenPort, connectTo, _connectPort);
                PortProxyGUI.RefreshProxyList();
            }

            Close();
        }
Esempio n. 3
0
        private void DisableSelectedProxies()
        {
            var items = listViewProxies.SelectedItems.OfType <ListViewItem>();

            foreach (var item in items)
            {
                item.ImageIndex = 0;
                var subItems = item.SubItems.OfType <ListViewSubItem>().ToArray();
                CmdUtil.DeleteProxy(subItems[1].Text, subItems[2].Text, int.Parse(subItems[3].Text));
            }
        }
Esempio n. 4
0
        private void EnableSelectedProxies()
        {
            var items = listViewProxies.SelectedItems.OfType <ListViewItem>();

            foreach (var item in items)
            {
                item.ImageIndex = 1;
                var subItems = item.SubItems.OfType <ListViewSubItem>().ToArray();
                CmdUtil.AddProxy("add", subItems[1].Text, subItems[2].Text, int.Parse(subItems[3].Text), subItems[4].Text, int.Parse(subItems[5].Text));
            }
        }