Пример #1
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();
        }
Пример #2
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));
            }
        }