Browse Source

not update all pac.txt, but only update the rules

tags/3.2
Gang Zhuo 10 years ago
parent
commit
075069ef16
1 changed files with 16 additions and 2 deletions
  1. +16
    -2
      shadowsocks-csharp/Controller/PACServer.cs

+ 16
- 2
shadowsocks-csharp/Controller/PACServer.cs View File

@@ -8,6 +8,7 @@ using System.IO.Compression;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
namespace Shadowsocks.Controller namespace Shadowsocks.Controller
{ {
@@ -264,7 +265,7 @@ Connection: Close
SerializeRules(lines, rules); SerializeRules(lines, rules);
string abpContent = GetAbpContent(); string abpContent = GetAbpContent();
abpContent = abpContent.Replace("__RULES__", rules.ToString()); abpContent = abpContent.Replace("__RULES__", rules.ToString());
File.WriteAllText(PAC_FILE, abpContent);
File.WriteAllText(PAC_FILE, abpContent, Encoding.UTF8);
if (UpdatePACFromGFWListCompleted != null) if (UpdatePACFromGFWListCompleted != null)
{ {
UpdatePACFromGFWListCompleted(this, new EventArgs()); UpdatePACFromGFWListCompleted(this, new EventArgs());
@@ -281,6 +282,18 @@ Connection: Close
private string GetAbpContent() private string GetAbpContent()
{ {
string content;
if (File.Exists(PAC_FILE))
{
content = File.ReadAllText(PAC_FILE, Encoding.UTF8);
Regex regex = new Regex("var\\s+rules\\s*=\\s*(\\[(\\s*\"[^\"]*\"\\s*,)*(\\s*\"[^\"]*\")\\s*\\])", RegexOptions.Singleline);
Match m = regex.Match(content);
if (m.Success)
{
content = regex.Replace(content, "var rules = __RULES__");
return content;
}
}
byte[] abpGZ = Resources.abp_js; byte[] abpGZ = Resources.abp_js;
byte[] buffer = new byte[1024]; // builtin pac gzip size: maximum 100K byte[] buffer = new byte[1024]; // builtin pac gzip size: maximum 100K
int n; int n;
@@ -294,8 +307,9 @@ Connection: Close
sb.Write(buffer, 0, n); sb.Write(buffer, 0, n);
} }
} }
return System.Text.Encoding.UTF8.GetString(sb.ToArray());
content = System.Text.Encoding.UTF8.GetString(sb.ToArray());
} }
return content;
} }
private static void SerializeRules(string[] rules, StringBuilder builder) private static void SerializeRules(string[] rules, StringBuilder builder)


Loading…
Cancel
Save