/// <summary> /// Clean Patch file /// </summary> /// <param name="chinaList"></param> /// <param name="proxy"></param> public static void CleanConfigurations(string chinaList, WebProxy proxy) { if (DownloadEasyList(null)) { Configurations patchConfig = ChinaLists.GetConfigurations(); if (patchConfig == null) { Console.WriteLine("wrong Patch Confguration file."); return; } StringBuilder sBuilder = new StringBuilder(); using (StreamReader sr = new StreamReader(chinaList, Encoding.UTF8)) { sBuilder.Append(sr.ReadToEnd()); } using (StreamReader sr = new StreamReader(ChinaListConst.EASYLIST, Encoding.UTF8)) { sBuilder.Append(sr.ReadToEnd()); } using (StreamReader sr = new StreamReader(ChinaListConst.EASYPRIVACY, Encoding.UTF8)) { sBuilder.Append(sr.ReadToEnd()); } string s = sBuilder.ToString(); List <string> removedItems = new List <string>(patchConfig.RemovedItems); foreach (var item in patchConfig.RemovedItems) { if (s.IndexOf(item) > -1) { continue; } removedItems.Remove(item); } List <ModifyItem> modifyItems = new List <ModifyItem>(patchConfig.ModifyItems); foreach (var item in patchConfig.ModifyItems) { if (s.IndexOf(item.OldItem) > -1) { continue; } modifyItems.Remove(item); } patchConfig.ModifyItems = modifyItems; patchConfig.RemovedItems = removedItems; string xml = SimpleSerializer.XmlSerialize <Configurations>(patchConfig); Save(ChinaListConst.PATCH_FILE, xml); } }
/// <summary> /// update list /// </summary> public void Update() { string content = ReadList(); content = UpdateTime(content); content = RemoveChecksum(content); string result = UpdateCheckSum(content); ChinaLists.Save(FileName, result); }
private static void DispatcherTask(Arguments args) { if (args.IsTrue("help") || args.IsTrue("h")) { Console.WriteLine(ChinaListConst.HELP_INFO, DateTime.Now.ToString("yyyy")); } else if (args.IsTrue("version")) { Console.WriteLine("ABPUtils version: {0}", ChinaLists.GetVersion()); } else if (args.IsTrue("ns") || args.IsTrue("nslookup")) { var domain = args.Single("d"); if (string.IsNullOrEmpty(domain)) { domain = args.Single("domain"); } if (string.IsNullOrEmpty(domain)) { Console.WriteLine("wrong input domain."); return; } QueryResult result = null; if (string.IsNullOrEmpty(args.Single("dns"))) { result = ChinaLists.DNSQuery(null, domain); } else { result = ChinaLists.DNSQuery(IPAddress.Parse(args.Single("dns")), domain); } if (result == null) { Console.WriteLine("Query result is null."); } else { Console.Write(result.ToString()); } } else if (args.IsTrue("v") || args.IsTrue("validate")) { var input = args.Single("i"); if (string.IsNullOrEmpty(input)) { input = args.Single("input"); } if (string.IsNullOrEmpty(input)) { Console.WriteLine("wrong input file."); return; } var chinaList = new ChinaList(input); chinaList.Validate(); } else if (args.IsTrue("u") || args.IsTrue("update")) { var input = args.Single("i"); if (string.IsNullOrEmpty(input)) { input = args.Single("input"); } if (string.IsNullOrEmpty(input)) { Console.WriteLine("wrong input file."); return; } var chinaList = new ChinaList(input); chinaList.Update(); chinaList.Validate(); } else if (args.IsTrue("c") || args.IsTrue("check")) { var input = args.Single("i"); if (string.IsNullOrEmpty(input)) { input = args.Single("input"); } if (string.IsNullOrEmpty(input)) { Console.WriteLine("wrong input file."); return; } var output = args.Single("o"); if (string.IsNullOrEmpty(output)) { output = args.Single("output"); } var dns = args.Single("dns"); if (string.IsNullOrEmpty(dns)) { ChinaLists.ValidateDomains(null, input, output); } else { ChinaLists.ValidateDomains(IPAddress.Parse(args.Single("dns")), input, output); } } else if (args.IsTrue("m") || args.IsTrue("merge")) { var input = string.Empty; input = args.Single("i"); if (string.IsNullOrEmpty(input)) { input = args.Single("input"); } if (string.IsNullOrEmpty(input)) { Console.WriteLine("wrong input file."); return; } WebProxy proxy = null; var p = args.Single("p"); if (string.IsNullOrEmpty(p)) { p = args.Single("proxy"); } if (!string.IsNullOrEmpty(p)) { var temp = p.Split(':'); proxy = new WebProxy(temp[0], int.Parse(temp[1])); proxy.BypassProxyOnLocal = true; } var output = args.Single("o"); if (string.IsNullOrEmpty(output)) { output = args.Single("output"); } ChinaLists.Merge(input, proxy, args.IsTrue("patch"), output); } else if (args.IsTrue("conf")) { var input = string.Empty; input = args.Single("i"); if (string.IsNullOrEmpty(input)) { input = args.Single("input"); } if (string.IsNullOrEmpty(input)) { Console.WriteLine("wrong input file."); return; } ChinaLists.CleanConfigurations(input, null); Console.WriteLine("Clean configuration file successful."); } else { Console.WriteLine("Wrong args"); } }