diff --git a/v2rayN/v2rayN/HttpProxyHandler/HttpWebServer.cs b/v2rayN/v2rayN/Base/HttpWebServer.cs similarity index 98% rename from v2rayN/v2rayN/HttpProxyHandler/HttpWebServer.cs rename to v2rayN/v2rayN/Base/HttpWebServer.cs index 906f26d9..152dcab9 100644 --- a/v2rayN/v2rayN/HttpProxyHandler/HttpWebServer.cs +++ b/v2rayN/v2rayN/Base/HttpWebServer.cs @@ -3,7 +3,7 @@ using System.Net; using System.Text; using System.Threading; -namespace v2rayN.HttpProxyHandler +namespace v2rayN.Base { public class HttpWebServer { diff --git a/v2rayN/v2rayN/HttpProxyHandler/HttpWebServerB.cs b/v2rayN/v2rayN/Base/HttpWebServerB.cs similarity index 97% rename from v2rayN/v2rayN/HttpProxyHandler/HttpWebServerB.cs rename to v2rayN/v2rayN/Base/HttpWebServerB.cs index 78cbb0fc..0aef834b 100644 --- a/v2rayN/v2rayN/HttpProxyHandler/HttpWebServerB.cs +++ b/v2rayN/v2rayN/Base/HttpWebServerB.cs @@ -1,12 +1,10 @@ using System; -using System.Collections; using System.IO; using System.Net; using System.Net.Sockets; -using System.Text; using System.Threading; -namespace v2rayN.HttpProxyHandler +namespace v2rayN.Base { public class HttpWebServerB { diff --git a/v2rayN/v2rayN/Forms/ListViewFlickerFree.cs b/v2rayN/v2rayN/Base/ListViewFlickerFree.cs similarity index 98% rename from v2rayN/v2rayN/Forms/ListViewFlickerFree.cs rename to v2rayN/v2rayN/Base/ListViewFlickerFree.cs index 6b7cb451..7fc58205 100644 --- a/v2rayN/v2rayN/Forms/ListViewFlickerFree.cs +++ b/v2rayN/v2rayN/Base/ListViewFlickerFree.cs @@ -1,7 +1,7 @@ using System.Drawing; using System.Windows.Forms; -namespace v2rayN.Forms +namespace v2rayN.Base { class ListViewFlickerFree : ListView { diff --git a/v2rayN/v2rayN/StringEx.cs b/v2rayN/v2rayN/Base/StringEx.cs similarity index 98% rename from v2rayN/v2rayN/StringEx.cs rename to v2rayN/v2rayN/Base/StringEx.cs index 59916b32..e7f87a44 100644 --- a/v2rayN/v2rayN/StringEx.cs +++ b/v2rayN/v2rayN/Base/StringEx.cs @@ -2,7 +2,7 @@ using System.IO; using System.Linq; -namespace v2rayN +namespace v2rayN.Base { static class StringEx { diff --git a/v2rayN/v2rayN/HttpProxyHandler/WebClientEx.cs b/v2rayN/v2rayN/Base/WebClientEx.cs similarity index 97% rename from v2rayN/v2rayN/HttpProxyHandler/WebClientEx.cs rename to v2rayN/v2rayN/Base/WebClientEx.cs index 3b141f85..0a435692 100644 --- a/v2rayN/v2rayN/HttpProxyHandler/WebClientEx.cs +++ b/v2rayN/v2rayN/Base/WebClientEx.cs @@ -1,7 +1,7 @@ using System; using System.Net; -namespace v2rayN.HttpProxyHandler +namespace v2rayN.Base { class WebClientEx : WebClient { diff --git a/v2rayN/v2rayN/Forms/MainForm.Designer.cs b/v2rayN/v2rayN/Forms/MainForm.Designer.cs index 5f161aba..d87e1cbf 100644 --- a/v2rayN/v2rayN/Forms/MainForm.Designer.cs +++ b/v2rayN/v2rayN/Forms/MainForm.Designer.cs @@ -31,7 +31,7 @@ this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); - this.lvServers = new v2rayN.Forms.ListViewFlickerFree(); + this.lvServers = new v2rayN.Base.ListViewFlickerFree(); this.cmsLv = new System.Windows.Forms.ContextMenuStrip(this.components); this.menuAddVmessServer = new System.Windows.Forms.ToolStripMenuItem(); this.menuAddShadowsocksServer = new System.Windows.Forms.ToolStripMenuItem(); @@ -784,7 +784,7 @@ private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.TextBox txtMsgBox; - private v2rayN.Forms.ListViewFlickerFree lvServers; + private v2rayN.Base.ListViewFlickerFree lvServers; private System.Windows.Forms.NotifyIcon notifyMain; private System.Windows.Forms.ContextMenuStrip cmsMain; private System.Windows.Forms.ToolStripMenuItem menuExit; diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs index f1e073ab..1d8b3586 100644 --- a/v2rayN/v2rayN/Forms/MainForm.cs +++ b/v2rayN/v2rayN/Forms/MainForm.cs @@ -8,6 +8,7 @@ using System.Windows.Forms; using v2rayN.Handler; using v2rayN.HttpProxyHandler; using v2rayN.Mode; +using v2rayN.Base; namespace v2rayN.Forms { @@ -15,7 +16,7 @@ namespace v2rayN.Forms { private V2rayHandler v2rayHandler; private PACListHandle pacListHandle; - private V2rayUpdateHandle v2rayUpdateHandle; + private DownloadHandle downloadHandle; private List lvSelecteds = new List(); private StatisticsHandler statistics = null; @@ -1279,10 +1280,10 @@ namespace v2rayN.Forms private void tsbCheckUpdateCore_Click(object sender, EventArgs e) { - if (v2rayUpdateHandle == null) + if (downloadHandle == null) { - v2rayUpdateHandle = new V2rayUpdateHandle(); - v2rayUpdateHandle.AbsoluteCompleted += (sender2, args) => + downloadHandle = new DownloadHandle(); + downloadHandle.AbsoluteCompleted += (sender2, args) => { if (args.Success) { @@ -1298,7 +1299,7 @@ namespace v2rayN.Forms } else { - v2rayUpdateHandle.DownloadFileAsync(config, url, false); + downloadHandle.DownloadFileAsync(config, url, false); } })); } @@ -1307,7 +1308,7 @@ namespace v2rayN.Forms AppendText(false, args.Msg); } }; - v2rayUpdateHandle.UpdateCompleted += (sender2, args) => + downloadHandle.UpdateCompleted += (sender2, args) => { if (args.Success) { @@ -1318,7 +1319,7 @@ namespace v2rayN.Forms { CloseV2ray(); - string fileName = v2rayUpdateHandle.DownloadFileName; + string fileName = downloadHandle.DownloadFileName; fileName = Utils.GetPath(fileName); using (ZipArchive archive = ZipFile.OpenRead(fileName)) { @@ -1346,14 +1347,14 @@ namespace v2rayN.Forms AppendText(false, args.Msg); } }; - v2rayUpdateHandle.Error += (sender2, args) => + downloadHandle.Error += (sender2, args) => { AppendText(true, args.GetException().Message); }; } AppendText(false, UIRes.I18N("MsgStartUpdatingV2rayCore")); - v2rayUpdateHandle.AbsoluteV2rayCore(config); + downloadHandle.AbsoluteV2rayCore(config); } private void tsbCheckUpdatePACList_Click(object sender, EventArgs e) @@ -1473,8 +1474,8 @@ namespace v2rayN.Forms continue; } - V2rayUpdateHandle v2rayUpdateHandle3 = new V2rayUpdateHandle(); - v2rayUpdateHandle3.UpdateCompleted += (sender2, args) => + DownloadHandle downloadHandle3 = new DownloadHandle(); + downloadHandle3.UpdateCompleted += (sender2, args) => { if (args.Success) { @@ -1503,12 +1504,12 @@ namespace v2rayN.Forms AppendText(false, args.Msg); } }; - v2rayUpdateHandle3.Error += (sender2, args) => + downloadHandle3.Error += (sender2, args) => { AppendText(true, args.GetException().Message); }; - v2rayUpdateHandle3.WebDownloadString(url); + downloadHandle3.WebDownloadString(url); AppendText(false, $"{hashCode}{UIRes.I18N("MsgStartGettingSubscriptions")}"); } diff --git a/v2rayN/v2rayN/Forms/OptionSettingForm.cs b/v2rayN/v2rayN/Forms/OptionSettingForm.cs index 777c1daa..b6cd232e 100644 --- a/v2rayN/v2rayN/Forms/OptionSettingForm.cs +++ b/v2rayN/v2rayN/Forms/OptionSettingForm.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Windows.Forms; using v2rayN.Handler; +using v2rayN.Base; namespace v2rayN.Forms { @@ -381,8 +382,8 @@ namespace v2rayN.Forms for (int k = 0; k < lstUrl.Count; k++) { var txt = lstTxt[k]; - V2rayUpdateHandle v2rayUpdateHandle3 = new V2rayUpdateHandle(); - v2rayUpdateHandle3.UpdateCompleted += (sender2, args) => + DownloadHandle downloadHandle = new DownloadHandle(); + downloadHandle.UpdateCompleted += (sender2, args) => { if (args.Success) { @@ -398,12 +399,12 @@ namespace v2rayN.Forms AppendText(false, args.Msg); } }; - v2rayUpdateHandle3.Error += (sender2, args) => + downloadHandle.Error += (sender2, args) => { AppendText(true, args.GetException().Message); }; - v2rayUpdateHandle3.WebDownloadString(lstUrl[k]); + downloadHandle.WebDownloadString(lstUrl[k]); } } void AppendText(bool notify, string text) diff --git a/v2rayN/v2rayN/Forms/SubSettingControl.cs b/v2rayN/v2rayN/Forms/SubSettingControl.cs index a4ee2189..a3f09593 100644 --- a/v2rayN/v2rayN/Forms/SubSettingControl.cs +++ b/v2rayN/v2rayN/Forms/SubSettingControl.cs @@ -1,5 +1,6 @@ using System; using System.Windows.Forms; +using v2rayN.Base; using v2rayN.Mode; namespace v2rayN.Forms diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs index ba87e466..e4f48d0e 100644 --- a/v2rayN/v2rayN/Handler/ConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Net; using v2rayN.Mode; +using v2rayN.Base; namespace v2rayN.Handler { diff --git a/v2rayN/v2rayN/Handler/V2rayUpdateHandle.cs b/v2rayN/v2rayN/Handler/DownloadHandle.cs similarity index 97% rename from v2rayN/v2rayN/Handler/V2rayUpdateHandle.cs rename to v2rayN/v2rayN/Handler/DownloadHandle.cs index e26eff00..38b402a0 100644 --- a/v2rayN/v2rayN/Handler/V2rayUpdateHandle.cs +++ b/v2rayN/v2rayN/Handler/DownloadHandle.cs @@ -1,20 +1,15 @@ using System; -using System.Collections.Generic; using System.IO; using System.Net; -using System.Text; -using Newtonsoft.Json; +using v2rayN.Base; using v2rayN.Mode; -using v2rayN.Properties; -using v2rayN.HttpProxyHandler; -using System.Diagnostics; namespace v2rayN.Handler { /// - ///Update V2ray Core + ///Download /// - class V2rayUpdateHandle + class DownloadHandle { public event EventHandler AbsoluteCompleted; diff --git a/v2rayN/v2rayN/Handler/SpeedtestHandler.cs b/v2rayN/v2rayN/Handler/SpeedtestHandler.cs index cba9e741..6254107d 100644 --- a/v2rayN/v2rayN/Handler/SpeedtestHandler.cs +++ b/v2rayN/v2rayN/Handler/SpeedtestHandler.cs @@ -11,7 +11,7 @@ namespace v2rayN.Handler { class SpeedtestHandler { - private V2rayUpdateHandle v2rayUpdateHandle2; + private DownloadHandle downloadHandle2; private Config _config; private V2rayHandler _v2rayHandler; private List _selecteds; @@ -186,10 +186,10 @@ namespace v2rayN.Handler string url = Global.SpeedTestUrl; testCounter = 0; - if (v2rayUpdateHandle2 == null) + if (downloadHandle2 == null) { - v2rayUpdateHandle2 = new V2rayUpdateHandle(); - v2rayUpdateHandle2.UpdateCompleted += (sender2, args) => + downloadHandle2 = new DownloadHandle(); + downloadHandle2.UpdateCompleted += (sender2, args) => { if (args.Success) { @@ -204,7 +204,7 @@ namespace v2rayN.Handler _updateFunc(ItemIndex, args.Msg); } }; - v2rayUpdateHandle2.Error += (sender2, args) => + downloadHandle2.Error += (sender2, args) => { _updateFunc(ItemIndex, args.GetException().Message); if (ServerSpeedTestSub(testCounter, url) != 0) @@ -232,7 +232,7 @@ namespace v2rayN.Handler testCounter++; - v2rayUpdateHandle2.DownloadFileAsync(_config, url,true); + downloadHandle2.DownloadFileAsync(_config, url,true); return 0; } diff --git a/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs b/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs index f9e08998..6aadec52 100644 --- a/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs @@ -1,10 +1,10 @@ using System; using System.Collections.Generic; using System.IO; -using v2rayN.Mode; -using System.Net; -using System.Text; using System.Linq; +using System.Net; +using v2rayN.Base; +using v2rayN.Mode; namespace v2rayN.Handler { diff --git a/v2rayN/v2rayN/HttpProxyHandler/HttpProxyHandle.cs b/v2rayN/v2rayN/HttpProxyHandler/HttpProxyHandle.cs index d2282c31..8195e1e1 100644 --- a/v2rayN/v2rayN/HttpProxyHandler/HttpProxyHandle.cs +++ b/v2rayN/v2rayN/HttpProxyHandler/HttpProxyHandle.cs @@ -10,21 +10,6 @@ namespace v2rayN.HttpProxyHandler /// class HttpProxyHandle { - private static string GetTimestamp(DateTime value) - { - return value.ToString("MMddHHmmssfff"); - } - - public static void ReSetPACProxy(Config config) - { - if (config.listenerType == 2) - { - //SysProxyHandle.SetIEProxy(false, false, null, null); - //PACServerHandle.Stop(); - } - Update(config, false); - } - public static bool Update(Config config, bool forceDisable) { int type = config.listenerType; @@ -46,7 +31,6 @@ namespace v2rayN.HttpProxyHandler if (type == 1) { PACServerHandle.Stop(); - PACFileWatcherHandle.StopWatch(); SysProxyHandle.SetIEProxy(true, true, $"{Global.Loopback}:{port}", null); } else if (type == 2) @@ -55,12 +39,10 @@ namespace v2rayN.HttpProxyHandler SysProxyHandle.SetIEProxy(true, false, null, pacUrl); PACServerHandle.Stop(); PACServerHandle.Init(config); - PACFileWatcherHandle.StartWatch(config); } else if (type == 3) { PACServerHandle.Stop(); - PACFileWatcherHandle.StopWatch(); SysProxyHandle.SetIEProxy(false, false, null, null); } else if (type == 4) @@ -69,14 +51,12 @@ namespace v2rayN.HttpProxyHandler SysProxyHandle.SetIEProxy(false, false, null, null); PACServerHandle.Stop(); PACServerHandle.Init(config); - PACFileWatcherHandle.StartWatch(config); } } else { SysProxyHandle.SetIEProxy(false, false, null, null); PACServerHandle.Stop(); - PACFileWatcherHandle.StopWatch(); } } catch (Exception ex) @@ -168,9 +148,7 @@ namespace v2rayN.HttpProxyHandler public static string GetPacUrl() { - string pacUrl = $"http://{Global.Loopback}:{Global.pacPort}/pac/?t={GetTimestamp(DateTime.Now)}"; - - + string pacUrl = $"http://{Global.Loopback}:{Global.pacPort}/pac/?t={ DateTime.Now.ToString("HHmmss")}"; return pacUrl; } } diff --git a/v2rayN/v2rayN/HttpProxyHandler/PACFileWatcherHandle.cs b/v2rayN/v2rayN/HttpProxyHandler/PACFileWatcherHandle.cs deleted file mode 100644 index 08043d73..00000000 --- a/v2rayN/v2rayN/HttpProxyHandler/PACFileWatcherHandle.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System.IO; -using System.Windows.Forms; -using v2rayN.Mode; - -namespace v2rayN.HttpProxyHandler -{ - /// - /// 提供PAC功能支持 - /// - class PACFileWatcherHandle - { - private static FileSystemWatcher fileSystemWatcher; - - private static long fileSize; - - public static void StartWatch(Config config) - { - if (fileSystemWatcher == null) - { - fileSystemWatcher = new FileSystemWatcher(Utils.StartupPath()); - fileSystemWatcher.Filter = "pac.txt"; - fileSystemWatcher.NotifyFilter = NotifyFilters.Size; - fileSystemWatcher.Changed += (sender, args) => - { - var fileInfo = new FileInfo(args.FullPath); - if (fileSize != fileInfo.Length) - { - fileSize = fileInfo.Length; - HttpProxyHandle.ReSetPACProxy(config); - } - - }; - } - fileSystemWatcher.EnableRaisingEvents = true; - } - - public static void StopWatch() - { - if (fileSystemWatcher != null) - { - fileSystemWatcher.EnableRaisingEvents = false; - } - } - } -} diff --git a/v2rayN/v2rayN/HttpProxyHandler/PACListHandle.cs b/v2rayN/v2rayN/HttpProxyHandler/PACListHandle.cs index 8aaa0822..0fa76f7c 100644 --- a/v2rayN/v2rayN/HttpProxyHandler/PACListHandle.cs +++ b/v2rayN/v2rayN/HttpProxyHandler/PACListHandle.cs @@ -4,6 +4,7 @@ using System.IO; using System.Net; using System.Text; using Newtonsoft.Json; +using v2rayN.Base; using v2rayN.Mode; using v2rayN.Properties; diff --git a/v2rayN/v2rayN/HttpProxyHandler/PACServerHandle.cs b/v2rayN/v2rayN/HttpProxyHandler/PACServerHandle.cs index 21e3fd6c..cc2a033b 100644 --- a/v2rayN/v2rayN/HttpProxyHandler/PACServerHandle.cs +++ b/v2rayN/v2rayN/HttpProxyHandler/PACServerHandle.cs @@ -5,6 +5,7 @@ using System.Text; using v2rayN.Mode; using v2rayN.Properties; using v2rayN.Tool; +using v2rayN.Base; namespace v2rayN.HttpProxyHandler { diff --git a/v2rayN/v2rayN/HttpProxyHandler/SysProxyHandle.cs b/v2rayN/v2rayN/HttpProxyHandler/SysProxyHandle.cs index e8056ec2..df06f21a 100644 --- a/v2rayN/v2rayN/HttpProxyHandler/SysProxyHandle.cs +++ b/v2rayN/v2rayN/HttpProxyHandler/SysProxyHandle.cs @@ -1,8 +1,9 @@ -using System; +using Newtonsoft.Json; +using System; using System.Diagnostics; using System.IO; using System.Text; -using Newtonsoft.Json; +using v2rayN.Base; using v2rayN.Mode; using v2rayN.Properties; using v2rayN.Tool; diff --git a/v2rayN/v2rayN/Mode/Config.cs b/v2rayN/v2rayN/Mode/Config.cs index 47b21e78..1586f621 100644 --- a/v2rayN/v2rayN/Mode/Config.cs +++ b/v2rayN/v2rayN/Mode/Config.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Text.RegularExpressions; +using v2rayN.Base; namespace v2rayN.Mode { diff --git a/v2rayN/v2rayN/Tool/Utils.cs b/v2rayN/v2rayN/Tool/Utils.cs index f8439463..2dd6acbf 100644 --- a/v2rayN/v2rayN/Tool/Utils.cs +++ b/v2rayN/v2rayN/Tool/Utils.cs @@ -18,6 +18,7 @@ using ZXing; using ZXing.Common; using ZXing.QrCode; using System.Security.Principal; +using v2rayN.Base; namespace v2rayN { diff --git a/v2rayN/v2rayN/v2rayN.csproj b/v2rayN/v2rayN/v2rayN.csproj index 04dfe9e9..53b582b3 100644 --- a/v2rayN/v2rayN/v2rayN.csproj +++ b/v2rayN/v2rayN/v2rayN.csproj @@ -114,6 +114,7 @@ LIB\System.Memory.dll False + False @@ -140,7 +141,7 @@ AddServer4Form.cs - + Component @@ -181,17 +182,16 @@ - - - - + + + - + Component @@ -208,7 +208,7 @@ True ResUI.resx - + Code