Skip to content

Commit

Permalink
自定义规则使用user-rule.txt保存
Browse files Browse the repository at this point in the history
  • Loading branch information
tzang authored and clowwindy committed Mar 4, 2015
1 parent d4d3e80 commit 28887b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 13 additions & 1 deletion shadowsocks-csharp/Controller/GfwListUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class GFWListUpdater

private static string PAC_FILE = PACServer.PAC_FILE;

private static string USER_RULE_FILE = PACServer.USER_RULE_FILE;

public event EventHandler<ResultEventArgs> UpdateCompleted;

public event ErrorEventHandler Error;
Expand All @@ -35,7 +37,17 @@ private void http_DownloadStringCompleted(object sender, DownloadStringCompleted
try
{
List<string> lines = ParseResult(e.Result);

if (File.Exists(USER_RULE_FILE))
{
string local = File.ReadAllText(USER_RULE_FILE, Encoding.UTF8);
string[] rules = local.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
foreach(string rule in rules)
{
if (rule.StartsWith("!") || rule.StartsWith("["))
continue;
lines.Add(rule);
}
}
string abpContent = Utils.UnGzip(Resources.abp_js);
abpContent = abpContent.Replace("__RULES__", SimpleJson.SimpleJson.SerializeObject(lines));
if (File.Exists(PAC_FILE))
Expand Down
2 changes: 2 additions & 0 deletions shadowsocks-csharp/Controller/PACServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class PACServer : Listener.Service
{
public static string PAC_FILE = "pac.txt";

public static string USER_RULE_FILE = "user-rule.txt";

FileSystemWatcher watcher;
private Configuration _config;

Expand Down

0 comments on commit 28887b9

Please sign in to comment.