@@ -12,8 +12,8 @@ namespace Shadowsocks.Controller | |||||
{ | { | ||||
public static string LogFilePath; | public static string LogFilePath; | ||||
private static FileStream fs; | |||||
private static StreamWriterWithTimestamp sw; | |||||
private static FileStream _fs; | |||||
private static StreamWriterWithTimestamp _sw; | |||||
public static bool OpenLogFile() | public static bool OpenLogFile() | ||||
{ | { | ||||
@@ -21,11 +21,11 @@ namespace Shadowsocks.Controller | |||||
{ | { | ||||
LogFilePath = Utils.GetTempPath("shadowsocks.log"); | LogFilePath = Utils.GetTempPath("shadowsocks.log"); | ||||
fs = new FileStream(LogFilePath, FileMode.Append); | |||||
sw = new StreamWriterWithTimestamp(fs); | |||||
sw.AutoFlush = true; | |||||
Console.SetOut(sw); | |||||
Console.SetError(sw); | |||||
_fs = new FileStream(LogFilePath, FileMode.Append); | |||||
_sw = new StreamWriterWithTimestamp(_fs); | |||||
_sw.AutoFlush = true; | |||||
Console.SetOut(_sw); | |||||
Console.SetError(_sw); | |||||
return true; | return true; | ||||
} | } | ||||
@@ -54,11 +54,11 @@ namespace Shadowsocks.Controller | |||||
WriteToLogFile(o); | WriteToLogFile(o); | ||||
} | } | ||||
public static void clear() { | |||||
sw.Close(); | |||||
sw.Dispose(); | |||||
fs.Close(); | |||||
fs.Dispose(); | |||||
public static void Clear() { | |||||
_sw.Close(); | |||||
_sw.Dispose(); | |||||
_fs.Close(); | |||||
_fs.Dispose(); | |||||
File.Delete(LogFilePath); | File.Delete(LogFilePath); | ||||
OpenLogFile(); | OpenLogFile(); | ||||
} | } | ||||
@@ -1,5 +1,6 @@ | |||||
using System; | using System; | ||||
using System.Collections; | using System.Collections; | ||||
using System.Globalization; | |||||
using System.IO; | using System.IO; | ||||
using System.Net; | using System.Net; | ||||
using System.Net.Sockets; | using System.Net.Sockets; | ||||
@@ -69,7 +70,7 @@ namespace Shadowsocks.Controller | |||||
} | } | ||||
else if (kv.Length == 1) | else if (kv.Length == 1) | ||||
{ | { | ||||
if (line.IndexOf("pac") >= 0) | |||||
if (line.IndexOf("pac", StringComparison.Ordinal) >= 0) | |||||
{ | { | ||||
pathMatch = true; | pathMatch = true; | ||||
} | } | ||||
@@ -207,7 +208,7 @@ Connection: Close | |||||
private void PACFileWatcher_Changed(object sender, FileSystemEventArgs e) | private void PACFileWatcher_Changed(object sender, FileSystemEventArgs e) | ||||
{ | { | ||||
string path = e.FullPath.ToString(); | string path = e.FullPath.ToString(); | ||||
string currentLastWriteTime = File.GetLastWriteTime(e.FullPath).ToString(); | |||||
string currentLastWriteTime = File.GetLastWriteTime(e.FullPath).ToString(CultureInfo.InvariantCulture); | |||||
// if there is no path info stored yet or stored path has different time of write then the one now is inspected | // if there is no path info stored yet or stored path has different time of write then the one now is inspected | ||||
if (!fileChangedTime.ContainsKey(path) || fileChangedTime[path].ToString() != currentLastWriteTime) | if (!fileChangedTime.ContainsKey(path) || fileChangedTime[path].ToString() != currentLastWriteTime) | ||||
@@ -226,7 +227,7 @@ Connection: Close | |||||
private void UserRuleFileWatcher_Changed(object sender, FileSystemEventArgs e) | private void UserRuleFileWatcher_Changed(object sender, FileSystemEventArgs e) | ||||
{ | { | ||||
string path = e.FullPath.ToString(); | string path = e.FullPath.ToString(); | ||||
string currentLastWriteTime = File.GetLastWriteTime(e.FullPath).ToString(); | |||||
string currentLastWriteTime = File.GetLastWriteTime(e.FullPath).ToString(CultureInfo.InvariantCulture); | |||||
// if there is no path info stored yet or stored path has different time of write then the one now is inspected | // if there is no path info stored yet or stored path has different time of write then the one now is inspected | ||||
if (!fileChangedTime.ContainsKey(path) || fileChangedTime[path].ToString() != currentLastWriteTime) | if (!fileChangedTime.ContainsKey(path) || fileChangedTime[path].ToString() != currentLastWriteTime) | ||||
@@ -176,7 +176,13 @@ namespace Shadowsocks.Controller | |||||
Server server = controller.GetAServer(IStrategyCallerType.TCP, (IPEndPoint)connection.RemoteEndPoint); | Server server = controller.GetAServer(IStrategyCallerType.TCP, (IPEndPoint)connection.RemoteEndPoint); | ||||
if (server == null || server.server == "") | if (server == null || server.server == "") | ||||
throw new ArgumentException("No server configured"); | throw new ArgumentException("No server configured"); | ||||
encryptor = EncryptorFactory.GetEncryptor(server.method, server.password, server.auth, false); | |||||
lock (_encryptionLock) | |||||
{ | |||||
lock (_decryptionLock) | |||||
{ | |||||
encryptor = EncryptorFactory.GetEncryptor(server.method, server.password, server.auth, false); | |||||
} | |||||
} | |||||
this.server = server; | this.server = server; | ||||
} | } | ||||
@@ -198,7 +198,7 @@ namespace Shadowsocks.Controller | |||||
name = (string)asset["name"]; | name = (string)asset["name"]; | ||||
browser_download_url = (string)asset["browser_download_url"]; | browser_download_url = (string)asset["browser_download_url"]; | ||||
version = ParseVersionFromURL(browser_download_url); | version = ParseVersionFromURL(browser_download_url); | ||||
prerelease = browser_download_url.IndexOf("prerelease") >= 0; | |||||
prerelease = browser_download_url.IndexOf("prerelease", StringComparison.Ordinal) >= 0; | |||||
} | } | ||||
private static string ParseVersionFromURL(string url) | private static string ParseVersionFromURL(string url) | ||||
@@ -247,7 +247,7 @@ namespace Shadowsocks.View | |||||
#region Clean up the content in LogMessageTextBox. | #region Clean up the content in LogMessageTextBox. | ||||
private void DoCleanLogs() | private void DoCleanLogs() | ||||
{ | { | ||||
Logging.clear(); | |||||
Logging.Clear(); | |||||
lastOffset = 0; | lastOffset = 0; | ||||
LogMessageTextBox.Clear(); | LogMessageTextBox.Clear(); | ||||
} | } | ||||