Beispiel #1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string address  = txtAddress.Text;
            string port     = txtPort.Text;
            string id       = txtId.Text;
            string security = txtSecurity.Text;
            string remarks  = txtRemarks.Text;

            if (Utils.IsNullOrEmpty(address))
            {
                UI.Show(UIRes.I18N("FillServerAddress"));
                return;
            }
            if (Utils.IsNullOrEmpty(port) || !Utils.IsNumberic(port))
            {
                UI.Show(UIRes.I18N("FillCorrectServerPort"));
                return;
            }

            vmessItem.address  = address;
            vmessItem.port     = Utils.ToInt(port);
            vmessItem.id       = id;
            vmessItem.security = security;
            vmessItem.remarks  = remarks;

            if (ConfigHandler.AddSocksServer(ref config, vmessItem, EditIndex) == 0)
            {
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                UI.Show(UIRes.I18N("OperationFailed"));
            }
        }
Beispiel #2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string remarks = txtRemarks.Text;
            string address = txtAddress.Text;
            string port    = txtPort.Text;

            string id       = string.Empty;
            string alterId  = string.Empty;
            string security = string.Empty;
            string flow     = string.Empty;

            switch (eConfigType)
            {
            case EConfigType.VMess:
                id       = txtId.Text;
                alterId  = txtAlterId.Text;
                security = cmbSecurity.Text;
                break;

            case EConfigType.Shadowsocks:
                id       = txtId3.Text;
                security = cmbSecurity3.Text;
                break;

            case EConfigType.Socks:
                id       = txtId4.Text;
                security = txtSecurity4.Text;
                break;

            case EConfigType.VLESS:
                id       = txtId5.Text;
                flow     = cmbFlow5.Text;
                security = cmbSecurity5.Text;
                break;

            case EConfigType.Trojan:
                id   = txtId6.Text;
                flow = cmbFlow6.Text;
                break;
            }

            if (Utils.IsNullOrEmpty(address))
            {
                UI.Show(ResUI.FillServerAddress);
                return;
            }
            if (Utils.IsNullOrEmpty(port) || !Utils.IsNumberic(port))
            {
                UI.Show(ResUI.FillCorrectServerPort);
                return;
            }
            if (eConfigType == EConfigType.Shadowsocks)
            {
                if (Utils.IsNullOrEmpty(id))
                {
                    UI.Show(ResUI.FillPassword);
                    return;
                }
                if (Utils.IsNullOrEmpty(security))
                {
                    UI.Show(ResUI.PleaseSelectEncryption);
                    return;
                }
            }
            if (eConfigType != EConfigType.Socks)
            {
                if (Utils.IsNullOrEmpty(id))
                {
                    UI.Show(ResUI.FillUUID);
                    return;
                }
            }

            transportControl.EndBindingServer();

            vmessItem.remarks  = remarks;
            vmessItem.address  = address;
            vmessItem.port     = Utils.ToInt(port);
            vmessItem.id       = id;
            vmessItem.alterId  = Utils.ToInt(alterId);
            vmessItem.security = security;

            if (Utils.IsNullOrEmpty(cmbCoreType.Text))
            {
                vmessItem.coreType = null;
            }
            else
            {
                vmessItem.coreType = (ECoreType)Enum.Parse(typeof(ECoreType), cmbCoreType.Text);
            }

            int ret = -1;

            switch (eConfigType)
            {
            case EConfigType.VMess:
                ret = ConfigHandler.AddServer(ref config, vmessItem);
                break;

            case EConfigType.Shadowsocks:
                ret = ConfigHandler.AddShadowsocksServer(ref config, vmessItem);
                break;

            case EConfigType.Socks:
                ret = ConfigHandler.AddSocksServer(ref config, vmessItem);
                break;

            case EConfigType.VLESS:
                vmessItem.flow = flow;
                ret            = ConfigHandler.AddVlessServer(ref config, vmessItem);
                break;

            case EConfigType.Trojan:
                vmessItem.flow = flow;
                ret            = ConfigHandler.AddTrojanServer(ref config, vmessItem);
                break;
            }

            if (ret == 0)
            {
                DialogResult = DialogResult.OK;
            }
            else
            {
                UI.ShowWarning(ResUI.OperationFailed);
            }
        }