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));
            }
        }
Exemple #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 (_updateMode)
            {
                var rule = Program.SqliteDbScope.GetRule(_oldType, _oldListenOn, _oldListenPort);
                CmdUtil.DeleteProxy(_oldType, _oldListenOn, _oldListenPort);
                Program.SqliteDbScope.Remove(rule);

                rule.Type        = type;
                rule.ListenOn    = listenOn;
                rule.ListenPort  = _listenPort;
                rule.ConnectTo   = connectTo;
                rule.ConnectPort = _connectPort;

                CmdUtil.AddProxy("add", type, listenOn, _listenPort, connectTo, _connectPort);
                Program.SqliteDbScope.Add(rule);

                _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);
                ParentWindow.RefreshProxyList();
            }

            Close();
        }