diff --git a/shadowsocks-csharp/Controller/GfwListUpdater.cs b/shadowsocks-csharp/Controller/GfwListUpdater.cs index c377efd2..2bebdcbf 100644 --- a/shadowsocks-csharp/Controller/GfwListUpdater.cs +++ b/shadowsocks-csharp/Controller/GfwListUpdater.cs @@ -90,180 +90,6 @@ namespace Shadowsocks.Controller return valid_lines.ToArray(); } - /* refer https://github.com/clowwindy/gfwlist2pac/blob/master/gfwlist2pac/main.py */ - public string[] GetDomains() - { - List lines = new List(GetValidLines()); - lines.AddRange(GetBuildIn()); - List domains = new List(lines.Count); - for (int i = 0; i < lines.Count; i++) - { - string line = lines[i]; - if (line.IndexOf(".*") >= 0) - continue; - if (line.StartsWith("http://")) - line = line.Substring(7); - else if (line.StartsWith("https://")) - line = line.Substring(8); - if (line.IndexOf("*") >= 0) - line = line.Replace("*", "/"); - if (line.StartsWith("||")) - while (line.StartsWith("||")) - line = line.Substring(2); - else if (line.StartsWith("|")) - line = line.TrimStart('|'); - else if (line.StartsWith(".")) - line = line.TrimStart('.'); - if (line.StartsWith("!")) - continue; - else if (line.StartsWith("[")) - continue; - else if (line.StartsWith("@")) - continue; /*ignore white list*/ - int pos = line.IndexOfAny(new char[] { '/' }); - if (pos >= 0) - line = line.Substring(0, pos); - if (line.Length > 0) - domains.Add(line); - } - return RemoveDuplicate(domains.ToArray()); - } - - /* refer https://github.com/clowwindy/gfwlist2pac/blob/master/gfwlist2pac/main.py */ - public string[] GetReducedDomains() - { - string[] domains = GetDomains(); - List new_domains = new List(domains.Length); - TldIndex tldIndex = GetTldIndex(); - - foreach (string domain in domains) - { - string last_root_domain = null; - int pos; - pos = domain.LastIndexOf('.'); - last_root_domain = domain.Substring(pos + 1); - if (!tldIndex.Contains(last_root_domain)) - continue; - while (pos > 0) - { - pos = domain.LastIndexOf('.', pos - 1); - last_root_domain = domain.Substring(pos + 1); - if (tldIndex.Contains(last_root_domain)) - continue; - else - break; - } - if (last_root_domain != null) - new_domains.Add(last_root_domain); - } - - return RemoveDuplicate(new_domains.ToArray()); - } - - private string[] RemoveDuplicate(string[] src) - { - List list = new List(src.Length); - Dictionary dic = new Dictionary(src.Length); - foreach (string s in src) - { - if (!dic.ContainsKey(s)) - { - dic.Add(s, s); - list.Add(s); - } - } - return list.ToArray(); - } - - private string[] GetTlds() - { - string[] tlds = null; - byte[] pacGZ = Resources.tld_txt; - byte[] buffer = new byte[1024]; - int n; - using (MemoryStream sb = new MemoryStream()) - { - using (GZipStream input = new GZipStream(new MemoryStream(pacGZ), - CompressionMode.Decompress, false)) - { - while ((n = input.Read(buffer, 0, buffer.Length)) > 0) - { - sb.Write(buffer, 0, n); - } - } - tlds = System.Text.Encoding.UTF8.GetString(sb.ToArray()) - .Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); - } - return tlds; - } - - private TldIndex GetTldIndex() - { - string[] tlds = GetTlds(); - TldIndex index = new TldIndex(); - foreach (string tld in tlds) - { - index.Add(tld); - } - return index; - } - - private string[] GetBuildIn() - { - string[] buildin = null; - byte[] builtinGZ = Resources.builtin_txt; - byte[] buffer = new byte[1024]; - int n; - using (MemoryStream sb = new MemoryStream()) - { - using (GZipStream input = new GZipStream(new MemoryStream(builtinGZ), - CompressionMode.Decompress, false)) - { - while ((n = input.Read(buffer, 0, buffer.Length)) > 0) - { - sb.Write(buffer, 0, n); - } - } - buildin = System.Text.Encoding.UTF8.GetString(sb.ToArray()) - .Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); - } - return buildin; - } - - public class TldIndex - { - List patterns = new List(); - IDictionary dic = new Dictionary(); - - public void Add(string tld) - { - if (string.IsNullOrEmpty(tld)) - return; - if (tld.IndexOfAny(new char[] { '*', '?' }) >= 0) - { - patterns.Add("^" + Regex.Escape(tld).Replace("\\*", ".*").Replace("\\?", ".") + "$"); - } - else if (!dic.ContainsKey(tld)) - { - dic.Add(tld, tld); - } - } - - public bool Contains(string tld) - { - if (dic.ContainsKey(tld)) - return true; - foreach (string pattern in patterns) - { - if (Regex.IsMatch(tld, pattern)) - return true; - } - return false; - } - - } - - } } diff --git a/shadowsocks-csharp/Data/builtin.txt.gz b/shadowsocks-csharp/Data/builtin.txt.gz deleted file mode 100644 index c846e644..00000000 Binary files a/shadowsocks-csharp/Data/builtin.txt.gz and /dev/null differ diff --git a/shadowsocks-csharp/Data/tld.txt.gz b/shadowsocks-csharp/Data/tld.txt.gz deleted file mode 100644 index 693a6e8c..00000000 Binary files a/shadowsocks-csharp/Data/tld.txt.gz and /dev/null differ diff --git a/shadowsocks-csharp/Properties/Resources.Designer.cs b/shadowsocks-csharp/Properties/Resources.Designer.cs index c4bfead9..5139429f 100755 --- a/shadowsocks-csharp/Properties/Resources.Designer.cs +++ b/shadowsocks-csharp/Properties/Resources.Designer.cs @@ -71,16 +71,6 @@ namespace Shadowsocks.Properties { } /// - /// Looks up a localized resource of type System.Byte[]. - /// - internal static byte[] builtin_txt { - get { - object obj = ResourceManager.GetObject("builtin_txt", resourceCulture); - return ((byte[])(obj)); - } - } - - /// /// Looks up a localized string similar to Shadowsocks=Shadowsocks ///Enable=启用代理 ///Mode=代理模式 @@ -205,15 +195,5 @@ namespace Shadowsocks.Properties { return ((System.Drawing.Bitmap)(obj)); } } - - /// - /// Looks up a localized resource of type System.Byte[]. - /// - internal static byte[] tld_txt { - get { - object obj = ResourceManager.GetObject("tld_txt", resourceCulture); - return ((byte[])(obj)); - } - } } } diff --git a/shadowsocks-csharp/Properties/Resources.resx b/shadowsocks-csharp/Properties/Resources.resx index 24d1b168..ee5f98ea 100755 --- a/shadowsocks-csharp/Properties/Resources.resx +++ b/shadowsocks-csharp/Properties/Resources.resx @@ -121,9 +121,6 @@ ..\Data\abp.js.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - ..\Data\builtin.txt.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - ..\data\cn.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 @@ -151,7 +148,4 @@ ..\Resources\ssw128.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Data\tld.txt.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - \ No newline at end of file diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 314ea6a3..1848edd9 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -102,6 +102,11 @@ + + True + True + Resources.resx + Form @@ -128,14 +133,9 @@ ResXFileCodeGenerator - Resources.Designer.cs Designer + Resources.Designer.cs - - True - Resources.resx - True - QRCodeForm.cs @@ -144,13 +144,11 @@ Designer - -