예제 #1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string url = txtUrl.Text;

            if (Utils.IsNullOrEmpty(url))
            {
                UI.Show(UIRes.I18N("PleaseFillUrl"));
                return;
            }

            string configFileName = txtConfigFileName.Text;

            if (Utils.IsNullOrEmpty(configFileName))
            {
                UI.Show(UIRes.I18N("PleaseFillConfigFileName"));
                return;
            }

            string remark = txtRemarks.Text;

            if (Utils.IsNullOrEmpty(remark))
            {
                UI.Show(UIRes.I18N("PleaseFillRemarks"));
                return;
            }

            if (!Utils.UrlIsExists(url))
            {
                UI.ShowWarning("无效的地址!!!");
                return;
            }

            var configContent = Utils.GetRemoteCustomConfig(url);

            if (string.IsNullOrEmpty(configContent))
            {
                UI.ShowWarning("远程配置文件为空!!!");
                return;
            }

            vmessItem.url            = url;
            vmessItem.configFileName = configFileName + ".json";
            vmessItem.address        = "customConf/" + vmessItem.configFileName;
            vmessItem.remarks        = remark;
            vmessItem.configType     = (int)EConfigType.Custom;

            //创建配置文件
            if (!Directory.Exists("customConf"))
            {
                Directory.CreateDirectory("customConf");
            }

            File.WriteAllText(vmessItem.address, configContent);

            if (ConfigHandler.AddCustomServerUrl(ref config, vmessItem) == 0)
            {
                //刷新
                UI.Show(UIRes.I18N("SuccessfullyImportedCustomServer"));
                Close();
            }
            else
            {
                UI.ShowWarning(UIRes.I18N("FailedImportedCustomServer"));
            }
        }