Browse Source

reformated source code

tags/3.0
kimw 8 years ago
parent
commit
22accf4a90
2 changed files with 25 additions and 35 deletions
  1. +6
    -12
      shadowsocks-csharp/Controller/Service/GfwListUpdater.cs
  2. +19
    -23
      shadowsocks-csharp/Controller/Service/PACServer.cs

+ 6
- 12
shadowsocks-csharp/Controller/Service/GfwListUpdater.cs View File

@@ -16,12 +16,6 @@ namespace Shadowsocks.Controller
{
private const string GFWLIST_URL = "https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt";
private static string PAC_FILE = PACServer.PAC_FILE;
private static string USER_RULE_FILE = PACServer.USER_RULE_FILE;
private static string USER_ABP_FILE = PACServer.USER_ABP_FILE;
public event EventHandler<ResultEventArgs> UpdateCompleted;
public event ErrorEventHandler Error;
@@ -42,9 +36,9 @@ namespace Shadowsocks.Controller
{
File.WriteAllText(Utils.GetTempPath("gfwlist.txt"), e.Result, Encoding.UTF8);
List<string> lines = ParseResult(e.Result);
if (File.Exists(USER_RULE_FILE))
if (File.Exists(PACServer.USER_RULE_FILE))
{
string local = File.ReadAllText(USER_RULE_FILE, Encoding.UTF8);
string local = File.ReadAllText(PACServer.USER_RULE_FILE, Encoding.UTF8);
string[] rules = local.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string rule in rules)
{
@@ -54,9 +48,9 @@ namespace Shadowsocks.Controller
}
}
string abpContent;
if (File.Exists(USER_ABP_FILE))
if (File.Exists(PACServer.USER_ABP_FILE))
{
abpContent = File.ReadAllText(USER_ABP_FILE, Encoding.UTF8);
abpContent = File.ReadAllText(PACServer.USER_ABP_FILE, Encoding.UTF8);
}
else
{
@@ -65,14 +59,14 @@ namespace Shadowsocks.Controller
abpContent = abpContent.Replace("__RULES__", JsonConvert.SerializeObject(lines, Formatting.Indented));
if (File.Exists(PACServer.PAC_FILE))
{
string original = File.ReadAllText(PAC_FILE, Encoding.UTF8);
string original = File.ReadAllText(PACServer.PAC_FILE, Encoding.UTF8);
if (original == abpContent)
{
UpdateCompleted(this, new ResultEventArgs(false));
return;
}
}
File.WriteAllText(PAC_FILE, abpContent, Encoding.UTF8);
File.WriteAllText(PACServer.PAC_FILE, abpContent, Encoding.UTF8);
if (UpdateCompleted != null)
{
UpdateCompleted(this, new ResultEventArgs(true));


+ 19
- 23
shadowsocks-csharp/Controller/Service/PACServer.cs View File

@@ -1,23 +1,21 @@
using Shadowsocks.Model;
using Shadowsocks.Properties;
using Shadowsocks.Util;
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Net.Sockets;
using System.Text;
using Shadowsocks.Model;
using Shadowsocks.Properties;
using Shadowsocks.Util;
namespace Shadowsocks.Controller
{
class PACServer : Listener.Service
{
public static string PAC_FILE = "pac.txt";
public static string USER_RULE_FILE = "user-rule.txt";
public static string USER_ABP_FILE = "abp.txt";
public static readonly string PAC_FILE = "pac.txt";
public static readonly string USER_RULE_FILE = "user-rule.txt";
public static readonly string USER_ABP_FILE = "abp.txt";
FileSystemWatcher PACFileWatcher;
FileSystemWatcher UserRuleFileWatcher;
@@ -50,7 +48,7 @@ namespace Shadowsocks.Controller
bool hostMatch = false, pathMatch = false, useSocks = false;
foreach (string line in lines)
{
string[] kv = line.Split(new char[]{':'}, 2);
string[] kv = line.Split(new char[] { ':' }, 2);
if (kv.Length == 2)
{
if (kv[0] == "Host")
@@ -60,14 +58,14 @@ namespace Shadowsocks.Controller
hostMatch = true;
}
}
else if (kv[0] == "User-Agent")
{
// we need to drop connections when changing servers
/* if (kv[1].IndexOf("Chrome") >= 0)
{
useSocks = true;
} */
}
//else if (kv[0] == "User-Agent")
//{
// // we need to drop connections when changing servers
// if (kv[1].IndexOf("Chrome") >= 0)
// {
// useSocks = true;
// }
//}
}
else if (kv.Length == 1)
{
@@ -202,7 +200,6 @@ Connection: Close
}
#region FileSystemWatcher.OnChanged()
// FileSystemWatcher Changed event is raised twice
// http://stackoverflow.com/questions/1764809/filesystemwatcher-changed-event-is-raised-twice
private static Hashtable fileChangedTime = new Hashtable();
@@ -221,7 +218,7 @@ Connection: Close
PACFileChanged(this, new EventArgs());
}
//lastly we update the last write time in the hashtable
// lastly we update the last write time in the hashtable
fileChangedTime[path] = currentLastWriteTime;
}
}
@@ -239,11 +236,10 @@ Connection: Close
Logging.Info($"Detected: User Rule file '{e.Name}' was {e.ChangeType.ToString().ToLower()}.");
UserRuleFileChanged(this, new EventArgs());
}
//lastly we update the last write time in the hashtable
// lastly we update the last write time in the hashtable
fileChangedTime[path] = currentLastWriteTime;
}
}
#endregion
private string GetPACAddress(byte[] requestBuf, int length, IPEndPoint localEndPoint, bool useSocks)


Loading…
Cancel
Save