private void tsbSubUpdate_Click(object sender, EventArgs e) { v2rayHandler_ProcessEvent(false, "更新订阅开始"); if (config.subItem == null || config.subItem.Count <= 0) { v2rayHandler_ProcessEvent(false, "未设置有效的订阅"); return; } for (int k = 1; k <= config.subItem.Count; k++) { string id = config.subItem[k - 1].id.Trim(); string url = config.subItem[k - 1].url.Trim(); string hashCode = $"{k}->"; if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url)) { v2rayHandler_ProcessEvent(false, $"{hashCode}未设置有效的订阅"); continue; } V2rayUpdateHandle v2rayUpdateHandle3 = new V2rayUpdateHandle(); v2rayUpdateHandle3.UpdateCompleted += (sender2, args) => { if (args.Success) { v2rayHandler_ProcessEvent(false, $"{hashCode}获取订阅内容成功"); var result = Utils.Base64Decode(args.Msg); if (Utils.IsNullOrEmpty(result)) { v2rayHandler_ProcessEvent(false, $"{hashCode}订阅内容解码失败(非BASE64码)"); return; } ConfigHandler.RemoveServerViaSubid(ref config, id); v2rayHandler_ProcessEvent(false, $"{hashCode}清除原订阅内容"); RefreshServers(); if (AddBatchServers(result, id) == 0) { } else { v2rayHandler_ProcessEvent(false, $"{hashCode}导入订阅内容失败"); } v2rayHandler_ProcessEvent(false, $"{hashCode}更新订阅结束"); } else { v2rayHandler_ProcessEvent(false, args.Msg); } }; v2rayUpdateHandle3.Error += (sender2, args) => { v2rayHandler_ProcessEvent(true, args.GetException().Message); }; v2rayUpdateHandle3.WebDownloadString(url); v2rayHandler_ProcessEvent(false, $"{hashCode}开始获取订阅内容"); } }
private void InitSubItemAutoUpdate() { foreach (var item in config.subItem) { if (item.updateInterval != 0) { var url = item.url; var id = item.id; //若上次更新时间加更新间隔小于当前时间 则立即更新节点列表 if (item.lastUpdateTime + item.updateInterval * 3600 < Utils.DateTimeToUTCTimeStamp(DateTime.UtcNow)) { V2rayUpdateHandle subItemUpdateHandle = new V2rayUpdateHandle(); subItemUpdateHandle.UpdateCompleted += (sender, args) => { UpdateSubItem(item); }; subItemUpdateHandle.WebDownloadString(url); } System.Timers.Timer timer = new System.Timers.Timer(item.updateInterval * 3600 * 1000); timer.Elapsed += (sender, e) => { this.Invoke(new MethodInvoker(() => { UpdateSubItem(item); })); }; timer.Start(); } } }
private void tsbCheckUpdateCore_Click(object sender, EventArgs e) { if (v2rayUpdateHandle == null) { v2rayUpdateHandle = new V2rayUpdateHandle(); v2rayUpdateHandle.UpdateCompleted += (sender2, args) => { if (args.Success) { v2rayHandler_ProcessEvent(false, "下载V2rayCore成功!"); v2rayHandler_ProcessEvent(false, "正在解压......"); try { CloseV2ray(); string fileName = args.Msg; fileName = Utils.GetPath(fileName); using (ZipArchive archive = ZipFile.OpenRead(fileName)) { foreach (ZipArchiveEntry entry in archive.Entries) { if (entry.Length == 0) { continue; } entry.ExtractToFile(Utils.GetPath(entry.Name), true); } } v2rayHandler_ProcessEvent(false, "更新V2rayCore成功!正在重启服务..."); Global.reloadV2ray = true; LoadV2ray(); v2rayHandler_ProcessEvent(false, "更新V2rayCore成功!"); } catch (Exception ex) { v2rayHandler_ProcessEvent(false, ex.Message); } } else { v2rayHandler_ProcessEvent(false, args.Msg); } }; v2rayUpdateHandle.Error += (sender2, args) => { v2rayHandler_ProcessEvent(true, args.GetException().Message); }; } v2rayHandler_ProcessEvent(false, "开始更新V2rayCore..."); v2rayUpdateHandle.UpdateV2rayCore(config); }
private void UpdateSubItem(SubItem item) { string remark = item.remarks.Trim(); string url = item.url.Trim(); if (Utils.IsNullOrEmpty(remark) || Utils.IsNullOrEmpty(url)) { v2rayHandler_ProcessEvent(false, $"{remark}->未设置有效的订阅"); return; } V2rayUpdateHandle v2rayUpdateHandle3 = new V2rayUpdateHandle(); v2rayUpdateHandle3.UpdateCompleted += (sender2, args) => { if (args.Success) { v2rayHandler_ProcessEvent(false, $"{remark}->获取订阅内容成功"); var result = Utils.Base64Decode(args.Msg); if (Utils.IsNullOrEmpty(result)) { v2rayHandler_ProcessEvent(false, $"{remark}->订阅内容解码失败(非BASE64码)"); return; } ConfigHandler.RemoveServerViaSubid(ref config, item.id); v2rayHandler_ProcessEvent(false, $"{remark}->清除原订阅内容"); RefreshServers(); if (AddBatchServers(result, item.id) == 0) { } else { v2rayHandler_ProcessEvent(false, $"{remark}->导入订阅内容失败"); } v2rayHandler_ProcessEvent(false, $"{remark}->更新订阅结束"); item.lastUpdateTime = Utils.DateTimeToUTCTimeStamp(DateTime.UtcNow); } else { v2rayHandler_ProcessEvent(false, args.Msg); } }; v2rayUpdateHandle3.Error += (sender2, args) => { v2rayHandler_ProcessEvent(true, args.GetException().Message); }; v2rayUpdateHandle3.WebDownloadString(url); v2rayHandler_ProcessEvent(false, $"{remark}->开始获取订阅内容"); }
private void ServerSpeedTest() { if (config.vmess.Count <= 0) { return; } ClearTestResult(); string url = Global.SpeedTestUrl; testCounter = 0; if (v2rayUpdateHandle2 == null) { v2rayUpdateHandle2 = new V2rayUpdateHandle(); v2rayUpdateHandle2.UpdateCompleted += (sender2, args) => { if (args.Success) { v2rayHandler_ProcessEvent(false, args.Msg); SetTestResult(lvSelecteds[testCounter - 1], args.Msg); if (ServerSpeedTestSub(testCounter, url) != 0) { RefreshServers(); return; } } else { v2rayHandler_ProcessEvent(false, args.Msg); } }; v2rayUpdateHandle2.Error += (sender2, args) => { SetTestResult(lvSelecteds[testCounter - 1], args.GetException().Message); v2rayHandler_ProcessEvent(true, args.GetException().Message); if (ServerSpeedTestSub(testCounter, url) != 0) { RefreshServers(); return; } }; } if (ServerSpeedTestSub(testCounter, url) != 0) { return; } }
private void btnSetDefRountingRule_Click(object sender, EventArgs e) { var lstUrl = new List <string>(); lstUrl.Add(Global.CustomRoutingListUrl + "proxy"); lstUrl.Add(Global.CustomRoutingListUrl + "direct"); lstUrl.Add(Global.CustomRoutingListUrl + "block"); var lstTxt = new List <TextBox>(); lstTxt.Add(txtUseragent); lstTxt.Add(txtUserdirect); lstTxt.Add(txtUserblock); for (int k = 0; k < lstUrl.Count; k++) { var txt = lstTxt[k]; V2rayUpdateHandle v2rayUpdateHandle3 = new V2rayUpdateHandle(); v2rayUpdateHandle3.UpdateCompleted += (sender2, args) => { if (args.Success) { var result = args.Msg; if (Utils.IsNullOrEmpty(result)) { return; } txt.Text = result; } else { AppendText(false, args.Msg); } }; v2rayUpdateHandle3.Error += (sender2, args) => { AppendText(true, args.GetException().Message); }; v2rayUpdateHandle3.WebDownloadString(lstUrl[k]); } }
private void tsbCheckUpdateCore_Click(object sender, EventArgs e) { if (v2rayUpdateHandle == null) { v2rayUpdateHandle = new V2rayUpdateHandle(); v2rayUpdateHandle.AbsoluteCompleted += (sender2, args) => { if (args.Success) { v2rayHandler_ProcessEvent(false, "解析V2rayCore成功!"); string url = args.Msg; this.Invoke((MethodInvoker)(delegate { if (MessageBox.Show(this, "是否下载?\r\n" + url, "YesNo", MessageBoxButtons.YesNo) == DialogResult.No) { return; } else { v2rayUpdateHandle.UpdateV2rayCore(config, url); } })); } else { v2rayHandler_ProcessEvent(false, args.Msg); } }; v2rayUpdateHandle.UpdateCompleted += (sender2, args) => { if (args.Success) { v2rayHandler_ProcessEvent(false, "下载V2rayCore成功!"); v2rayHandler_ProcessEvent(false, "正在解压......"); try { CloseV2ray(); string fileName = v2rayUpdateHandle.DownloadFileName; fileName = Utils.GetPath(fileName); using (ZipArchive archive = ZipFile.OpenRead(fileName)) { foreach (ZipArchiveEntry entry in archive.Entries) { if (entry.Length == 0) { continue; } entry.ExtractToFile(Utils.GetPath(entry.Name), true); } } v2rayHandler_ProcessEvent(false, "更新V2rayCore成功!正在重启服务..."); Global.reloadV2ray = true; LoadV2ray(); v2rayHandler_ProcessEvent(false, "更新V2rayCore成功!"); } catch (Exception ex) { v2rayHandler_ProcessEvent(false, ex.Message); } } else { v2rayHandler_ProcessEvent(false, args.Msg); } }; v2rayUpdateHandle.Error += (sender2, args) => { v2rayHandler_ProcessEvent(true, args.GetException().Message); }; } v2rayHandler_ProcessEvent(false, "开始更新V2rayCore..."); v2rayUpdateHandle.AbsoluteV2rayCore(config); }
private void tsbSubUpdate_Click(object sender, EventArgs e) { AppendText(false, UIRes.I18N("MsgUpdateSubscriptionStart")); if (config.subItem == null || config.subItem.Count <= 0) { AppendText(false, UIRes.I18N("MsgNoValidSubscription")); return; } for (int k = 1; k <= config.subItem.Count; k++) { string id = config.subItem[k - 1].id.Trim(); string url = config.subItem[k - 1].url.Trim(); string hashCode = $"{k}->"; if (config.subItem[k - 1].enabled == false) { continue; } if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url)) { AppendText(false, $"{hashCode}{UIRes.I18N("MsgNoValidSubscription")}"); continue; } V2rayUpdateHandle v2rayUpdateHandle3 = new V2rayUpdateHandle(); v2rayUpdateHandle3.UpdateCompleted += (sender2, args) => { if (args.Success) { AppendText(false, $"{hashCode}{UIRes.I18N("MsgGetSubscriptionSuccessfully")}"); var result = Utils.Base64Decode(args.Msg); if (Utils.IsNullOrEmpty(result)) { AppendText(false, $"{hashCode}{UIRes.I18N("MsgSubscriptionDecodingFailed")}"); return; } ConfigHandler.RemoveServerViaSubid(ref config, id); AppendText(false, $"{hashCode}{UIRes.I18N("MsgClearSubscription")}"); RefreshServers(); if (AddBatchServers(result, id) == 0) { } else { AppendText(false, $"{hashCode}{UIRes.I18N("MsgFailedImportSubscription")}"); } AppendText(false, $"{hashCode}{UIRes.I18N("MsgUpdateSubscriptionEnd")}"); } else { AppendText(false, args.Msg); } }; v2rayUpdateHandle3.Error += (sender2, args) => { AppendText(true, args.GetException().Message); }; v2rayUpdateHandle3.WebDownloadString(url); AppendText(false, $"{hashCode}{UIRes.I18N("MsgStartGettingSubscriptions")}"); } }
private void tsbCheckUpdateCore_Click(object sender, EventArgs e) { if (v2rayUpdateHandle == null) { v2rayUpdateHandle = new V2rayUpdateHandle(); v2rayUpdateHandle.AbsoluteCompleted += (sender2, args) => { if (args.Success) { AppendText(false, UIRes.I18N("MsgParsingV2rayCoreSuccessfully")); string url = args.Msg; this.Invoke((MethodInvoker)(delegate { if (UI.ShowYesNo(string.Format(UIRes.I18N("DownloadYesNo"), url)) == DialogResult.No) { return; } else { v2rayUpdateHandle.DownloadFileAsync(config, url); } })); } else { AppendText(false, args.Msg); } }; v2rayUpdateHandle.UpdateCompleted += (sender2, args) => { if (args.Success) { AppendText(false, UIRes.I18N("MsgDownloadV2rayCoreSuccessfully")); AppendText(false, UIRes.I18N("MsgUnpacking")); try { CloseV2ray(); string fileName = v2rayUpdateHandle.DownloadFileName; fileName = Utils.GetPath(fileName); using (ZipArchive archive = ZipFile.OpenRead(fileName)) { foreach (ZipArchiveEntry entry in archive.Entries) { if (entry.Length == 0) { continue; } entry.ExtractToFile(Utils.GetPath(entry.Name), true); } } AppendText(false, UIRes.I18N("MsgUpdateV2rayCoreSuccessfullyMore")); Global.reloadV2ray = true; LoadV2ray(); AppendText(false, UIRes.I18N("MsgUpdateV2rayCoreSuccessfully")); } catch (Exception ex) { AppendText(false, ex.Message); } } else { AppendText(false, args.Msg); } }; v2rayUpdateHandle.Error += (sender2, args) => { AppendText(true, args.GetException().Message); }; } AppendText(false, UIRes.I18N("MsgStartUpdatingV2rayCore")); v2rayUpdateHandle.AbsoluteV2rayCore(config); }
public void tsbSubUpdate_Click(object sender, EventArgs e) { // 修改为PAC代理模式 menuGlobalPAC_Click(sender, e); //打出开始订阅 AppendText(false, UIRes.I18N("MsgUpdateSubscriptionStart")); //查找订阅地址 //if (config.subItem == null || config.subItem.Count <= 0) //{ // AppendText(false, UIRes.I18N("MsgNoValidSubscription")); // return; //} V2rayUpdateHandle v2rayUpdateHandle3 = new V2rayUpdateHandle(); v2rayUpdateHandle3.UpdateCompleted += (sender2, args) => { if (args.Success) { // 获取订阅内容成功 AppendText(false, UIRes.I18N("MsgGetSubscriptionSuccessfully")); SubResponse result = Utils.FromJson <SubResponse>(args.Msg); if (result.status != "SUCCESS") { login(); //引导去登录 AppendText(false, result.msg); } var subData = Utils.Base64Decode(result.data.data); if (Utils.IsNullOrEmpty(subData)) { // 解析失败 AppendText(false, UIRes.I18N("MsgSubscriptionDecodingFailed")); return; } var id = Utils.GetGUID(); //移除所有订阅服务器 ConfigHandler.RemoveServerViaSubid(ref config); AppendText(false, UIRes.I18N("MsgClearSubscription")); // 刷新界面显示 RefreshServers(); if (AddBatchServers(subData, id) == 0) { } else { AppendText(false, UIRes.I18N("MsgFailedImportSubscription")); } AppendText(false, UIRes.I18N("MsgUpdateSubscriptionEnd")); } else { AppendText(false, args.Msg); } }; v2rayUpdateHandle3.Error += (sender2, args) => { AppendText(true, args.GetException().Message); }; v2rayUpdateHandle3.WebDownloadString(Global.Subscribe); AppendText(false, UIRes.I18N("MsgStartGettingSubscriptions")); }
private void btn_login_click(object sender, EventArgs e) { var username = text_login_username.Text; if (Utils.IsNullOrEmpty(username)) { UI.Show(UIRes.I18N("MsgLoginEmptyUserName")); return; } var password = text_login_password.Text; if (Utils.IsNullOrEmpty(password)) { UI.Show(UIRes.I18N("MsgLoginEmptyPassword")); return; } if (password == "@HelloWorld@") { password = config.user.password; } else { password = password.Trim(); } V2rayUpdateHandle LoginPost = new V2rayUpdateHandle(); LoginPost.WebLogin(Global.Login, username, password); LoginPost.LoginCompleted += (serder2, args) => { loginResult = Utils.FromJson <LoginCompletedData>(args.Msg); if (loginResult.status == "SUCCESS") { //登录成功 if (config.user == null) { config.user = new UserConfig(); } config.user.username = username; config.user.password = password; config.user.token = loginResult.data.token; ConfigHandler.ToJsonFile(config); mainForm.tsbSubUpdate_Click(sender, e); this.Close(); } else { //登录失败 UI.Show(UIRes.I18N("MsgLoginUserNameAndPasswordNotMatch")); } }; LoginPost.Error += (sender2, args) => { UI.Show(args.GetException().Message); }; }