Browse Source

more reliable & maintainable extension methods

tags/3.0
Licshee 9 years ago
parent
commit
4a45d60c40
3 changed files with 6 additions and 4 deletions
  1. +1
    -1
      shadowsocks-csharp/Controller/I18N.cs
  2. +3
    -2
      shadowsocks-csharp/Controller/Service/GfwListUpdater.cs
  3. +2
    -1
      shadowsocks-csharp/Controller/ShadowsocksController.cs

+ 1
- 1
shadowsocks-csharp/Controller/I18N.cs View File

@@ -21,7 +21,7 @@ namespace Shadowsocks.Controller
string line; string line;
while ((line = sr.ReadLine()) != null) while ((line = sr.ReadLine()) != null)
{ {
if (line == "" || line[0] == '#')
if (line.BeginWith('#'))
continue; continue;
var pos = line.IndexOf('='); var pos = line.IndexOf('=');


+ 3
- 2
shadowsocks-csharp/Controller/Service/GfwListUpdater.cs View File

@@ -30,6 +30,7 @@ namespace Shadowsocks.Controller
} }
} }
private static readonly IEnumerable<char> IgnoredLineBegins = new[] { '!', '[' };
private void http_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) private void http_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{ {
try try
@@ -44,7 +45,7 @@ namespace Shadowsocks.Controller
string rule; string rule;
while ((rule = sr.ReadLine()) != null) while ((rule = sr.ReadLine()) != null)
{ {
if (rule == "" || rule[0] == '!' || rule[0] == '[')
if (rule.BeginWithAny(IgnoredLineBegins))
continue; continue;
lines.Add(rule); lines.Add(rule);
} }
@@ -102,7 +103,7 @@ namespace Shadowsocks.Controller
string line; string line;
while ((line = sr.ReadLine()) != null) while ((line = sr.ReadLine()) != null)
{ {
if (line == "" || line[0] == '!' || line[0] == '[')
if (line.BeginWithAny(IgnoredLineBegins))
continue; continue;
valid_lines.Add(line); valid_lines.Add(line);
} }


+ 2
- 1
shadowsocks-csharp/Controller/ShadowsocksController.cs View File

@@ -442,6 +442,7 @@ namespace Shadowsocks.Controller
UpdatePACFromGFWListError(this, e); UpdatePACFromGFWListError(this, e);
} }
private static readonly IEnumerable<char> IgnoredLineBegins = new[] { '!', '[' };
private void pacServer_UserRuleFileChanged(object sender, EventArgs e) private void pacServer_UserRuleFileChanged(object sender, EventArgs e)
{ {
// TODO: this is a dirty hack. (from code GListUpdater.http_DownloadStringCompleted()) // TODO: this is a dirty hack. (from code GListUpdater.http_DownloadStringCompleted())
@@ -459,7 +460,7 @@ namespace Shadowsocks.Controller
string rule; string rule;
while ((rule = sr.ReadLine()) != null) while ((rule = sr.ReadLine()) != null)
{ {
if (rule == "" || rule[0] == '!' || rule[0] == '[')
if (rule.BeginWithAny(IgnoredLineBegins))
continue; continue;
lines.Add(rule); lines.Add(rule);
} }


Loading…
Cancel
Save