private void buttonAddSub_Click(object sender, EventArgs e) { string url = textBoxSubUrl.Text; if (url.Length > 0) { string remark = textBoxRemark.Text; if (remark.Length == 0) { remark = "new" + (Program.subsProfiles.Count); } SubsProfile sub = new SubsProfile(url, remark); sub.groupId = Program.subsProfiles.Count(); while (Program.groupSubsMap.ContainsKey(sub.groupId)) { sub.groupId++; } Program.subsProfiles.Add(sub); Program.subsProfiles[0].SubsRefList.Add(sub); Program.groupSubsMap.Add(sub.groupId, sub); DataRow dr = Program.dt.NewRow(); dr["remark"] = remark; dr["url"] = url; //dr["groupId"] = sub.groupId; Program.dt.Rows.Add(dr); Program.bs.ResetBindings(false); listBoxSubs.Items.Add(remark + "-" + url); } }
public static SubsProfile readingJson(string path) { string jsonStr = getJsonStr(path); SubsProfile temp = js.Deserialize <SubsProfile>(jsonStr); return(temp); }
public static void writingJson(SubsProfile subsProfile, string dir = "") { string filename = Utils.MD5Sum(subsProfile.remark + "-" + subsProfile.url); string json = js.Serialize(subsProfile); save(string.Format("{0}\\{1}.json", dir, filename), json); }
private static void readSubsData() { string filepath = string.Format("{0}\\{1}.json", SubsSaveDir, Utils.MD5Sum("-")); if (File.Exists(filepath)) { SubsProfile tmp = IOSerialize.readingJson(filepath); subsProfiles[0] = tmp; } }
void subscribeWorker_DoWork2(object sender, DoWorkEventArgs e) { SubsProfile subsProfile = (SubsProfile)e.Argument; subsProfiles.Clear(); if (subsProfile.VmessConfList.Count > 0) { subsProfile.VmessConfList.Clear(); } var tag = ImportURL(Utils.Base64Decode(Utils.GetUrl(subsProfile.url)), subsProfile); refreshListServBox(); }
void subscribeWorker_DoWork(object sender, DoWorkEventArgs e) { subsProfiles.Clear(); for (int i = 1; i < Program.subsProfiles.Count; i++) { SubsProfile item = Program.subsProfiles[i]; if (item.VmessConfList.Count > 0) { item.VmessConfList.Clear(); } var tag = ImportURL(Utils.Base64Decode(Utils.GetUrl(item.url)), item); } refreshListServBox(); }
List <string> ImportURL(string importUrl, SubsProfile subsProfile) { List <string> linkMark = new List <string>(); foreach (var link in importUrl.Split(Environment.NewLine.ToCharArray())) { if (link.StartsWith("vmess")) { ServerProfile sp = ImportVmess(link); linkMark.Add(sp.remark); sp.groupId = subsProfile.groupId; subsProfile.VmessConfList.Add(sp); subsProfiles.Add(sp); } } Debug.WriteLine("importurl " + String.Join(",", linkMark)); return(linkMark); }
private void updateUrl(SubsProfile subsProfile) { try { BackgroundWorker subscribeWorker = new BackgroundWorker(); subscribeWorker.WorkerSupportsCancellation = true; subscribeWorker.DoWork += subscribeWorker_DoWork2; if (subscribeWorker.IsBusy) { return; } subscribeWorker.RunWorkerAsync(subsProfile); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "request timeout"); return; } }
private void buttonRemove_Click(object sender, EventArgs e) { var selectedIndex = listBoxSubs.SelectedIndex; if (selectedIndex > 0 && selectedIndex < Program.subsProfiles.Count) { listBoxSubs.Items.RemoveAt(selectedIndex); listBoxSubs.SelectedIndex = listBoxSubs.Items.Count - 1; SubsProfile deletedSubs = Program.subsProfiles[selectedIndex]; Program.subsProfiles.Remove(deletedSubs); Program.subsProfiles[0].SubsRefList.Remove(deletedSubs); deletedSubs.VmessConfList.Clear(); if (Program.groupSubsMap.ContainsKey(deletedSubs.groupId)) { Program.groupSubsMap.Remove(deletedSubs.groupId); } Program.dt.Rows.RemoveAt(selectedIndex); Program.bs.ResetBindings(false); } }