From 26af708a5a5c901225cd991a80d820fa9c14dd9c Mon Sep 17 00:00:00 2001 From: nobody Date: Tue, 2 Jun 2020 16:01:07 +0800 Subject: [PATCH 01/14] Fix a bug in core updating. --- V2RayGCon/Libs/Nets/Downloader.cs | 35 +++++++++++++++++++++-- V2RayGCon/Properties/AssemblyInfo.cs | 3 +- V2RayGCon/Resources/Resx/I18N.Designer.cs | 9 ++++++ V2RayGCon/Resources/Resx/I18N.resx | 3 ++ V2RayGCon/Resources/Resx/I18N.zh-CN.resx | 3 ++ 5 files changed, 50 insertions(+), 3 deletions(-) diff --git a/V2RayGCon/Libs/Nets/Downloader.cs b/V2RayGCon/Libs/Nets/Downloader.cs index c2e73f2b..b428f3ee 100644 --- a/V2RayGCon/Libs/Nets/Downloader.cs +++ b/V2RayGCon/Libs/Nets/Downloader.cs @@ -66,6 +66,7 @@ public bool UnzipPackage() var filename = GetLocalFilename(); if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(filename)) { + setting.SendLog(I18N.LocateTargetFolderFail); return false; } @@ -82,11 +83,12 @@ public bool UnzipPackage() VgcApis.Misc.Utils.Sleep(2000); try { + RemoveOldExe(path); Misc.Utils.ZipFileDecompress(filename, path); } - catch + catch (Exception ex) { - setting.SendLog(I18N.DecompressFileFail); + setting.SendLog(I18N.DecompressFileFail + Environment.NewLine + ex.ToString()); return false; } return true; @@ -105,6 +107,35 @@ public void Cancel() #endregion #region private method + void RemoveOldExe(string path) + { + string[] exes = new string[] { "v2ray.exe", "v2ctl.exe" }; + string prefix = "bak"; + + foreach (var exe in exes) + { + var newFn = Path.Combine(path, $"{prefix}.{exe}"); + if (File.Exists(newFn)) + { + try + { + File.Delete(newFn); + } + catch + { + var now = DateTime.Now.ToString("yyyy-MM-dd.HHmmss.ffff"); + newFn = Path.Combine(path, $"{prefix}.{now}.{exe}"); + } + } + + var orgFn = Path.Combine(path, exe); + if (File.Exists(orgFn)) + { + File.Move(orgFn, newFn); + } + } + } + void SendProgress(int percentage) { try diff --git a/V2RayGCon/Properties/AssemblyInfo.cs b/V2RayGCon/Properties/AssemblyInfo.cs index ad3947b5..637c08a9 100644 --- a/V2RayGCon/Properties/AssemblyInfo.cs +++ b/V2RayGCon/Properties/AssemblyInfo.cs @@ -33,10 +33,11 @@ // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0.0")] +[assembly: AssemblyVersion("1.4.0.1")] [assembly: AssemblyFileVersion("1.0.0.0")] /* + * v1.4.0.1 Fix a bug in v2ray-core updating. * ---------------------------------------- * v1.3.9.8 Fix a bug which would block core updating. * v1.3.9.7 Add luasocket and luasec. diff --git a/V2RayGCon/Resources/Resx/I18N.Designer.cs b/V2RayGCon/Resources/Resx/I18N.Designer.cs index 9f609a63..cc83475f 100644 --- a/V2RayGCon/Resources/Resx/I18N.Designer.cs +++ b/V2RayGCon/Resources/Resx/I18N.Designer.cs @@ -1099,6 +1099,15 @@ internal static string LoadJsonFail { } } + /// + /// 查找类似 Locate target folder fail. 的本地化字符串。 + /// + internal static string LocateTargetFolderFail { + get { + return ResourceManager.GetString("LocateTargetFolderFail", resourceCulture); + } + } + /// /// 查找类似 Log 的本地化字符串。 /// diff --git a/V2RayGCon/Resources/Resx/I18N.resx b/V2RayGCon/Resources/Resx/I18N.resx index 1f492c88..c9c25073 100644 --- a/V2RayGCon/Resources/Resx/I18N.resx +++ b/V2RayGCon/Resources/Resx/I18N.resx @@ -750,4 +750,7 @@ No, abort. Clear speed test results? + + Locate target folder fail. + \ No newline at end of file diff --git a/V2RayGCon/Resources/Resx/I18N.zh-CN.resx b/V2RayGCon/Resources/Resx/I18N.zh-CN.resx index e5e8f6fa..a8fe69e1 100644 --- a/V2RayGCon/Resources/Resx/I18N.zh-CN.resx +++ b/V2RayGCon/Resources/Resx/I18N.zh-CN.resx @@ -741,4 +741,7 @@ https://github.com/v2ray/v2ray-core 清除速度测试数据? + + 定位目标文件不会失败! + \ No newline at end of file From 1db26a873cd564426fce563661eac99737b5a645 Mon Sep 17 00:00:00 2001 From: nobody Date: Wed, 3 Jun 2020 11:14:32 +0800 Subject: [PATCH 02/14] Add custom inbounds setting. --- .../CoreServerComponent/Configer.cs | 44 +- V2RayGCon/Controllers/CoreServerCtrl.cs | 2 +- .../FormOptionComponent/TabDefaults.cs | 15 +- V2RayGCon/Models/Datas/Enums.cs | 1 + V2RayGCon/Models/Datas/Table.cs | 3 +- V2RayGCon/Models/Datas/UserSettings.cs | 4 + V2RayGCon/Properties/AssemblyInfo.cs | 3 +- V2RayGCon/Resources/Resx/I18N.Designer.cs | 27 + V2RayGCon/Resources/Resx/I18N.resx | 9 + V2RayGCon/Resources/Resx/I18N.zh-CN.resx | 9 + V2RayGCon/Services/ConfigMgr.cs | 27 +- V2RayGCon/Services/Launcher.cs | 5 +- V2RayGCon/Services/Settings.cs | 13 + V2RayGCon/Views/UserControls/ServerUI.cs | 4 + .../FormBatchModifyServerSetting.Designer.cs | 22 +- .../WinForms/FormBatchModifyServerSetting.cs | 18 +- .../FormBatchModifyServerSetting.resx | 160 +++- .../FormBatchModifyServerSetting.zh-CN.resx | 12 + .../FormModifyServerSettings.Designer.cs | 17 +- .../WinForms/FormModifyServerSettings.resx | 831 +++++++++--------- .../FormModifyServerSettings.zh-CN.resx | 37 +- .../Views/WinForms/FormOption.Designer.cs | 49 +- V2RayGCon/Views/WinForms/FormOption.cs | 4 +- V2RayGCon/Views/WinForms/FormOption.resx | 69 +- .../Views/WinForms/FormOption.zh-CN.resx | 13 +- VgcApis/Models/Datas/Enums.cs | 1 + 26 files changed, 878 insertions(+), 521 deletions(-) diff --git a/V2RayGCon/Controllers/CoreServerComponent/Configer.cs b/V2RayGCon/Controllers/CoreServerComponent/Configer.cs index 726ba335..31799d3f 100644 --- a/V2RayGCon/Controllers/CoreServerComponent/Configer.cs +++ b/V2RayGCon/Controllers/CoreServerComponent/Configer.cs @@ -237,13 +237,41 @@ bool IsProtocolMatchProxyRequirment(bool isGlobalProxy, string protocol) Tuple GetterParsedInboundInfo(string rawConfig) { var protocol = Misc.Utils.InboundTypeNumberToName(coreInfo.customInbType); - var ip = coreInfo.inbIp; - var port = coreInfo.inbPort; + switch (protocol) + { + case "http": + case "socks": + var info = new Tuple( + protocol, coreInfo.inbIp, coreInfo.inbPort); + return info; + case "config": + return GetInboundInfoFromConfig(rawConfig); + case "custom": + return GetInboundInfoFromCustomInboundsSetting(); + default: + return null; + } + } - if (protocol != "config") + Tuple GetInboundInfoFromCustomInboundsSetting() + { + try { + var jobj = JArray.Parse(setting.CustomDefInbounds)[0]; + var protocol = Misc.Utils.GetValue(jobj, "protocol"); + string ip = Misc.Utils.GetValue(jobj, "listen"); + int port = Misc.Utils.GetValue(jobj, "port"); return new Tuple(protocol, ip, port); } + catch + { + setting.SendLog(I18N.ParseCustomInboundsSettingFail); + } + return null; + } + + Tuple GetInboundInfoFromConfig(string rawConfig) + { var parsedConfig = configMgr.DecodeConfig( rawConfig, @@ -257,11 +285,11 @@ Tuple GetterParsedInboundInfo(string rawConfig) } string prefix = "inbound"; + string protocol = ""; foreach (var p in new string[] { "inbound", "inbounds.0" }) { prefix = p; - protocol = Misc.Utils.GetValue( - parsedConfig, prefix, "protocol"); + protocol = Misc.Utils.GetValue(parsedConfig, prefix, "protocol"); if (!string.IsNullOrEmpty(protocol)) { @@ -269,10 +297,12 @@ Tuple GetterParsedInboundInfo(string rawConfig) } } - ip = Misc.Utils.GetValue(parsedConfig, prefix, "listen"); - port = Misc.Utils.GetValue(parsedConfig, prefix, "port"); + string ip = Misc.Utils.GetValue(parsedConfig, prefix, "listen"); + int port = Misc.Utils.GetValue(parsedConfig, prefix, "port"); return new Tuple(protocol, ip, port); } + + #endregion } } diff --git a/V2RayGCon/Controllers/CoreServerCtrl.cs b/V2RayGCon/Controllers/CoreServerCtrl.cs index 58ffd8a9..7c067f09 100644 --- a/V2RayGCon/Controllers/CoreServerCtrl.cs +++ b/V2RayGCon/Controllers/CoreServerCtrl.cs @@ -99,7 +99,7 @@ bool SetCustomInboundInfo(CoreServSettings cs) var restartCore = false; if (cs.inboundMode != ci.customInbType) { - ci.customInbType = Math.Abs(cs.inboundMode) % 3; + ci.customInbType = Misc.Utils.Clamp(cs.inboundMode, 0, Models.Datas.Table.customInbTypeNames.Length); restartCore = true; } diff --git a/V2RayGCon/Controllers/FormOptionComponent/TabDefaults.cs b/V2RayGCon/Controllers/FormOptionComponent/TabDefaults.cs index 1520b012..a2566caf 100644 --- a/V2RayGCon/Controllers/FormOptionComponent/TabDefaults.cs +++ b/V2RayGCon/Controllers/FormOptionComponent/TabDefaults.cs @@ -20,6 +20,10 @@ class TabDefaults : OptionComponentController tboxSetSpeedtestCycles = null, tboxSetSpeedtestTimeout = null; + RichTextBox exRTBoxDefCustomInbounds = null; + + + public TabDefaults( ComboBox cboxDefImportMode, TextBox tboxDefImportAddr, @@ -32,10 +36,14 @@ public TabDefaults( ComboBox cboxDefSpeedtestUrl, TextBox tboxSetSpeedtestCycles, ComboBox cboxDefSpeedtestExpectedSize, - TextBox tboxSetSpeedtestTimeout) + TextBox tboxSetSpeedtestTimeout, + + RichTextBox exRTBoxDefCustomInbounds) { this.setting = Services.Settings.Instance; + this.exRTBoxDefCustomInbounds = exRTBoxDefCustomInbounds; + // Do not put these lines of code into InitElement. this.cboxDefImportMode = cboxDefImportMode; this.tboxDefImportAddr = tboxDefImportAddr; @@ -53,6 +61,8 @@ public TabDefaults( private void InitElement() { + exRTBoxDefCustomInbounds.Text = setting.CustomDefInbounds; + // mode chkImportBypassCnSite.Checked = setting.CustomDefImportBypassCnSite; chkImportInjectGlobalImport.Checked = setting.CustomDefImportGlobalImport; @@ -81,6 +91,8 @@ public override bool SaveOptions() return false; } + setting.CustomDefInbounds = exRTBoxDefCustomInbounds.Text; + // mode if (VgcApis.Misc.Utils.TryParseAddress(tboxDefImportAddr.Text, out string ip, out int port)) { @@ -108,6 +120,7 @@ public override bool IsOptionsChanged() { var success = VgcApis.Misc.Utils.TryParseAddress(tboxDefImportAddr.Text, out string ip, out int port); if (!success + || setting.CustomDefInbounds != exRTBoxDefCustomInbounds.Text || setting.CustomDefImportGlobalImport != chkImportInjectGlobalImport.Checked || setting.CustomDefImportBypassCnSite != chkImportBypassCnSite.Checked || setting.CustomDefImportSsShareLink != chkImportSsShareLink.Checked diff --git a/V2RayGCon/Models/Datas/Enums.cs b/V2RayGCon/Models/Datas/Enums.cs index d8e6345e..a2180615 100644 --- a/V2RayGCon/Models/Datas/Enums.cs +++ b/V2RayGCon/Models/Datas/Enums.cs @@ -17,6 +17,7 @@ public enum ProxyTypes Config = 0, HTTP = 1, SOCKS = 2, + Custom = 3, } public enum FormLocations diff --git a/V2RayGCon/Models/Datas/Table.cs b/V2RayGCon/Models/Datas/Table.cs index c1f0fbe5..e9b0ee4c 100644 --- a/V2RayGCon/Models/Datas/Table.cs +++ b/V2RayGCon/Models/Datas/Table.cs @@ -23,7 +23,8 @@ class Table public static readonly string[] customInbTypeNames = new string[] { "config", "http", - "socks" + "socks", + "custom", }; public static readonly Dictionary ssMethods = new Dictionary diff --git a/V2RayGCon/Models/Datas/UserSettings.cs b/V2RayGCon/Models/Datas/UserSettings.cs index 4b92d52b..275cfa41 100644 --- a/V2RayGCon/Models/Datas/UserSettings.cs +++ b/V2RayGCon/Models/Datas/UserSettings.cs @@ -5,6 +5,8 @@ namespace V2RayGCon.Models.Datas class UserSettings { #region public properties + + public string CustomInbounds { get; set; } public string DebugLogFilePath { get; set; } public bool isEnableDebugFile { get; set; } @@ -56,6 +58,8 @@ public UserSettings() { Normalized(); + CustomInbounds = @"[]"; + DebugLogFilePath = @""; isEnableDebugFile = false; diff --git a/V2RayGCon/Properties/AssemblyInfo.cs b/V2RayGCon/Properties/AssemblyInfo.cs index 637c08a9..734bc04c 100644 --- a/V2RayGCon/Properties/AssemblyInfo.cs +++ b/V2RayGCon/Properties/AssemblyInfo.cs @@ -33,10 +33,11 @@ // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0.1")] +[assembly: AssemblyVersion("1.4.0.2")] [assembly: AssemblyFileVersion("1.0.0.0")] /* + * v1.4.0.2 Custom inbounds support. * v1.4.0.1 Fix a bug in v2ray-core updating. * ---------------------------------------- * v1.3.9.8 Fix a bug which would block core updating. diff --git a/V2RayGCon/Resources/Resx/I18N.Designer.cs b/V2RayGCon/Resources/Resx/I18N.Designer.cs index cc83475f..a678d394 100644 --- a/V2RayGCon/Resources/Resx/I18N.Designer.cs +++ b/V2RayGCon/Resources/Resx/I18N.Designer.cs @@ -576,6 +576,15 @@ internal static string CurSysProxy { } } + /// + /// 查找类似 Custom 的本地化字符串。 + /// + internal static string Custom { + get { + return ResourceManager.GetString("Custom", resourceCulture); + } + } + /// /// 查找类似 Data too big. Please trim down the config file. 的本地化字符串。 /// @@ -1036,6 +1045,15 @@ internal static string InbModeConfigToolTip { } } + /// + /// 查找类似 Use custom inbounds setting in option window. 的本地化字符串。 + /// + internal static string InbModeCustomToolTip { + get { + return ResourceManager.GetString("InbModeCustomToolTip", resourceCulture); + } + } + /// /// 查找类似 Inject packageing imports fail, ignore imports. 的本地化字符串。 /// @@ -1345,6 +1363,15 @@ internal static string PacProxy { } } + /// + /// 查找类似 Parse custom inbound setting fail! 的本地化字符串。 + /// + internal static string ParseCustomInboundsSettingFail { + get { + return ResourceManager.GetString("ParseCustomInboundsSettingFail", resourceCulture); + } + } + /// /// 查找类似 Can not parse json! Please check current config. 的本地化字符串。 /// diff --git a/V2RayGCon/Resources/Resx/I18N.resx b/V2RayGCon/Resources/Resx/I18N.resx index c9c25073..d721aa92 100644 --- a/V2RayGCon/Resources/Resx/I18N.resx +++ b/V2RayGCon/Resources/Resx/I18N.resx @@ -753,4 +753,13 @@ No, abort. Locate target folder fail. + + Parse custom inbound setting fail! + + + Use custom inbounds setting in option window. + + + Custom + \ No newline at end of file diff --git a/V2RayGCon/Resources/Resx/I18N.zh-CN.resx b/V2RayGCon/Resources/Resx/I18N.zh-CN.resx index a8fe69e1..1b0e5aa2 100644 --- a/V2RayGCon/Resources/Resx/I18N.zh-CN.resx +++ b/V2RayGCon/Resources/Resx/I18N.zh-CN.resx @@ -744,4 +744,13 @@ https://github.com/v2ray/v2ray-core 定位目标文件不会失败! + + 解释自定义inbounds失败! + + + 使用选项窗口中的自定义inbounds设定 + + + 自定义 + \ No newline at end of file diff --git a/V2RayGCon/Services/ConfigMgr.cs b/V2RayGCon/Services/ConfigMgr.cs index db16a6db..e8d80650 100644 --- a/V2RayGCon/Services/ConfigMgr.cs +++ b/V2RayGCon/Services/ConfigMgr.cs @@ -105,15 +105,30 @@ public bool ModifyInboundWithCustomSetting( string ip, int port) { - switch (inbType) + if (inbType == (int)Models.Datas.Enums.ProxyTypes.Config) { - case (int)Models.Datas.Enums.ProxyTypes.HTTP: - case (int)Models.Datas.Enums.ProxyTypes.SOCKS: - break; + return true; + } - case (int)Models.Datas.Enums.ProxyTypes.Config: - default: + if (inbType == (int)Models.Datas.Enums.ProxyTypes.Custom) + { + try + { + var inbs = JArray.Parse(setting.CustomDefInbounds); + config["inbounds"] = inbs; return true; + } + catch + { + setting.SendLog(I18N.ParseCustomInboundsSettingFail); + } + return false; + } + + if (inbType != (int)Models.Datas.Enums.ProxyTypes.HTTP + && inbType != (int)Models.Datas.Enums.ProxyTypes.SOCKS) + { + return false; } var protocol = Misc.Utils.InboundTypeNumberToName(inbType); diff --git a/V2RayGCon/Services/Launcher.cs b/V2RayGCon/Services/Launcher.cs index 50375148..135ee04c 100644 --- a/V2RayGCon/Services/Launcher.cs +++ b/V2RayGCon/Services/Launcher.cs @@ -77,7 +77,10 @@ void ShowPlugin(string name) #if DEBUG void This_Function_Is_Used_For_Debugging() { - ShowPlugin(@"Luna"); + // ShowPlugin(@"Luna"); + + Views.WinForms.FormLog.ShowForm(); + Views.WinForms.FormMain.ShowForm(); //notifier.InjectDebugMenuItem(new ToolStripMenuItem( // "Debug", diff --git a/V2RayGCon/Services/Settings.cs b/V2RayGCon/Services/Settings.cs index e6c17c54..44ef9cd8 100644 --- a/V2RayGCon/Services/Settings.cs +++ b/V2RayGCon/Services/Settings.cs @@ -51,6 +51,19 @@ public class Settings : } #region Properties + public string CustomDefInbounds + { + get => userSettings.CustomInbounds; + set + { + if (userSettings.CustomInbounds == value) + { + return; + } + userSettings.CustomInbounds = value; + SaveSettingsLater(); + } + } public string DebugLogFilePath { diff --git a/V2RayGCon/Views/UserControls/ServerUI.cs b/V2RayGCon/Views/UserControls/ServerUI.cs index 643bf41d..d8d5f54d 100644 --- a/V2RayGCon/Views/UserControls/ServerUI.cs +++ b/V2RayGCon/Views/UserControls/ServerUI.cs @@ -320,6 +320,10 @@ void UpdateInboundModeLabel(VgcApis.Interfaces.CoreCtrlComponents.ICoreStates co text = (lower ? @"s" : @"S") + coreState.GetInboundPort(); tooltip = @"inbound -> socks://" + coreState.GetInboundAddr(); break; + case (int)VgcApis.Models.Datas.Enums.ProxyTypes.Custom: + text = I18N.Custom; + tooltip = I18N.InbModeCustomToolTip; + break; } UpdateControlTextAndTooltip(rlbInboundMode, text, tooltip); } diff --git a/V2RayGCon/Views/WinForms/FormBatchModifyServerSetting.Designer.cs b/V2RayGCon/Views/WinForms/FormBatchModifyServerSetting.Designer.cs index 77aa1e1d..4e9a6e80 100644 --- a/V2RayGCon/Views/WinForms/FormBatchModifyServerSetting.Designer.cs +++ b/V2RayGCon/Views/WinForms/FormBatchModifyServerSetting.Designer.cs @@ -48,7 +48,9 @@ private void InitializeComponent() this.chkIsInjectSkipCNSite = new System.Windows.Forms.CheckBox(); this.cboxImport = new System.Windows.Forms.ComboBox(); this.cboxAutorun = new System.Windows.Forms.ComboBox(); + this.tboxRemark = new System.Windows.Forms.TextBox(); this.chkImport = new System.Windows.Forms.CheckBox(); + this.chkRemark = new System.Windows.Forms.CheckBox(); this.chkAutorun = new System.Windows.Forms.CheckBox(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.groupBox1.SuspendLayout(); @@ -133,7 +135,8 @@ private void InitializeComponent() this.cboxInMode.Items.AddRange(new object[] { resources.GetString("cboxInMode.Items"), resources.GetString("cboxInMode.Items1"), - resources.GetString("cboxInMode.Items2")}); + resources.GetString("cboxInMode.Items2"), + resources.GetString("cboxInMode.Items3")}); this.cboxInMode.Name = "cboxInMode"; this.toolTip1.SetToolTip(this.cboxInMode, resources.GetString("cboxInMode.ToolTip")); // @@ -167,7 +170,9 @@ private void InitializeComponent() this.groupBox2.Controls.Add(this.chkIsInjectSkipCNSite); this.groupBox2.Controls.Add(this.cboxImport); this.groupBox2.Controls.Add(this.cboxAutorun); + this.groupBox2.Controls.Add(this.tboxRemark); this.groupBox2.Controls.Add(this.chkImport); + this.groupBox2.Controls.Add(this.chkRemark); this.groupBox2.Controls.Add(this.chkAutorun); this.groupBox2.Controls.Add(this.chkMark); this.groupBox2.Controls.Add(this.cboxMark); @@ -215,6 +220,12 @@ private void InitializeComponent() this.cboxAutorun.Name = "cboxAutorun"; this.toolTip1.SetToolTip(this.cboxAutorun, resources.GetString("cboxAutorun.ToolTip")); // + // tboxRemark + // + resources.ApplyResources(this.tboxRemark, "tboxRemark"); + this.tboxRemark.Name = "tboxRemark"; + this.toolTip1.SetToolTip(this.tboxRemark, resources.GetString("tboxRemark.ToolTip")); + // // chkImport // resources.ApplyResources(this.chkImport, "chkImport"); @@ -222,6 +233,13 @@ private void InitializeComponent() this.toolTip1.SetToolTip(this.chkImport, resources.GetString("chkImport.ToolTip")); this.chkImport.UseVisualStyleBackColor = true; // + // chkRemark + // + resources.ApplyResources(this.chkRemark, "chkRemark"); + this.chkRemark.Name = "chkRemark"; + this.toolTip1.SetToolTip(this.chkRemark, resources.GetString("chkRemark.ToolTip")); + this.chkRemark.UseVisualStyleBackColor = true; + // // chkAutorun // resources.ApplyResources(this.chkAutorun, "chkAutorun"); @@ -274,5 +292,7 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox chkIsInjectSkipCNSite; private System.Windows.Forms.CheckBox chkShareOverLAN; private System.Windows.Forms.CheckBox chkIncrement; + private System.Windows.Forms.TextBox tboxRemark; + private System.Windows.Forms.CheckBox chkRemark; } } diff --git a/V2RayGCon/Views/WinForms/FormBatchModifyServerSetting.cs b/V2RayGCon/Views/WinForms/FormBatchModifyServerSetting.cs index 18feb0b7..69b9cb5d 100644 --- a/V2RayGCon/Views/WinForms/FormBatchModifyServerSetting.cs +++ b/V2RayGCon/Views/WinForms/FormBatchModifyServerSetting.cs @@ -51,10 +51,12 @@ private void FormBatchModifyServerInfo_Shown(object sender, EventArgs e) var first = firstCtrl.GetCoreStates().GetAllRawCoreInfo(); + this.cboxInMode.SelectedIndex = first.customInbType; this.tboxInIP.Text = first.inbIp; this.tboxInPort.Text = first.inbPort.ToString(); this.cboxMark.Text = first.customMark; + this.tboxRemark.Text = first.customRemark; this.cboxAutorun.SelectedIndex = first.isAutoRun ? 0 : 1; this.cboxImport.SelectedIndex = first.isInjectImport ? 0 : 1; this.cboxIsInjectSkipCNSite.SelectedIndex = first.isInjectSkipCNSite ? 0 : 1; @@ -95,12 +97,13 @@ private void btnModify_Click(object sender, EventArgs e) var newImport = chkImport.Checked ? cboxImport.SelectedIndex : -1; var newSkipCN = chkIsInjectSkipCNSite.Checked ? cboxIsInjectSkipCNSite.SelectedIndex : -1; var isPortAutoIncrease = chkIncrement.Checked; + var newRemark = chkRemark.Checked ? tboxRemark.Text : null; ModifyServersSetting( list, newMode, newIP, newPort, isPortAutoIncrease, - newMark, newAutorun, newImport, newSkipCN); + newMark, newRemark, newAutorun, newImport, newSkipCN); } #endregion @@ -109,7 +112,7 @@ private void btnModify_Click(object sender, EventArgs e) void ModifyServersSetting( List list, int newMode, string newIP, int newPort, bool isPortAutoIncrease, - string newMark, int newAutorun, int newImport, int newSkipCN) + string newMark, string newRemark, int newAutorun, int newImport, int newSkipCN) { Action worker = (index, next) => { @@ -121,7 +124,7 @@ void ModifyServersSetting( ModifyServerSetting( ref server, newMode, newIP, portNumber, - newMark, newAutorun, newImport, newSkipCN); + newMark, newRemark, newAutorun, newImport, newSkipCN); server.InvokeEventOnPropertyChange(); next(); return; @@ -132,7 +135,7 @@ void ModifyServersSetting( ModifyServerSetting( ref server, newMode, newIP, portNumber, - newMark, newAutorun, newImport, newSkipCN); + newMark, newRemark, newAutorun, newImport, newSkipCN); server.GetCoreCtrl().RestartCoreThen(); next(); }); @@ -152,7 +155,7 @@ void ModifyServersSetting( void ModifyServerSetting( ref VgcApis.Interfaces.ICoreServCtrl serverCtrl, int newMode, string newIP, int newPort, - string newMark, int newAutorun, int newImport, int newSkipCN) + string newMark, string newRemark, int newAutorun, int newImport, int newSkipCN) { var server = serverCtrl.GetCoreStates().GetAllRawCoreInfo(); @@ -189,6 +192,11 @@ void ModifyServerSetting( { server.customMark = newMark; } + + if (!string.IsNullOrEmpty(newRemark)) + { + server.customRemark = newRemark; + } } #endregion diff --git a/V2RayGCon/Views/WinForms/FormBatchModifyServerSetting.resx b/V2RayGCon/Views/WinForms/FormBatchModifyServerSetting.resx index b0eaaaf0..d9a8f728 100644 --- a/V2RayGCon/Views/WinForms/FormBatchModifyServerSetting.resx +++ b/V2RayGCon/Views/WinForms/FormBatchModifyServerSetting.resx @@ -124,6 +124,10 @@ System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 2, 2, 2, 2 + Auto increment port number. @@ -153,9 +157,8 @@ 3 - 87, 61 + 87, 91 - 2, 2, 2, 2 @@ -193,10 +196,10 @@ 12, 39 - 306, 108 + 306, 144 - 4 + 5 $this @@ -204,11 +207,14 @@ 0 + + 2, 2, 2, 2 + 1 - 340, 249 + 340, 292 System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 @@ -219,8 +225,8 @@ System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 cboxMark @@ -252,6 +258,9 @@ 2, 2, 2, 2 + + + 2, 2, 2, 2 @@ -261,8 +270,8 @@ - - 4 + + True groupBox1 @@ -291,11 +300,14 @@ 127, 20 + + + True - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 6 True @@ -303,6 +315,9 @@ System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + tboxRemark + 87, 18 @@ -315,6 +330,9 @@ 7 + + + chkShareOverLAN @@ -331,16 +349,19 @@ cboxImport - 12, 62 + 12, 93 System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 12, 83 + 12, 117 - - + + groupBox2 + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 True @@ -354,8 +375,11 @@ 2, 2, 2, 2 + + groupBox2 + - 5 + 7 System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 @@ -366,11 +390,14 @@ 127, 20 + + 4 + Port - - + + 4 7 @@ -399,8 +426,11 @@ System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - groupBox2 + + 12, 44 + + + Custom SOCKS @@ -414,15 +444,24 @@ 3 + + 87, 42 + - 87, 39 + 87, 67 - 7 + 9 Inject global import. + + 60, 16 + + + Remark + $this @@ -438,8 +477,8 @@ System.Windows.Forms.ToolTip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 12, 19 + + True System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 @@ -462,8 +501,8 @@ groupBox2 - - Share proxy over LAN. + + Bottom Config @@ -471,8 +510,8 @@ chkInIP - - 2, 2, 2, 2 + + Bottom chkMark @@ -489,15 +528,27 @@ System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + NoControl + + + Share proxy over LAN. + 127, 20 + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + 16, 13 66, 16 + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 @@ -513,11 +564,14 @@ 2, 2, 2, 2 + + + groupBox2 - 6 + 8 3 @@ -540,15 +594,15 @@ groupBox2 + + chkRemark + 223, 62 2, 2, 2, 2 - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 4 @@ -564,8 +618,8 @@ 2, 2, 2, 2 - - + + 5 True @@ -574,7 +628,7 @@ 2, 2, 2, 2 - 105, 220 + 105, 260 FormBatchModifyServerSetting @@ -588,8 +642,8 @@ - - 66, 16 + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 127, 21 @@ -624,8 +678,8 @@ groupBox1 - - 6 + + 12, 20 Inbound protocol. Config means keep the original config. @@ -636,8 +690,8 @@ 2, 2, 2, 2 - - + + 2, 2, 2, 2 Import @@ -667,11 +721,14 @@ - 87, 82 + 87, 115 7 + + 66, 16 + 6, 12 @@ -699,9 +756,18 @@ Mark + + + + + 127, 21 + 127, 20 + + 4 + groupBox2 @@ -739,7 +805,7 @@ System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 173, 220 + 173, 260 5 @@ -766,7 +832,7 @@ 4 - 12, 41 + 12, 69 True @@ -774,6 +840,9 @@ 2 + + groupBox2 + 12, 62 @@ -786,6 +855,9 @@ System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 6 + True diff --git a/V2RayGCon/Views/WinForms/FormBatchModifyServerSetting.zh-CN.resx b/V2RayGCon/Views/WinForms/FormBatchModifyServerSetting.zh-CN.resx index 18e680a3..2e23deaa 100644 --- a/V2RayGCon/Views/WinForms/FormBatchModifyServerSetting.zh-CN.resx +++ b/V2RayGCon/Views/WinForms/FormBatchModifyServerSetting.zh-CN.resx @@ -156,6 +156,9 @@ 允许局域网访问代理 + + 自定义 + @@ -192,9 +195,18 @@ + + + 注入全局import + + 备注 + + + + 自启动 diff --git a/V2RayGCon/Views/WinForms/FormModifyServerSettings.Designer.cs b/V2RayGCon/Views/WinForms/FormModifyServerSettings.Designer.cs index 3651ab4d..60948e1f 100644 --- a/V2RayGCon/Views/WinForms/FormModifyServerSettings.Designer.cs +++ b/V2RayGCon/Views/WinForms/FormModifyServerSettings.Designer.cs @@ -57,11 +57,13 @@ private void InitializeComponent() // resources.ApplyResources(this.label1, "label1"); this.label1.Name = "label1"; + this.toolTip1.SetToolTip(this.label1, resources.GetString("label1.ToolTip")); // // tboxServerName // resources.ApplyResources(this.tboxServerName, "tboxServerName"); this.tboxServerName.Name = "tboxServerName"; + this.toolTip1.SetToolTip(this.tboxServerName, resources.GetString("tboxServerName.ToolTip")); // // cboxInboundAddress // @@ -73,6 +75,7 @@ private void InitializeComponent() resources.GetString("cboxInboundAddress.Items2"), resources.GetString("cboxInboundAddress.Items3")}); this.cboxInboundAddress.Name = "cboxInboundAddress"; + this.toolTip1.SetToolTip(this.cboxInboundAddress, resources.GetString("cboxInboundAddress.ToolTip")); this.cboxInboundAddress.TextChanged += new System.EventHandler(this.cboxInboundAddress_TextChanged); // // chkAutoRun @@ -98,14 +101,16 @@ private void InitializeComponent() // // cboxInboundMode // + resources.ApplyResources(this.cboxInboundMode, "cboxInboundMode"); this.cboxInboundMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cboxInboundMode.FormattingEnabled = true; this.cboxInboundMode.Items.AddRange(new object[] { resources.GetString("cboxInboundMode.Items"), resources.GetString("cboxInboundMode.Items1"), - resources.GetString("cboxInboundMode.Items2")}); - resources.ApplyResources(this.cboxInboundMode, "cboxInboundMode"); + resources.GetString("cboxInboundMode.Items2"), + resources.GetString("cboxInboundMode.Items3")}); this.cboxInboundMode.Name = "cboxInboundMode"; + this.toolTip1.SetToolTip(this.cboxInboundMode, resources.GetString("cboxInboundMode.ToolTip")); this.cboxInboundMode.SelectedIndexChanged += new System.EventHandler(this.cboxInboundMode_SelectedIndexChanged); // // cboxMark @@ -113,6 +118,7 @@ private void InitializeComponent() resources.ApplyResources(this.cboxMark, "cboxMark"); this.cboxMark.FormattingEnabled = true; this.cboxMark.Name = "cboxMark"; + this.toolTip1.SetToolTip(this.cboxMark, resources.GetString("cboxMark.ToolTip")); // // chkUntrack // @@ -143,6 +149,7 @@ private void InitializeComponent() // resources.ApplyResources(this.btnSave, "btnSave"); this.btnSave.Name = "btnSave"; + this.toolTip1.SetToolTip(this.btnSave, resources.GetString("btnSave.ToolTip")); this.btnSave.UseVisualStyleBackColor = true; this.btnSave.Click += new System.EventHandler(this.btnSave_Click); // @@ -162,27 +169,32 @@ private void InitializeComponent() // resources.ApplyResources(this.label7, "label7"); this.label7.Name = "label7"; + this.toolTip1.SetToolTip(this.label7, resources.GetString("label7.ToolTip")); // // tboxDescription // resources.ApplyResources(this.tboxDescription, "tboxDescription"); this.tboxDescription.Name = "tboxDescription"; + this.toolTip1.SetToolTip(this.tboxDescription, resources.GetString("tboxDescription.ToolTip")); // // label10 // resources.ApplyResources(this.label10, "label10"); this.label10.Name = "label10"; + this.toolTip1.SetToolTip(this.label10, resources.GetString("label10.ToolTip")); // // tboxTitle // resources.ApplyResources(this.tboxTitle, "tboxTitle"); this.tboxTitle.Name = "tboxTitle"; this.tboxTitle.ReadOnly = true; + this.toolTip1.SetToolTip(this.tboxTitle, resources.GetString("tboxTitle.ToolTip")); // // tboxRemark // resources.ApplyResources(this.tboxRemark, "tboxRemark"); this.tboxRemark.Name = "tboxRemark"; + this.toolTip1.SetToolTip(this.tboxRemark, resources.GetString("tboxRemark.ToolTip")); // // FormModifyServerSettings // @@ -209,6 +221,7 @@ private void InitializeComponent() this.Controls.Add(this.label3); this.Controls.Add(this.label1); this.Name = "FormModifyServerSettings"; + this.toolTip1.SetToolTip(this, resources.GetString("$this.ToolTip")); this.Load += new System.EventHandler(this.FormModifyServerSettings_Load); this.ResumeLayout(false); this.PerformLayout(); diff --git a/V2RayGCon/Views/WinForms/FormModifyServerSettings.resx b/V2RayGCon/Views/WinForms/FormModifyServerSettings.resx index 8ab18e62..c160f91a 100644 --- a/V2RayGCon/Views/WinForms/FormModifyServerSettings.resx +++ b/V2RayGCon/Views/WinForms/FormModifyServerSettings.resx @@ -118,630 +118,669 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True + + 4 - - 6, 43 + + 35, 12 - - 29, 12 + + tboxServerName - - 0 + + label6 - - Name + + 0.0.0.0:1080 - - label1 + + True - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 5 - - $this + + - - 19 + + lovely - - - Top, Left, Right + + 0 - - 83, 39 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 190, 21 + + $this 0 - - lovely - - - tboxServerName + + 83, 39 - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 6, 123 - - $this + + Autorun - - 11 + + - - Top, Left, Right + + 0 - - 0.0.0.0:1080 + + btnSave - - 0.0.0.0:8080 + + tboxTitle - - 127.0.0.1:1080 + + Mark - - 127.0.0.1:8080 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 156, 93 + + True - - 117, 20 + + $this - - 3 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 127.0.0.1:12345 + + + Top, Left, Right - - cboxInboundAddress + + chkAutoRun - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 5 - + $this - - 8 - True - - 83, 172 - - - 66, 16 - - - 6 + + $this - - Autorun + + NoControl - - 17, 17 - - - Run this server when app start. + + NoControl - - chkAutoRun + + Global import * - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 16 - - $this + + True - - 5 + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 156, 194 + + 66, 16 - - 114, 16 + + cboxMark - - 9 + + Inbound - - Global import * + + Server settings - - Inject global imports when this server starts. + + NoControl - - chkGlobalImport + + * means server will restart - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 19 - - $this + + 83, 66 - - 4 + + label10 - - True + + label1 - - NoControl + + 0 156, 172 - - 126, 16 + + $this - - 7 + + NoControl - - Bypass CN sites * + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Inject bypass cn sites routing setting when core starts. + + 6, 12 chkBypassCnSite - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 11, 12 - - $this + + System.Windows.Forms.ToolTip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 2 + + Title - - Config + + 8 - - HTTP + + 117, 20 - - SOCKS + + * - - 83, 93 + + 190, 21 - - 67, 20 + + True - - 2 + + tboxRemark - - cboxInboundMode + + 83, 119 - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True - + + Inject bypass cn sites routing setting when core starts. + + + 8 + + + 29, 12 + + + 0 + + + 67, 20 + + $this - - 6 + + 12 - - Top, Left, Right + + 3 - - 83, 119 + + - - 190, 20 + + 17 - - 4 + + - - cboxMark + + 1 - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Inject global imports when this server starts. - + $this - - 7 + + 126, 16 - - True + + label5 - - 83, 194 + + 71, 12 - - 66, 16 + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 8 + + 83, 172 - - Untrack + + 6, 148 - - Do not keep this server's running state. + + 190, 20 - - chkUntrack + + 6, 43 - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 156, 194 - - $this + + Top, Right - - 3 + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True + + FormModifyServerSettings - - 6, 97 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 47, 12 + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 0 + + toolTip1 - - Inbound + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Override inbound settings. Config means no override. + + 4 - - label2 + + 14 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 320, 313 - + + 83, 145 + + $this - - 17 + + 10 - - Top, Right + + 7 - - True + + Label for searching. - - 281, 97 + + Bottom - - 11, 12 + + SOCKS - - 0 + + Bypass CN sites * - - * + + 10 - - Server will restart! + + 47, 12 - - label5 + + 2 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + CenterScreen - - $this + + 281, 97 - - 13 + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True + + $this - - 6, 123 + + Server will restart! - - 29, 12 + + $this - - 0 + + Run this server when app start. - - Mark + + True - - Label for searching. + + Untrack - - label6 + + - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True - + $this - - 15 + + 6, 216 - - Bottom + + 2 - - 117, 238 + + 3 - - 70, 24 + + label4 - - 10 + + chkGlobalImport - - Save + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - btnSave + + Description - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 66, 16 - - $this + + Top, Left, Right - - 1 + + 0 - - True + + 9 - - NoControl + + Save 6, 16 - - 35, 12 - - + 0 - - Title - 修改Inbound地址及端口 - - label3 - - + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - $this + + 83, 12 + + + 117, 238 + + + Top, Left, Right + + + Top, Left, Right + + + True + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 6 + + + 127.0.0.1:8080 - - 18 + + Config - - True + + 0.0.0.0:8080 - - NoControl + + 11 - - 6, 148 + + 7 - - 41, 12 + + $this - + + Do not keep this server's running state. + + 0 - - Remark + + $this - - Label for searching. + + $this - - label4 + + System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + label3 - + $this - - 14 + + 167, 12 - - True + + Override inbound settings. Config means no override. + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 6, 70 - - 71, 12 + + 83, 93 - - 0 + + 127.0.0.1:12345 - - Description + + 6, 97 - - label7 + + tboxDescription - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - $this + + Label for searching. - - 16 + + 29, 12 - - Top, Left, Right + + - - 83, 66 + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 190, 21 - - 1 + + 9 - - a lovely server + + $this - - tboxDescription + + True - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Name - + + + + + + + + + + + 127.0.0.1:1080 + + $this - - 9 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True + + cboxInboundMode - - NoControl + + Custom - - 6, 216 + + 190, 21 - - 167, 12 + + label2 0 - - * means server will restart + + 13 - - label10 + + - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 0 - - $this + + Top, Left, Right - - 12 + + 304, 274 - - Top, Left, Right + + label7 - - 83, 12 + + + + + 156, 93 190, 21 - - 0 - - - tboxTitle + + 15 - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + chkUntrack - - $this + + 6 - - 0 + + 18 - + Top, Left, Right - - 83, 145 + + True - - 190, 21 + + 114, 16 - - 5 + + a lovely server + + + + + + cboxInboundAddress remark - - tboxRemark - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - $this + + 41, 12 - - 10 + + 83, 194 - - True - - - 6, 12 + + 70, 24 - - 304, 274 + + $this - - 320, 313 + + $this - - CenterScreen + + 0 - - Server settings + + $this - - toolTip1 + + True - - System.Windows.Forms.ToolTip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Remark - - FormModifyServerSettings + + 1 - - System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + HTTP + + True + + + 17, 17 + \ No newline at end of file diff --git a/V2RayGCon/Views/WinForms/FormModifyServerSettings.zh-CN.resx b/V2RayGCon/Views/WinForms/FormModifyServerSettings.zh-CN.resx index 49dfac52..34981f7e 100644 --- a/V2RayGCon/Views/WinForms/FormModifyServerSettings.zh-CN.resx +++ b/V2RayGCon/Views/WinForms/FormModifyServerSettings.zh-CN.resx @@ -120,15 +120,6 @@ 名称 - - - - - - - - - 自启动 @@ -147,11 +138,8 @@ 服务器启动时注入绕过CN网站的routing配置 - - - - - + + 自定义 不追踪 @@ -174,9 +162,6 @@ 保存 - - - 标题 @@ -189,28 +174,10 @@ 描述 - - - - - - * 修改带星号的选项会重启服务器 - - - - - - - - - 服务器设置 - - - \ No newline at end of file diff --git a/V2RayGCon/Views/WinForms/FormOption.Designer.cs b/V2RayGCon/Views/WinForms/FormOption.Designer.cs index 9faec421..762e56b6 100644 --- a/V2RayGCon/Views/WinForms/FormOption.Designer.cs +++ b/V2RayGCon/Views/WinForms/FormOption.Designer.cs @@ -68,6 +68,8 @@ private void InitializeComponent() this.cboxSettingLanguage = new System.Windows.Forms.ComboBox(); this.label1 = new System.Windows.Forms.Label(); this.tabPageDefaults = new System.Windows.Forms.TabPage(); + this.groupBox7 = new System.Windows.Forms.GroupBox(); + this.exRTBoxDefCustomInbounds = new VgcApis.UserControls.ExRichTextBox(); this.groupBox4 = new System.Windows.Forms.GroupBox(); this.chkDefImportInjectGlobalImport = new System.Windows.Forms.CheckBox(); this.chkDefImportBypassCnSite = new System.Windows.Forms.CheckBox(); @@ -108,6 +110,7 @@ private void InitializeComponent() this.groupBox5.SuspendLayout(); this.groupBox1.SuspendLayout(); this.tabPageDefaults.SuspendLayout(); + this.groupBox7.SuspendLayout(); this.groupBox4.SuspendLayout(); this.groupBox3.SuspendLayout(); this.tabPageImport.SuspendLayout(); @@ -408,12 +411,26 @@ private void InitializeComponent() // // tabPageDefaults // + this.tabPageDefaults.Controls.Add(this.groupBox7); this.tabPageDefaults.Controls.Add(this.groupBox4); this.tabPageDefaults.Controls.Add(this.groupBox3); resources.ApplyResources(this.tabPageDefaults, "tabPageDefaults"); this.tabPageDefaults.Name = "tabPageDefaults"; this.tabPageDefaults.UseVisualStyleBackColor = true; // + // groupBox7 + // + resources.ApplyResources(this.groupBox7, "groupBox7"); + this.groupBox7.Controls.Add(this.exRTBoxDefCustomInbounds); + this.groupBox7.Name = "groupBox7"; + this.groupBox7.TabStop = false; + // + // exRTBoxDefCustomInbounds + // + resources.ApplyResources(this.exRTBoxDefCustomInbounds, "exRTBoxDefCustomInbounds"); + this.exRTBoxDefCustomInbounds.Name = "exRTBoxDefCustomInbounds"; + this.toolTip1.SetToolTip(this.exRTBoxDefCustomInbounds, resources.GetString("exRTBoxDefCustomInbounds.ToolTip")); + // // groupBox4 // resources.ApplyResources(this.groupBox4, "groupBox4"); @@ -461,7 +478,8 @@ private void InitializeComponent() this.cboxDefImportMode.Items.AddRange(new object[] { resources.GetString("cboxDefImportMode.Items"), resources.GetString("cboxDefImportMode.Items1"), - resources.GetString("cboxDefImportMode.Items2")}); + resources.GetString("cboxDefImportMode.Items2"), + resources.GetString("cboxDefImportMode.Items3")}); resources.ApplyResources(this.cboxDefImportMode, "cboxDefImportMode"); this.cboxDefImportMode.Name = "cboxDefImportMode"; this.toolTip1.SetToolTip(this.cboxDefImportMode, resources.GetString("cboxDefImportMode.ToolTip")); @@ -688,6 +706,7 @@ private void InitializeComponent() this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.tabPageDefaults.ResumeLayout(false); + this.groupBox7.ResumeLayout(false); this.groupBox4.ResumeLayout(false); this.groupBox4.PerformLayout(); this.groupBox3.ResumeLayout(false); @@ -759,18 +778,20 @@ private void InitializeComponent() private System.Windows.Forms.TextBox tboxSettingsMaxCoreNum; private System.Windows.Forms.Label label13; private System.Windows.Forms.Label label12; - private System.Windows.Forms.CheckBox chkSubsIsAutoPatch; - private System.Windows.Forms.TabPage tabPageMultiConf; - private System.Windows.Forms.Button btnMultiConfAdd; - private System.Windows.Forms.FlowLayoutPanel flyMultiConfPanel; - private System.Windows.Forms.ComboBox cboxDefSpeedTestExpectedSize; - private System.Windows.Forms.ComboBox cboxDefSpeedTestUrl; - private System.Windows.Forms.ComboBox cboxSettingsRandomSelectServerLatency; - private System.Windows.Forms.Label label14; - private System.Windows.Forms.Label label15; - private System.Windows.Forms.CheckBox chkSetSelfSignedCert; - private System.Windows.Forms.CheckBox chkSetEnableDebugFile; - private System.Windows.Forms.TextBox tboxSetDebugFilePath; - private System.Windows.Forms.Button btnSetBrowseDebugFile; + private System.Windows.Forms.CheckBox chkSubsIsAutoPatch; + private System.Windows.Forms.TabPage tabPageMultiConf; + private System.Windows.Forms.Button btnMultiConfAdd; + private System.Windows.Forms.FlowLayoutPanel flyMultiConfPanel; + private System.Windows.Forms.ComboBox cboxDefSpeedTestExpectedSize; + private System.Windows.Forms.ComboBox cboxDefSpeedTestUrl; + private System.Windows.Forms.ComboBox cboxSettingsRandomSelectServerLatency; + private System.Windows.Forms.Label label14; + private System.Windows.Forms.Label label15; + private System.Windows.Forms.CheckBox chkSetSelfSignedCert; + private System.Windows.Forms.CheckBox chkSetEnableDebugFile; + private System.Windows.Forms.TextBox tboxSetDebugFilePath; + private System.Windows.Forms.Button btnSetBrowseDebugFile; + private System.Windows.Forms.GroupBox groupBox7; + private VgcApis.UserControls.ExRichTextBox exRTBoxDefCustomInbounds; } } diff --git a/V2RayGCon/Views/WinForms/FormOption.cs b/V2RayGCon/Views/WinForms/FormOption.cs index 6ed494b2..1953f03f 100644 --- a/V2RayGCon/Views/WinForms/FormOption.cs +++ b/V2RayGCon/Views/WinForms/FormOption.cs @@ -112,7 +112,9 @@ private Controllers.FormOptionCtrl InitOptionCtrl() cboxDefSpeedTestUrl, tboxDefSpeedtestCycles, cboxDefSpeedTestExpectedSize, - tboxDefSpeedtestTimeout) + tboxDefSpeedtestTimeout, + + exRTBoxDefCustomInbounds) ); return ctrl; diff --git a/V2RayGCon/Views/WinForms/FormOption.resx b/V2RayGCon/Views/WinForms/FormOption.resx index 6cc8b0b8..7ab14bca 100644 --- a/V2RayGCon/Views/WinForms/FormOption.resx +++ b/V2RayGCon/Views/WinForms/FormOption.resx @@ -1236,6 +1236,66 @@ 1 + + Top, Bottom, Left, Right + + + Top, Bottom, Left, Right + + + 6, 20 + + + ForcedVertical + + + 428, 109 + + + 1 + + + [] + + + [{ ... }, {...}, ...] + + + exRTBoxDefCustomInbounds + + + VgcApis.UserControls.ExRichTextBox, VgcApis, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + groupBox7 + + + 0 + + + 13, 164 + + + 449, 140 + + + 8 + + + Custom inbounds + + + groupBox7 + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tabPageDefaults + + + 0 + Top, Left, Right @@ -1374,6 +1434,9 @@ SOCKS + + Custom + 80, 18 @@ -1456,7 +1519,7 @@ Def. Mode - Config means keep original inbound config. + Default inbound mode. Config means keep original inbound config. label10 @@ -1498,7 +1561,7 @@ tabPageDefaults - 0 + 1 Top, Left, Right @@ -1857,7 +1920,7 @@ tabPageDefaults - 1 + 2 4, 22 diff --git a/V2RayGCon/Views/WinForms/FormOption.zh-CN.resx b/V2RayGCon/Views/WinForms/FormOption.zh-CN.resx index 22198e55..5d9e9b80 100644 --- a/V2RayGCon/Views/WinForms/FormOption.zh-CN.resx +++ b/V2RayGCon/Views/WinForms/FormOption.zh-CN.resx @@ -297,6 +297,12 @@ + + 自定义inbounds + + + + 全局import @@ -312,8 +318,11 @@ 导入时包含shadowsocks分享链接 + + 自定义 + - Config表示保持原样 + 默认地址 @@ -325,7 +334,7 @@ 默认模式 - Config表示保持原样 + 默认inbound模式。Config表示保持原样。 导入分享链接 diff --git a/VgcApis/Models/Datas/Enums.cs b/VgcApis/Models/Datas/Enums.cs index 81aee48a..c67a71b2 100644 --- a/VgcApis/Models/Datas/Enums.cs +++ b/VgcApis/Models/Datas/Enums.cs @@ -70,6 +70,7 @@ public enum ProxyTypes Config = 0, HTTP = 1, SOCKS = 2, + Custom = 3, } public enum FormLocations From b4cc5c0faf4b889afb84a332b0e6465bc7c4ccb0 Mon Sep 17 00:00:00 2001 From: nobody Date: Thu, 4 Jun 2020 19:02:14 +0800 Subject: [PATCH 03/14] Support multiple v2ray-core update source. --- V2RayGCon/Libs/Nets/Downloader.cs | 33 +- V2RayGCon/Libs/V2Ray/Core.cs | 6 +- V2RayGCon/Misc/Utils.cs | 41 -- V2RayGCon/Models/Datas/UserSettings.cs | 6 +- V2RayGCon/Properties/AssemblyInfo.cs | 3 +- V2RayGCon/Resources/Resx/StrConst.Designer.cs | 168 +----- V2RayGCon/Resources/Resx/StrConst.resx | 59 +- V2RayGCon/Services/Notifier.cs | 5 +- V2RayGCon/Services/Settings.cs | 9 + V2RayGCon/V2RayGCon.csproj | 19 +- V2RayGCon/Views/UserControls/WelcomeUI.cs | 3 +- .../WinForms/FormDownloadCore.Designer.cs | 32 +- V2RayGCon/Views/WinForms/FormDownloadCore.cs | 103 +++- .../Views/WinForms/FormDownloadCore.resx | 505 +++++++++--------- .../WinForms/FormDownloadCore.zh-CN.resx | 13 +- V2RayGCon/Views/WinForms/FormQRCode.cs | 2 +- VgcApis/Models/Consts/Core.cs | 29 + VgcApis/Models/Consts/Files.cs | 1 + VgcApis/Models/Consts/Patterns.cs | 2 + VgcApis/Models/Consts/Webs.cs | 2 + 20 files changed, 451 insertions(+), 590 deletions(-) diff --git a/V2RayGCon/Libs/Nets/Downloader.cs b/V2RayGCon/Libs/Nets/Downloader.cs index b428f3ee..a34bca4c 100644 --- a/V2RayGCon/Libs/Nets/Downloader.cs +++ b/V2RayGCon/Libs/Nets/Downloader.cs @@ -12,7 +12,8 @@ internal sealed class Downloader public event EventHandler OnProgress; string _packageName; - string _version; + string _version = @"v4.23.4"; + string _source = VgcApis.Models.Consts.Core.GetSourceUrlByIndex(0); string _sha256sum = null; readonly object waitForDigest = new object(); @@ -24,16 +25,20 @@ internal sealed class Downloader public Downloader(Services.Settings setting) { this.setting = setting; - SetArchitecture(false); - _version = StrConst.DefCoreVersion; webClient = null; } #region public method + public void SetSource(int index) + { + _source = VgcApis.Models.Consts.Core.GetSourceUrlByIndex(index); + } + public void SetArchitecture(bool win64 = false) { - _packageName = win64 ? StrConst.PkgWin64 : StrConst.PkgWin32; + var arch = win64 ? "64" : "32"; + _packageName = $"v2ray-windows-{arch}.zip"; } public void SetVersion(string version) @@ -80,7 +85,7 @@ public bool UnzipPackage() } } - VgcApis.Misc.Utils.Sleep(2000); + VgcApis.Misc.Utils.Sleep(1000); try { RemoveOldExe(path); @@ -109,7 +114,11 @@ public void Cancel() #region private method void RemoveOldExe(string path) { - string[] exes = new string[] { "v2ray.exe", "v2ctl.exe" }; + string[] exes = new string[] { + VgcApis.Models.Consts.Core.V2RayCoreExeFileName, + VgcApis.Models.Consts.Core.V2RayCtlExeFileName, + }; + string prefix = "bak"; foreach (var exe in exes) @@ -168,7 +177,7 @@ void UpdateCore() var pluginServ = Services.PluginsServer.Instance; pluginServ.StopAllPlugins(); - VgcApis.Misc.Utils.Sleep(3000); + VgcApis.Misc.Utils.Sleep(1000); var activeServerList = servers.GetRunningServers(); servers.StopAllServersThen(() => @@ -248,10 +257,16 @@ void GetSha256Sum(string url) ?.Trim(); } + string GenReleaseUrl() + { + // tail = "/releases/download/{0}/{1}"; + string tpl = _source + @"/download/{0}/{1}"; + return string.Format(tpl, _version, _packageName); + } + void Download() { - string tpl = StrConst.DownloadLinkTpl; - string url = string.Format(tpl, _version, _packageName); + string url = GenReleaseUrl(); lock (waitForDigest) { diff --git a/V2RayGCon/Libs/V2Ray/Core.cs b/V2RayGCon/Libs/V2Ray/Core.cs index 5d04ade4..1af10be9 100644 --- a/V2RayGCon/Libs/V2Ray/Core.cs +++ b/V2RayGCon/Libs/V2Ray/Core.cs @@ -38,7 +38,7 @@ string v2ctl { if (string.IsNullOrEmpty(_v2ctl)) { - _v2ctl = GetExecutablePath(StrConst.ExecutableV2ctl); + _v2ctl = GetExecutablePath(VgcApis.Models.Consts.Core.V2RayCtlExeFileName); } return _v2ctl; } @@ -82,7 +82,7 @@ public int QueryStatsApi(int port, bool isUplink) } var queryParam = string.Format( - StrConst.StatsQueryParamTpl, + VgcApis.Models.Consts.Core.StatsQueryParamTpl, port.ToString(), isUplink ? "uplink" : "downlink"); @@ -132,7 +132,7 @@ public string GetExecutablePath(string fileName = null) List folders = GenV2RayCoreSearchPaths(setting.isPortable); for (var i = 0; i < folders.Count; i++) { - var file = Path.Combine(folders[i], fileName ?? StrConst.ExecutableV2ray); + var file = Path.Combine(folders[i], fileName ?? VgcApis.Models.Consts.Core.V2RayCoreExeFileName); if (File.Exists(file)) { return file; diff --git a/V2RayGCon/Misc/Utils.cs b/V2RayGCon/Misc/Utils.cs index e025eb30..163e5509 100644 --- a/V2RayGCon/Misc/Utils.cs +++ b/V2RayGCon/Misc/Utils.cs @@ -1139,49 +1139,8 @@ public static string Fetch(string url) => public static string Fetch(string url, int timeout) => Fetch(url, -1, timeout); - public static string GetLatestVgcVersion() - { - string html = Fetch(StrConst.UrlLatestVGC); - if (string.IsNullOrEmpty(html)) - { - return string.Empty; - } - string p = StrConst.PatternLatestVGC; - var match = Regex.Match(html, p, RegexOptions.IgnoreCase); - if (match.Success) - { - return match.Groups[1].Value; - } - - return string.Empty; - } - - public static List GetOnlineV2RayCoreVersionList(int proxyPort) - { - List versions = new List { }; - var url = StrConst.V2rayCoreReleasePageUrl; - - string html = Fetch(url, proxyPort, -1); - if (string.IsNullOrEmpty(html)) - { - return versions; - } - - string pattern = StrConst.PatternDownloadLink; - var matches = Regex.Matches(html, pattern, RegexOptions.IgnoreCase); - foreach (Match match in matches) - { - var v = match.Groups[1].Value; - if (!versions.Contains(v)) - { - versions.Add(v); - } - } - - return versions; - } #endregion #region files diff --git a/V2RayGCon/Models/Datas/UserSettings.cs b/V2RayGCon/Models/Datas/UserSettings.cs index 275cfa41..f60834f1 100644 --- a/V2RayGCon/Models/Datas/UserSettings.cs +++ b/V2RayGCon/Models/Datas/UserSettings.cs @@ -20,7 +20,8 @@ class UserSettings public SpeedTestOptions SpeedtestOptions = null; // FormDownloadCore - public bool isDownloadWin32V2RayCore { get; set; } = true; + public bool isDownloadWin32V2RayCore { get; set; } + public string v2rayCoreDownloadSource { get; set; } public List V2RayCoreDownloadVersionList = null; public bool isSupportSelfSignedCert { get; set; } @@ -58,6 +59,9 @@ public UserSettings() { Normalized(); + isDownloadWin32V2RayCore = true; + v2rayCoreDownloadSource = VgcApis.Models.Consts.Core.GetSourceUrlByIndex(0); + CustomInbounds = @"[]"; DebugLogFilePath = @""; diff --git a/V2RayGCon/Properties/AssemblyInfo.cs b/V2RayGCon/Properties/AssemblyInfo.cs index 734bc04c..87594d26 100644 --- a/V2RayGCon/Properties/AssemblyInfo.cs +++ b/V2RayGCon/Properties/AssemblyInfo.cs @@ -33,10 +33,11 @@ // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0.2")] +[assembly: AssemblyVersion("1.4.0.3")] [assembly: AssemblyFileVersion("1.0.0.0")] /* + * v1.4.0.3 Add v2fly as core update source. * v1.4.0.2 Custom inbounds support. * v1.4.0.1 Fix a bug in v2ray-core updating. * ---------------------------------------- diff --git a/V2RayGCon/Resources/Resx/StrConst.Designer.cs b/V2RayGCon/Resources/Resx/StrConst.Designer.cs index 2fe16482..36daaf57 100644 --- a/V2RayGCon/Resources/Resx/StrConst.Designer.cs +++ b/V2RayGCon/Resources/Resx/StrConst.Designer.cs @@ -245,173 +245,11 @@ internal static string ConfigJsonKeywords { } /// - /// 查找类似 v3.26 的本地化字符串。 + /// 查找类似 DO NOT REMOVE THIS FILE! 的本地化字符串。 /// - internal static string DefCoreVersion { + internal static string Notice { get { - return ResourceManager.GetString("DefCoreVersion", resourceCulture); - } - } - - /// - /// 查找类似 https://github.com/v2ray/v2ray-core/releases/download/{0}/{1} 的本地化字符串。 - /// - internal static string DownloadLinkTpl { - get { - return ResourceManager.GetString("DownloadLinkTpl", resourceCulture); - } - } - - /// - /// 查找类似 vmess://ew0KICAicHMiOiAiZHVtbXkxIiwNCiAgImFkZCI6ICIxLjIuMy40IiwNCiAgInBvcnQiOiAiNDQzIiwNCiAgImlkIjogImI4NzNkNWY0LTMyNjEtNGYxOS04MGE3LWYwZTY3YzkwYzA4MiIsDQogICJhaWQiOiAiMTAwIiwNCiAgIm5ldCI6ICJ3cyIsDQogICJ0eXBlIjogIm5vbmUiLA0KICAiaG9zdCI6ICIvcmF5IiwNCiAgInRscyI6ICJ0bHMiDQp9 的本地化字符串。 - /// - internal static string DummyServ1 { - get { - return ResourceManager.GetString("DummyServ1", resourceCulture); - } - } - - /// - /// 查找类似 vmess://ew0KICAicHMiOiAiZHVtbXkyIiwNCiAgImFkZCI6ICIyLjMuNC41IiwNCiAgInBvcnQiOiAiMTIzNCIsDQogICJpZCI6ICI1NjIxODM4ZS1hYmM1LTRiNmQtOWQzMS00MmUwOGE3ZWMzMmYiLA0KICAiYWlkIjogIjY0IiwNCiAgIm5ldCI6ICJ0Y3AiLA0KICAidHlwZSI6ICJub25lIiwNCiAgImhvc3QiOiAiIiwNCiAgInRscyI6ICIiDQp9 的本地化字符串。 - /// - internal static string DummyServ2 { - get { - return ResourceManager.GetString("DummyServ2", resourceCulture); - } - } - - /// - /// 查找类似 v2ctl.exe 的本地化字符串。 - /// - internal static string ExecutableV2ctl { - get { - return ResourceManager.GetString("ExecutableV2ctl", resourceCulture); - } - } - - /// - /// 查找类似 v2ray.exe 的本地化字符串。 - /// - internal static string ExecutableV2ray { - get { - return ResourceManager.GetString("ExecutableV2ray", resourceCulture); - } - } - - /// - /// 查找类似 JS Files|*.js|All File|*.* 的本地化字符串。 - /// - internal static string ExtJs { - get { - return ResourceManager.GetString("ExtJs", resourceCulture); - } - } - - /// - /// 查找类似 PNG Files|*.png|All File|*.* 的本地化字符串。 - /// - internal static string ExtPng { - get { - return ResourceManager.GetString("ExtPng", resourceCulture); - } - } - - /// - /// 查找类似 https://github.com/v2ray/v2ray-core/releases/latest 的本地化字符串。 - /// - internal static string LatestCoreLink { - get { - return ResourceManager.GetString("LatestCoreLink", resourceCulture); - } - } - - /// - /// 查找类似 https://www.youtube.com/watch?v=BA7fdSkp8ds 的本地化字符串。 - /// - internal static string Nobody3uVideoUrl { - get { - return ResourceManager.GetString("Nobody3uVideoUrl", resourceCulture); - } - } - - /// - /// 查找类似 /v2ray/v2ray-core/releases/download/(v[\.0-9]+)/v2ray-windows-64.zip 的本地化字符串。 - /// - internal static string PatternDownloadLink { - get { - return ResourceManager.GetString("PatternDownloadLink", resourceCulture); - } - } - - /// - /// 查找类似 /nobody3u/V2RayGCon/releases/tag/([\.0-9]+) 的本地化字符串。 - /// - internal static string PatternLatestVGC { - get { - return ResourceManager.GetString("PatternLatestVGC", resourceCulture); - } - } - - /// - /// 查找类似 v2ray-windows-32.zip 的本地化字符串。 - /// - internal static string PkgWin32 { - get { - return ResourceManager.GetString("PkgWin32", resourceCulture); - } - } - - /// - /// 查找类似 v2ray-windows-64.zip 的本地化字符串。 - /// - internal static string PkgWin64 { - get { - return ResourceManager.GetString("PkgWin64", resourceCulture); - } - } - - /// - /// 查找类似 api --server="127.0.0.1:{0}" StatsService.GetStats "name: """"inbound>>>agentin>>>traffic>>>{1}"""" reset: true" 的本地化字符串。 - /// - internal static string StatsQueryParamTpl { - get { - return ResourceManager.GetString("StatsQueryParamTpl", resourceCulture); - } - } - - /// - /// 查找类似 https://github.com/nobody3u/V2RayGCon/releases/tag/{0} 的本地化字符串。 - /// - internal static string TplUrlVGCRelease { - get { - return ResourceManager.GetString("TplUrlVGCRelease", resourceCulture); - } - } - - /// - /// 查找类似 https://github.com/nobody3u/V2RayGCon/releases/latest 的本地化字符串。 - /// - internal static string UrlLatestVGC { - get { - return ResourceManager.GetString("UrlLatestVGC", resourceCulture); - } - } - - /// - /// 查找类似 https://github.com/v2ray/v2ray-core/releases 的本地化字符串。 - /// - internal static string V2rayCoreReleasePageUrl { - get { - return ResourceManager.GetString("V2rayCoreReleasePageUrl", resourceCulture); - } - } - - /// - /// 查找类似 https://github.com/nobody3u/V2RayGCon/wiki/vlink 的本地化字符串。 - /// - internal static string VlinkWiki { - get { - return ResourceManager.GetString("VlinkWiki", resourceCulture); + return ResourceManager.GetString("Notice", resourceCulture); } } } diff --git a/V2RayGCon/Resources/Resx/StrConst.resx b/V2RayGCon/Resources/Resx/StrConst.resx index 4e007a80..8222a0bb 100644 --- a/V2RayGCon/Resources/Resx/StrConst.resx +++ b/V2RayGCon/Resources/Resx/StrConst.resx @@ -121,50 +121,9 @@ ..\Config\config_min.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312 - - https://github.com/v2ray/v2ray-core/releases/download/{0}/{1} - - - v2ray-windows-32.zip - - - v3.26 - - - v2ray.exe - - - vmess://ew0KICAicHMiOiAiZHVtbXkxIiwNCiAgImFkZCI6ICIxLjIuMy40IiwNCiAgInBvcnQiOiAiNDQzIiwNCiAgImlkIjogImI4NzNkNWY0LTMyNjEtNGYxOS04MGE3LWYwZTY3YzkwYzA4MiIsDQogICJhaWQiOiAiMTAwIiwNCiAgIm5ldCI6ICJ3cyIsDQogICJ0eXBlIjogIm5vbmUiLA0KICAiaG9zdCI6ICIvcmF5IiwNCiAgInRscyI6ICJ0bHMiDQp9 - - - vmess://ew0KICAicHMiOiAiZHVtbXkyIiwNCiAgImFkZCI6ICIyLjMuNC41IiwNCiAgInBvcnQiOiAiMTIzNCIsDQogICJpZCI6ICI1NjIxODM4ZS1hYmM1LTRiNmQtOWQzMS00MmUwOGE3ZWMzMmYiLA0KICAiYWlkIjogIjY0IiwNCiAgIm5ldCI6ICJ0Y3AiLA0KICAidHlwZSI6ICJub25lIiwNCiAgImhvc3QiOiAiIiwNCiAgInRscyI6ICIiDQp9 - - - v2ray-windows-64.zip - - - PNG Files|*.png|All File|*.* - - - https://github.com/v2ray/v2ray-core/releases/latest - - - /v2ray/v2ray-core/releases/download/(v[\.0-9]+)/v2ray-windows-64.zip - - - https://github.com/v2ray/v2ray-core/releases - - - /nobody3u/V2RayGCon/releases/tag/([\.0-9]+) - - - https://github.com/nobody3u/V2RayGCon/releases/tag/{0} - - - https://github.com/nobody3u/V2RayGCon/releases/latest - - - https://github.com/nobody3u/V2RayGCon/wiki/vlink + + DO NOT REMOVE THIS FILE! + 本文件包含config模板 ..\Config\config_pkg.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 @@ -172,18 +131,6 @@ ..\Config\config_example.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 - - JS Files|*.js|All File|*.* - - - https://www.youtube.com/watch?v=BA7fdSkp8ds - - - v2ctl.exe - - - api --server="127.0.0.1:{0}" StatsService.GetStats "name: """"inbound>>>agentin>>>traffic>>>{1}"""" reset: true" - ..\Files\CSharp\ConfigJsonKeywords.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 diff --git a/V2RayGCon/Services/Notifier.cs b/V2RayGCon/Services/Notifier.cs index dc44bd8e..add9015f 100644 --- a/V2RayGCon/Services/Notifier.cs +++ b/V2RayGCon/Services/Notifier.cs @@ -279,9 +279,10 @@ public void ScanQrcode() void Success(string link) { // no comment ^v^ - if (link == StrConst.Nobody3uVideoUrl) + var video = VgcApis.Models.Consts.Webs.Nobody3uVideoUrl; + if (link == video) { - Misc.UI.VisitUrl(I18N.VisitWebPage, StrConst.Nobody3uVideoUrl); + Misc.UI.VisitUrl(I18N.VisitWebPage, video); return; } diff --git a/V2RayGCon/Services/Settings.cs b/V2RayGCon/Services/Settings.cs index 44ef9cd8..19eadcce 100644 --- a/V2RayGCon/Services/Settings.cs +++ b/V2RayGCon/Services/Settings.cs @@ -140,6 +140,15 @@ public void SetShutdownReason(VgcApis.Models.Datas.Enums.ShutdownReasons reason) this.shutdownReason = reason; } + public string v2rayCoreDownloadSource + { + get => userSettings.v2rayCoreDownloadSource; + set + { + userSettings.v2rayCoreDownloadSource = value; + SaveSettingsLater(); + } + } public bool isDownloadWin32V2RayCore { diff --git a/V2RayGCon/V2RayGCon.csproj b/V2RayGCon/V2RayGCon.csproj index 178ab57e..42984cf5 100644 --- a/V2RayGCon/V2RayGCon.csproj +++ b/V2RayGCon/V2RayGCon.csproj @@ -152,6 +152,11 @@ + + True + True + StrConst.resx + @@ -271,11 +276,6 @@ - - StrConst.resx - True - True - I18N.zh-CN.resx True @@ -365,6 +365,10 @@ FormSimAddVmessClient.cs + + ResXFileCodeGenerator + StrConst.Designer.cs + MultiConfUI.cs @@ -411,11 +415,6 @@ Resources.resx True - - ResXFileCodeGenerator - StrConst.Designer.cs - Designer - ResXFileCodeGenerator I18N.zh-CN.Designer.cs diff --git a/V2RayGCon/Views/UserControls/WelcomeUI.cs b/V2RayGCon/Views/UserControls/WelcomeUI.cs index 8200ae2e..299fc54a 100644 --- a/V2RayGCon/Views/UserControls/WelcomeUI.cs +++ b/V2RayGCon/Views/UserControls/WelcomeUI.cs @@ -47,7 +47,8 @@ private void lbDownloadV2rayCore_LinkClicked(object sender, LinkLabelLinkClicked private void lbV2rayCoreGitHub_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { - Misc.UI.VisitUrl(I18N.VisitV2rayCoreReleasePage, StrConst.V2rayCoreReleasePageUrl); + var url = VgcApis.Models.Consts.Core.GetSourceUrlByIndex(0); + Misc.UI.VisitUrl(I18N.VisitV2rayCoreReleasePage, url); } private void lbWiki_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) diff --git a/V2RayGCon/Views/WinForms/FormDownloadCore.Designer.cs b/V2RayGCon/Views/WinForms/FormDownloadCore.Designer.cs index 3f3728d4..60fc2e9a 100644 --- a/V2RayGCon/Views/WinForms/FormDownloadCore.Designer.cs +++ b/V2RayGCon/Views/WinForms/FormDownloadCore.Designer.cs @@ -44,16 +44,16 @@ private void InitializeComponent() this.labelCoreVersion = new System.Windows.Forms.Label(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.cboxDownloadSource = new System.Windows.Forms.ComboBox(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.SuspendLayout(); // // cboxVer // - resources.ApplyResources(this.cboxVer, "cboxVer"); this.cboxVer.FormattingEnabled = true; + resources.ApplyResources(this.cboxVer, "cboxVer"); this.cboxVer.Name = "cboxVer"; - this.toolTip1.SetToolTip(this.cboxVer, resources.GetString("cboxVer.ToolTip")); // // btnRefreshVer // @@ -98,7 +98,6 @@ private void InitializeComponent() // resources.ApplyResources(this.btnExit, "btnExit"); this.btnExit.Name = "btnExit"; - this.toolTip1.SetToolTip(this.btnExit, resources.GetString("btnExit.ToolTip")); this.btnExit.UseVisualStyleBackColor = true; this.btnExit.Click += new System.EventHandler(this.BtnExit_Click); // @@ -106,56 +105,63 @@ private void InitializeComponent() // resources.ApplyResources(this.pgBarDownload, "pgBarDownload"); this.pgBarDownload.Name = "pgBarDownload"; - this.toolTip1.SetToolTip(this.pgBarDownload, resources.GetString("pgBarDownload.ToolTip")); // // label1 // resources.ApplyResources(this.label1, "label1"); this.label1.Name = "label1"; - this.toolTip1.SetToolTip(this.label1, resources.GetString("label1.ToolTip")); // // cboxArch // - resources.ApplyResources(this.cboxArch, "cboxArch"); this.cboxArch.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cboxArch.FormattingEnabled = true; this.cboxArch.Items.AddRange(new object[] { resources.GetString("cboxArch.Items"), resources.GetString("cboxArch.Items1")}); + resources.ApplyResources(this.cboxArch, "cboxArch"); this.cboxArch.Name = "cboxArch"; - this.toolTip1.SetToolTip(this.cboxArch, resources.GetString("cboxArch.ToolTip")); this.cboxArch.SelectedIndexChanged += new System.EventHandler(this.cboxArch_SelectedIndexChanged); // // labelCoreVersion // resources.ApplyResources(this.labelCoreVersion, "labelCoreVersion"); this.labelCoreVersion.Name = "labelCoreVersion"; - this.toolTip1.SetToolTip(this.labelCoreVersion, resources.GetString("labelCoreVersion.ToolTip")); // // groupBox1 // - resources.ApplyResources(this.groupBox1, "groupBox1"); this.groupBox1.Controls.Add(this.btnCheckVersion); this.groupBox1.Controls.Add(this.labelCoreVersion); + resources.ApplyResources(this.groupBox1, "groupBox1"); this.groupBox1.Name = "groupBox1"; this.groupBox1.TabStop = false; - this.toolTip1.SetToolTip(this.groupBox1, resources.GetString("groupBox1.ToolTip")); // // groupBox2 // - resources.ApplyResources(this.groupBox2, "groupBox2"); this.groupBox2.Controls.Add(this.chkUseProxy); this.groupBox2.Controls.Add(this.btnExit); this.groupBox2.Controls.Add(this.btnDownload); this.groupBox2.Controls.Add(this.btnCancel); + this.groupBox2.Controls.Add(this.cboxDownloadSource); this.groupBox2.Controls.Add(this.cboxArch); this.groupBox2.Controls.Add(this.label1); this.groupBox2.Controls.Add(this.pgBarDownload); this.groupBox2.Controls.Add(this.btnRefreshVer); this.groupBox2.Controls.Add(this.cboxVer); + resources.ApplyResources(this.groupBox2, "groupBox2"); this.groupBox2.Name = "groupBox2"; this.groupBox2.TabStop = false; - this.toolTip1.SetToolTip(this.groupBox2, resources.GetString("groupBox2.ToolTip")); + // + // cboxDownloadSource + // + this.cboxDownloadSource.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cboxDownloadSource.FormattingEnabled = true; + this.cboxDownloadSource.Items.AddRange(new object[] { + resources.GetString("cboxDownloadSource.Items"), + resources.GetString("cboxDownloadSource.Items1"), + resources.GetString("cboxDownloadSource.Items2")}); + resources.ApplyResources(this.cboxDownloadSource, "cboxDownloadSource"); + this.cboxDownloadSource.Name = "cboxDownloadSource"; + this.cboxDownloadSource.SelectedIndexChanged += new System.EventHandler(this.cboxDownloadSource_SelectedIndexChanged); // // FormDownloadCore // @@ -167,7 +173,6 @@ private void InitializeComponent() this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "FormDownloadCore"; - this.toolTip1.SetToolTip(this, resources.GetString("$this.ToolTip")); this.Shown += new System.EventHandler(this.FormDownloadCore_Shown); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); @@ -193,5 +198,6 @@ private void InitializeComponent() private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.Button btnExit; private System.Windows.Forms.CheckBox chkUseProxy; + private System.Windows.Forms.ComboBox cboxDownloadSource; } } \ No newline at end of file diff --git a/V2RayGCon/Views/WinForms/FormDownloadCore.cs b/V2RayGCon/Views/WinForms/FormDownloadCore.cs index 16c8f76d..8f87c3ca 100644 --- a/V2RayGCon/Views/WinForms/FormDownloadCore.cs +++ b/V2RayGCon/Views/WinForms/FormDownloadCore.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; using System.Windows.Forms; using V2RayGCon.Resources.Resx; @@ -45,18 +47,57 @@ public static FormDownloadCore ShowForm() private void FormDownloadCore_Shown(object sender, System.EventArgs e) { + RefreshV2RayCoreSourceUrls(); RefreshLocalV2RayCoreVersion(); chkUseProxy.Checked = setting.isUpdateUseProxy; } - #region private method + #region private methods + List GetOnlineV2RayCoreVersionList( + int proxyPort, string sourceUrl) + { + List versions = new List { }; + + string html = Misc.Utils.Fetch(sourceUrl, proxyPort, -1); + if (string.IsNullOrEmpty(html)) + { + return versions; + } + + string pattern = VgcApis.Models.Consts.Patterns.V2RayCoreReleaseAssets; + + var matches = Regex.Matches(html, pattern, RegexOptions.IgnoreCase); + foreach (Match match in matches) + { + var v = match.Groups[1].Value; + if (!versions.Contains(v)) + { + versions.Add(v); + } + } + + return versions; + } + + void RefreshV2RayCoreSourceUrls() + { + var urls = VgcApis.Models.Consts.Core.SourceUrls; + var items = cboxDownloadSource.Items; + items.Clear(); + items.AddRange(urls); + VgcApis.Misc.UI.ResetComboBoxDropdownMenuWidth(cboxDownloadSource); + var url = setting.v2rayCoreDownloadSource; + var index = VgcApis.Models.Consts.Core.GetIndexBySourceUrl(url); + cboxDownloadSource.SelectedIndex = index; + } + void RefreshLocalV2RayCoreVersion() { var el = labelCoreVersion; VgcApis.Misc.Utils.RunInBackground(() => { - var core = new V2RayGCon.Libs.V2Ray.Core(setting); + var core = new Libs.V2Ray.Core(setting); var version = core.GetCoreVersion(); var msg = string.IsNullOrEmpty(version) ? I18N.GetCoreVerFail : @@ -81,6 +122,7 @@ void EnableBtnDownload() void DownloadV2RayCore(int proxyPort) { downloader = new Libs.Nets.Downloader(setting); + downloader.SetSource(cboxDownloadSource.SelectedIndex); downloader.SetArchitecture(cboxArch.SelectedIndex == 1); downloader.SetVersion(cboxVer.Text); downloader.proxyPort = proxyPort; @@ -127,8 +169,7 @@ void ResetUI(int progress) void InitUI() { - cboxArch.SelectedIndex = - setting.isDownloadWin32V2RayCore ? 0 : 1; + cboxArch.SelectedIndex = setting.isDownloadWin32V2RayCore ? 0 : 1; var verList = setting.GetV2RayCoreVersionList(); Misc.UI.FillComboBox(cboxVer, new List(verList)); @@ -142,39 +183,35 @@ private void BtnExit_Click(object sender, System.EventArgs e) private void BtnRefreshVer_Click(object sender, System.EventArgs e) { - var elRefresh = btnRefreshVer; - var elCboxVer = cboxVer; + btnRefreshVer.Enabled = false; - elRefresh.Enabled = false; + var sourceUrl = VgcApis.Models.Consts.Core.GetSourceUrlByIndex(cboxDownloadSource.SelectedIndex); + int proxyPort = chkUseProxy.Checked ? servers.GetAvailableHttpProxyPort() : -1; - VgcApis.Misc.Utils.RunInBackground(() => + Action> done = (versions) => { - int proxyPort = -1; - if (chkUseProxy.Checked) + btnRefreshVer.Enabled = true; + if (versions.Count > 0) { - proxyPort = servers.GetAvailableHttpProxyPort(); + Misc.UI.FillComboBox(cboxVer, versions); } - var versions = Misc.Utils.GetOnlineV2RayCoreVersionList(proxyPort); - if (versions != null && versions.Count > 0) + else { - setting.SaveV2RayCoreVersionList(versions); + MessageBox.Show(I18N.GetVersionListFail); } + }; - VgcApis.Misc.UI.Invoke(() => elRefresh.Enabled = true); - - VgcApis.Misc.UI.Invoke(() => + Action worker = () => + { + var versions = GetOnlineV2RayCoreVersionList(proxyPort, sourceUrl); + if (versions != null && versions.Count > 0) { - if (versions.Count > 0) - { - Misc.UI.FillComboBox(elCboxVer, versions); - } - else - { - MessageBox.Show(I18N.GetVersionListFail); - } - }); + setting.SaveV2RayCoreVersionList(versions); + } + VgcApis.Misc.UI.Invoke(() => done(versions)); + }; - }); + VgcApis.Misc.Utils.RunInBackground(worker); } private void BtnUpdate_Click(object sender, System.EventArgs e) @@ -214,7 +251,6 @@ private void BtnCheckVersion_Click(object sender, System.EventArgs e) RefreshLocalV2RayCoreVersion(); } - #endregion private void cboxArch_SelectedIndexChanged(object sender, System.EventArgs e) { @@ -232,5 +268,14 @@ private void cboxArch_SelectedIndexChanged(object sender, System.EventArgs e) setting.isDownloadWin32V2RayCore = isWin32; } + + private void cboxDownloadSource_SelectedIndexChanged(object sender, System.EventArgs e) + { + var index = cboxDownloadSource.SelectedIndex; + var url = VgcApis.Models.Consts.Core.GetSourceUrlByIndex(index); + setting.v2rayCoreDownloadSource = url; + } + #endregion + } } diff --git a/V2RayGCon/Views/WinForms/FormDownloadCore.resx b/V2RayGCon/Views/WinForms/FormDownloadCore.resx index 50d751b9..30790625 100644 --- a/V2RayGCon/Views/WinForms/FormDownloadCore.resx +++ b/V2RayGCon/Views/WinForms/FormDownloadCore.resx @@ -117,403 +117,406 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Refresh version list - - - 197, 77 + + 86, 46 + + + 106, 20 - - 8 + + 0 - + + cboxVer + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + groupBox2 - - 2 + + 9 - - + + 8, 46 - - cboxVer + + 72, 20 - - 108, 20 + + 2 - - btnCancel + + Refresh - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + Refresh version list - - True + + btnRefreshVer + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 groupBox2 - - 7 + + 8 - - label1 + + 92, 103 - - Check current v2ray-core version. + + 75, 24 - + + 2 + + + Download + + + Download and update v2ray-core. + + + btnDownload + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + groupBox2 - - FormDownloadCore + + 2 - - chkUseProxy + + 173, 103 + + + 75, 24 2 - - 253, 20 - - - 8 + + Cancel - - 6 + + Stop download - - Refresh + + btnCancel - - 6 + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + groupBox2 - - 63, 20 + + 3 - - + + + NoControl - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 8, 20 - - 0 + + 76, 20 - - 6, 12 + + 7 - - 3 + + Recheck - - True + + Check current v2ray-core version. btnCheckVersion - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Download and update v2ray-core. + + groupBox1 - - + + 0 - - 2 + + True - - - CenterScreen + + 8, 107 - - NoControl + + 78, 16 - - 4 + + 7 - - 5 + + Use proxy - - Current version + + Randomly select a HTTP server to download v2ray-core. - - groupBox2 + + chkUseProxy - - groupBox2 + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 groupBox2 - + 0 - - 47, 12 + + NoControl - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 254, 103 - - + + 75, 24 - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 6 - - toolTip1 + + Exit - - 8, 20 + + btnExit - + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - + + groupBox2 - - True + + 1 - - 2 + + 8, 72 - - NoControl + + 321, 25 - - 364, 187 + + 3 - - Available version + + pgBarDownload - - Checking v2ray-core version... + + System.Windows.Forms.ProgressBar, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + + groupBox2 + + 7 - - groupBox1 + + True - - Download + + 198, 50 - - 78, 16 + + 47, 12 5 - - Randomly select a HTTP server to download v2ray-core. + + Windows - - 75, 20 + + label1 - + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + groupBox2 + + 6 + 32 bit - - 1 + + 64 bit - - 90, 24 + + 251, 46 - 76, 20 - - - Exit - - - 13, 12 + 78, 20 - - 8, 46 + + 4 - - + + cboxArch - - btnDownload + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 72, 20 + + groupBox2 - - 337, 51 + + 5 - - 4 + + True - - 63, 20 + + 90, 24 - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 185, 12 - - 64 bit + + 6 - - + + Checking v2ray-core version... - - pgBarDownload + + labelCoreVersion - - 0 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 3 + + groupBox1 - + 1 - - 76, 20 + + 13, 12 - - 321, 25 + + 337, 51 - - System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 8 - - btnRefreshVer + + Current version - - System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + groupBox1 - - cboxArch + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 266, 77 + + $this - + 1 - - + + github.com/v2ray/v2ray-core - - labelCoreVersion + + github.com/v2fly/v2ray-core - - 200, 24 + + - - 337, 106 + + 8, 20 - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 321, 20 - - Recheck + + 4 - - 7 + + cboxDownloadSource - - groupBox2 + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + groupBox2 - - - - - Stop download - - - 6 - - - 8 + + 4 13, 69 - - btnExit - - - System.Windows.Forms.ToolTip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Windows.Forms.ProgressBar, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 185, 12 - - - Download v2ray-core - - - groupBox1 - - - System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 337, 135 - - 86, 20 + + 8 - - 8, 80 + + Available version - - Cancel + + groupBox2 - - Use proxy + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + $this 0 - - $this + + True + + + 6, 12 - - 116, 77 + + 364, 217 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + CenterScreen - - 8, 20 + + Download v2ray-core - - groupBox1 + + toolTip1 - - Windows + + System.Windows.Forms.ToolTip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + FormDownloadCore + + + System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True - - - 17, 17 - \ No newline at end of file diff --git a/V2RayGCon/Views/WinForms/FormDownloadCore.zh-CN.resx b/V2RayGCon/Views/WinForms/FormDownloadCore.zh-CN.resx index 953bd5f1..6e48b8bb 100644 --- a/V2RayGCon/Views/WinForms/FormDownloadCore.zh-CN.resx +++ b/V2RayGCon/Views/WinForms/FormDownloadCore.zh-CN.resx @@ -144,16 +144,15 @@ 检查当前v2ray-core版本 - - - 72, 16 - 使用代理 随机选一个HTTP代理来下载v2ray-core + + 来源 + 退出 @@ -175,9 +174,6 @@ - - 161, 12 - 正在查询v2ray-core版本 ... @@ -190,6 +186,9 @@ + + + 可用版本 diff --git a/V2RayGCon/Views/WinForms/FormQRCode.cs b/V2RayGCon/Views/WinForms/FormQRCode.cs index b3480f35..0097a7e3 100644 --- a/V2RayGCon/Views/WinForms/FormQRCode.cs +++ b/V2RayGCon/Views/WinForms/FormQRCode.cs @@ -242,7 +242,7 @@ private void btnSavePic_Click(object sender, EventArgs e) Stream myStream; SaveFileDialog saveFileDialog1 = new SaveFileDialog { - Filter = StrConst.ExtPng, + Filter = VgcApis.Models.Consts.Files.PngExt, FilterIndex = 1, RestoreDirectory = true, }; diff --git a/VgcApis/Models/Consts/Core.cs b/VgcApis/Models/Consts/Core.cs index a896a51a..2d78423a 100644 --- a/VgcApis/Models/Consts/Core.cs +++ b/VgcApis/Models/Consts/Core.cs @@ -4,6 +4,35 @@ namespace VgcApis.Models.Consts { static public class Core { + public static string StatsQueryParamTpl = "api --server=\"127.0.0.1:{0}\" StatsService.GetStats \"name: \"\"\"\"inbound>>>agentin>>>traffic>>>{1}\"\"\"\" reset: true\""; + + public static string V2RayCtlExeFileName = "v2ctl.exe"; + public static string V2RayCoreExeFileName = "v2ray.exe"; + + public static string[] SourceUrls = new string[] + { + @"https://github.com/v2ray/v2ray-core/releases", + @"https://github.com/v2fly/v2ray-core/releases", + }; + + public static int GetIndexBySourceUrl(string url) + { + for (int i = 0; i < SourceUrls.Length; i++) + { + if (SourceUrls[i] == url) + { + return i; + } + } + return -1; + } + + public static string GetSourceUrlByIndex(int index) + { + index = Misc.Utils.Clamp(index, 0, SourceUrls.Length); + return SourceUrls[index]; + } + public static string StdIn = @"stdin:"; public static string ConfigArg = @"config"; diff --git a/VgcApis/Models/Consts/Files.cs b/VgcApis/Models/Consts/Files.cs index 54081d1c..238384a2 100644 --- a/VgcApis/Models/Consts/Files.cs +++ b/VgcApis/Models/Consts/Files.cs @@ -13,6 +13,7 @@ static string GenExtString(string extension, bool appendAllFile = true) return appendAllFile ? $"{e}|{AllExt}" : e; } + public static readonly string PngExt = GenExtString("png"); public static readonly string JsExt = GenExtString("js"); public static readonly string JsonExt = GenExtString("json"); public static readonly string PacExt = GenExtString("pac"); diff --git a/VgcApis/Models/Consts/Patterns.cs b/VgcApis/Models/Consts/Patterns.cs index c6e7dd38..6b11b0b6 100644 --- a/VgcApis/Models/Consts/Patterns.cs +++ b/VgcApis/Models/Consts/Patterns.cs @@ -2,6 +2,8 @@ { public static class Patterns { + public static string V2RayCoreReleaseAssets = @"/v2ray-core/releases/download/(v[\.0-9]+)/v2ray-windows-64.zip"; + public const string GitHubReadmeUrl = @"https://github.com(/[^/]+/[^/]+)/blob(/.*)"; public const string GitHuhFileUrl = @"https://github.com(/[^/]+/[^/]+)/blob(/.*)"; diff --git a/VgcApis/Models/Consts/Webs.cs b/VgcApis/Models/Consts/Webs.cs index 5e69a992..4f01741f 100644 --- a/VgcApis/Models/Consts/Webs.cs +++ b/VgcApis/Models/Consts/Webs.cs @@ -2,6 +2,8 @@ { public static class Webs { + public static string Nobody3uVideoUrl = @"https://www.youtube.com/watch?v=BA7fdSkp8ds"; + readonly static string ChromeUserAgent = @"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"; public readonly static string UserAgent = $"User-Agent: {ChromeUserAgent}"; From a526da770243266313634db6b011c6208c778ce3 Mon Sep 17 00:00:00 2001 From: nobody Date: Mon, 8 Jun 2020 02:01:31 +0800 Subject: [PATCH 04/14] Fix a bug in Misc:RandHex(). --- V2RayGCon/Misc/Utils.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/V2RayGCon/Misc/Utils.cs b/V2RayGCon/Misc/Utils.cs index 163e5509..bdce3c56 100644 --- a/V2RayGCon/Misc/Utils.cs +++ b/V2RayGCon/Misc/Utils.cs @@ -1240,6 +1240,8 @@ public static string SHA256(string randomString) } static readonly object genRandomNumberLocker = new object(); + static Random randHexSource = new Random(); + public static string RandomHex(int length) { // https://stackoverflow.com/questions/1344221/how-can-i-generate-random-alphanumeric-strings-in-c @@ -1248,7 +1250,6 @@ public static string RandomHex(int length) return string.Empty; } - Random random = new Random(); const string chars = "0123456789abcdef"; int charLen = chars.Length; @@ -1258,7 +1259,7 @@ public static string RandomHex(int length) { lock (genRandomNumberLocker) { - rndIndex = random.Next(charLen); + rndIndex = randHexSource.Next(charLen); } sb.Append(chars[rndIndex]); } From 8cab5025db433fcfb45ad94aa9b56108af0344b6 Mon Sep 17 00:00:00 2001 From: nobody Date: Mon, 8 Jun 2020 02:51:07 +0800 Subject: [PATCH 05/14] Switch to VgcApis.Misc.Utils.RandHex(). --- .../Controllers/ConfigerComponent/Quick.cs | 2 +- .../CoreServerComponent/CoreStates.cs | 2 +- V2RayGCon/Misc/Utils.cs | 32 ++----------------- V2RayGCon/Properties/AssemblyInfo.cs | 3 +- V2RayGConTests/Base64Tests.cs | 6 ++-- V2RayGConTests/VeeTests/Ver001ModelTest.cs | 6 ++-- VgcApis/Misc/Utils.cs | 19 ++++++++--- 7 files changed, 26 insertions(+), 44 deletions(-) diff --git a/V2RayGCon/Controllers/ConfigerComponent/Quick.cs b/V2RayGCon/Controllers/ConfigerComponent/Quick.cs index 692b87be..64ef908f 100644 --- a/V2RayGCon/Controllers/ConfigerComponent/Quick.cs +++ b/V2RayGCon/Controllers/ConfigerComponent/Quick.cs @@ -102,7 +102,7 @@ void InsertMTProto(ref JObject config) var user = Misc.Utils.GetKey(mtproto, $"{inbTag}.0.settings.users.0"); if (user != null && user is JObject) { - user["secret"] = Misc.Utils.RandomHex(32); + user["secret"] = VgcApis.Misc.Utils.RandomHex(32); } Misc.Utils.CombineConfigWithRoutingInFront(ref mtproto, config); diff --git a/V2RayGCon/Controllers/CoreServerComponent/CoreStates.cs b/V2RayGCon/Controllers/CoreServerComponent/CoreStates.cs index 49b8ed67..760fd515 100644 --- a/V2RayGCon/Controllers/CoreServerComponent/CoreStates.cs +++ b/V2RayGCon/Controllers/CoreServerComponent/CoreStates.cs @@ -117,7 +117,7 @@ public string GetUid() string newUid; do { - newUid = Misc.Utils.RandomHex(16); + newUid = VgcApis.Misc.Utils.RandomHex(16); } while (uidList.Contains(newUid)); coreInfo.uid = newUid; diff --git a/V2RayGCon/Misc/Utils.cs b/V2RayGCon/Misc/Utils.cs index bdce3c56..0658805b 100644 --- a/V2RayGCon/Misc/Utils.cs +++ b/V2RayGCon/Misc/Utils.cs @@ -1239,37 +1239,11 @@ public static string SHA256(string randomString) return hash.ToString(); } - static readonly object genRandomNumberLocker = new object(); - static Random randHexSource = new Random(); - public static string RandomHex(int length) - { - // https://stackoverflow.com/questions/1344221/how-can-i-generate-random-alphanumeric-strings-in-c - if (length <= 0) - { - return string.Empty; - } + // 懒得改调用处的代码了。 + public static int Clamp(int value, int min, int max) => + VgcApis.Misc.Utils.Clamp(value, min, max); - const string chars = "0123456789abcdef"; - int charLen = chars.Length; - - int rndIndex; - StringBuilder sb = new StringBuilder(""); - for (int i = 0; i < length; i++) - { - lock (genRandomNumberLocker) - { - rndIndex = randHexSource.Next(charLen); - } - sb.Append(chars[rndIndex]); - } - return sb.ToString(); - } - - public static int Clamp(int value, int min, int max) - { - return Math.Max(Math.Min(value, max - 1), min); - } public static int GetIndexIgnoreCase(Dictionary dict, string value) { diff --git a/V2RayGCon/Properties/AssemblyInfo.cs b/V2RayGCon/Properties/AssemblyInfo.cs index 87594d26..68f86433 100644 --- a/V2RayGCon/Properties/AssemblyInfo.cs +++ b/V2RayGCon/Properties/AssemblyInfo.cs @@ -33,10 +33,11 @@ // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0.3")] +[assembly: AssemblyVersion("1.4.0.4")] [assembly: AssemblyFileVersion("1.0.0.0")] /* + * v1.4.0.4 Fix a bug in Misc:RandHex(). * v1.4.0.3 Add v2fly as core update source. * v1.4.0.2 Custom inbounds support. * v1.4.0.1 Fix a bug in v2ray-core updating. diff --git a/V2RayGConTests/Base64Tests.cs b/V2RayGConTests/Base64Tests.cs index 9af2a002..83e4c6cc 100644 --- a/V2RayGConTests/Base64Tests.cs +++ b/V2RayGConTests/Base64Tests.cs @@ -1,6 +1,4 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Text; namespace V2RayGCon.Test { @@ -15,9 +13,9 @@ public class Base64Tests @"中123ac文" }; - string GenRandHex() => Misc.Utils.RandomHex(7); + string GenRandHex() => VgcApis.Misc.Utils.RandomHex(7); + - [TestMethod] public void NormalEncodingTest() { diff --git a/V2RayGConTests/VeeTests/Ver001ModelTest.cs b/V2RayGConTests/VeeTests/Ver001ModelTest.cs index b66dfc70..99319da1 100644 --- a/V2RayGConTests/VeeTests/Ver001ModelTest.cs +++ b/V2RayGConTests/VeeTests/Ver001ModelTest.cs @@ -18,9 +18,9 @@ public void Ver001NormalTest() description = "描述abc123", isUseTls = true, streamParam1 = "/v2ray?#abc", - streamParam2 = Misc.Utils.RandomHex(7), - streamParam3 = Misc.Utils.RandomHex(7), - streamType = Misc.Utils.RandomHex(7), + streamParam2 = VgcApis.Misc.Utils.RandomHex(7), + streamParam3 = VgcApis.Misc.Utils.RandomHex(7), + streamType = VgcApis.Misc.Utils.RandomHex(7), port = 123, uuid = Guid.NewGuid(), }; diff --git a/VgcApis/Misc/Utils.cs b/VgcApis/Misc/Utils.cs index fcb049cb..f11c7dc8 100644 --- a/VgcApis/Misc/Utils.cs +++ b/VgcApis/Misc/Utils.cs @@ -1343,6 +1343,7 @@ public static int Clamp(int value, int min, int max) return Math.Max(Math.Min(value, max - 1), min); } + static readonly Random randHexSource = new Random(); public static string RandomHex(int length) { // https://stackoverflow.com/questions/1344221/how-can-i-generate-random-alphanumeric-strings-in-c @@ -1351,12 +1352,20 @@ public static string RandomHex(int length) return string.Empty; } - Random random = new Random(); const string chars = "0123456789abcdef"; - return new string( - Enumerable.Repeat(chars, length) - .Select(s => s[random.Next(s.Length)]) - .ToArray()); + int charLen = chars.Length; + + int rndIndex; + StringBuilder sb = new StringBuilder(""); + lock (randHexSource) + { + for (int i = 0; i < length; i++) + { + rndIndex = randHexSource.Next(charLen); + sb.Append(chars[rndIndex]); + } + } + return sb.ToString(); } #endregion From 70c85efee8497492849bcb7c257c4e498c53ea0b Mon Sep 17 00:00:00 2001 From: nobody Date: Mon, 8 Jun 2020 03:09:47 +0800 Subject: [PATCH 06/14] Add utils.GC(). --- V2RayGCon/Resources/Files/lua/libs/utils.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/V2RayGCon/Resources/Files/lua/libs/utils.lua b/V2RayGCon/Resources/Files/lua/libs/utils.lua index 7279fe40..c1ffe9bc 100644 --- a/V2RayGCon/Resources/Files/lua/libs/utils.lua +++ b/V2RayGCon/Resources/Files/lua/libs/utils.lua @@ -90,6 +90,14 @@ end -- utils +function u.GC() + local prev = collectgarbage("count") + collectgarbage("collect") + local cur = math.floor(collectgarbage("count")) + local diff = math.floor(prev - cur) + print("Mem stat: collected ", diff, " KiB current ", cur, " KiB") +end + function u.ToNumber(str) return ToNumber(str) end From 2479d5af301b005a080c8e034a93671338097e9b Mon Sep 17 00:00:00 2001 From: nobody Date: Mon, 8 Jun 2020 21:21:24 +0800 Subject: [PATCH 07/14] Create menu items on demand. --- README.md | 3 +- .../ConfigerComponent/MenuUpdater.cs | 122 +++++++++--------- V2RayGCon/Controllers/FormConfigerCtrl.cs | 3 +- V2RayGCon/Properties/AssemblyInfo.cs | 3 +- .../Resources/Files/lua/libs/COPYING.txt | 27 ++++ V2RayGCon/Services/Notifier.cs | 34 +++-- V2RayGCon/Views/WinForms/FormConfiger.cs | 12 -- V2RayGCon/Views/WinForms/FormOption.resx | 4 +- VgcApis/Models/Consts/Intervals.cs | 1 - VgcApis/Models/Consts/Webs.cs | 2 +- 10 files changed, 121 insertions(+), 90 deletions(-) create mode 100644 V2RayGCon/Resources/Files/lua/libs/COPYING.txt diff --git a/README.md b/README.md index e02903ad..2daa0471 100644 --- a/README.md +++ b/README.md @@ -41,4 +41,5 @@ Require .net framework 4.5+. [rxi/json.lua](https://github.com/rxi/json.lua) Luna插件中的json解释器 [shadowsocksr-backup/shadowsocksr-csharp](https://github.com/shadowsocksr-backup/shadowsocksr-csharp) 屏幕扫码实现代码 [txthinking/blackwhite](https://github.com/txthinking/blackwhite) ProxySetter插件中的默认PAC -[v2ray/v2ray-core](https://github.com/v2ray/v2ray-core) v2ray-core服务端 \ No newline at end of file +[v2ray/v2ray-core](https://github.com/v2ray/v2ray-core) v2ray-core服务端 +[wilhelmy/lua-bencode](https://bitbucket.org/wilhelmy/lua-bencode) bencode(torrent)解释器 \ No newline at end of file diff --git a/V2RayGCon/Controllers/ConfigerComponent/MenuUpdater.cs b/V2RayGCon/Controllers/ConfigerComponent/MenuUpdater.cs index 230b4d27..f78b1c79 100644 --- a/V2RayGCon/Controllers/ConfigerComponent/MenuUpdater.cs +++ b/V2RayGCon/Controllers/ConfigerComponent/MenuUpdater.cs @@ -12,96 +12,99 @@ class MenuUpdater : ConfigerComponentController Views.WinForms.FormConfiger formConfiger; ToolStripMenuItem miReplaceServer, miLoadServer; - VgcApis.Libs.Tasks.LazyGuy lazyServerMenuItemsUpdater; - public MenuUpdater( Views.WinForms.FormConfiger formConfiger, ToolStripMenuItem miReplaceServer, ToolStripMenuItem miLoadServer) { servers = Services.Servers.Instance; - this.formConfiger = formConfiger; this.miReplaceServer = miReplaceServer; this.miLoadServer = miLoadServer; - lazyServerMenuItemsUpdater = new VgcApis.Libs.Tasks.LazyGuy( - ServerMenuItemsUpdateWorker, - VgcApis.Models.Consts.Intervals.FormConfigerMenuUpdateDelay, - 1500) + VgcApis.Misc.Utils.RunInBackground(() => { - Name = "Vgc.Configer.MenuUpdater", - }; + VgcApis.Misc.Utils.Sleep(2000); + ServerMenuItemsUpdateWorker(); + }); + } #region properties #endregion #region private method - void ServerMenuItemsUpdateWorker() + List CollectServNameAndConfig() { - var loadServMiList = new List(); - var replaceServMiList = new List(); - - try + var serverList = servers.GetAllServersOrderByIndex(); + var servInfos = new List(); + for (int i = 0; i < serverList.Count; i++) { - var serverList = servers.GetAllServersOrderByIndex(); - + var coreServ = serverList[i]; + var coreState = coreServ.GetCoreStates(); + var name = string.Format( + "{0}.{1}", + coreState.GetIndex(), + coreState.GetLongName()); - for (int i = 0; i < serverList.Count; i++) - { - var coreServ = serverList[i]; - var coreState = coreServ.GetCoreStates(); - - var name = string.Format( - "{0}.{1}", - coreState.GetIndex(), - coreState.GetLongName()); - - - var org = coreServ.GetConfiger().GetConfig(); - loadServMiList.Add(GenMenuItemLoad(name, org)); - replaceServMiList.Add(GenMenuItemReplace(name, org)); - } - } - catch - { - return; + var org = coreServ.GetConfiger().GetConfig(); + servInfos.Add(new string[] { name, org }); } - - VgcApis.Misc.UI.Invoke( - () => ReplaceOldMenus(loadServMiList, replaceServMiList)); + return servInfos; } - private void ReplaceOldMenus( - List loadServMiList, - List replaceServMiList) + void ServerMenuItemsUpdateWorker() { - var miRootReplace = miReplaceServer.DropDownItems; - var miRootLoad = miLoadServer.DropDownItems; + // step 1 bg + var servInfos = CollectServNameAndConfig(); - miRootReplace.Clear(); - miRootLoad.Clear(); + // step 2 ui + VgcApis.Misc.UI.Invoke(() => + { + var miRootReplace = miReplaceServer.DropDownItems; + var miRootLoad = miLoadServer.DropDownItems; + miRootReplace.Clear(); + miRootLoad.Clear(); + }); - if (loadServMiList.Count <= 0) + if (servInfos.Count <= 0) { - miReplaceServer.Enabled = false; - miLoadServer.Enabled = false; + VgcApis.Misc.UI.Invoke(() => + { + miReplaceServer.Enabled = false; + miLoadServer.Enabled = false; + }); return; } - var groupSize = VgcApis.Models.Consts.Config.MenuItemGroupSize; - var groupedMiLoad = VgcApis.Misc.UI.AutoGroupMenuItems( - loadServMiList, groupSize); - var groupedMiReplace = VgcApis.Misc.UI.AutoGroupMenuItems( - replaceServMiList, groupSize); + // step 3 ui + var loadServMiList = new List(); + var replaceServMiList = new List(); + VgcApis.Misc.UI.Invoke(() => + { + foreach (var si in servInfos) + { + loadServMiList.Add(GenMenuItemLoad(si[0], si[1])); + replaceServMiList.Add(GenMenuItemReplace(si[0], si[1])); + } + }); - miRootLoad.AddRange(groupedMiLoad.ToArray()); - miRootReplace.AddRange(groupedMiReplace.ToArray()); + // step 4 bg + var groupSize = VgcApis.Models.Consts.Config.MenuItemGroupSize; + var groupedMiLoad = VgcApis.Misc.UI.AutoGroupMenuItems(loadServMiList, groupSize); + var groupedMiReplace = VgcApis.Misc.UI.AutoGroupMenuItems(replaceServMiList, groupSize); - miLoadServer.Enabled = true; - miReplaceServer.Enabled = true; + // step 5 ui + VgcApis.Misc.UI.Invoke(() => + { + var miRootReplace = miReplaceServer.DropDownItems; + var miRootLoad = miLoadServer.DropDownItems; + miRootLoad.AddRange(groupedMiLoad.ToArray()); + miRootReplace.AddRange(groupedMiReplace.ToArray()); + miLoadServer.Enabled = true; + miReplaceServer.Enabled = true; + }); } private ToolStripMenuItem GenMenuItemLoad(string name, string orgConfig) @@ -142,11 +145,8 @@ private ToolStripMenuItem GenMenuItemReplace(string name, string orgConfig) #region public method public void Cleanup() { - lazyServerMenuItemsUpdater?.Dispose(); - } - public void UpdateMenusLater() => - lazyServerMenuItemsUpdater?.Deadline(); + } public override void Update(JObject config) { } #endregion diff --git a/V2RayGCon/Controllers/FormConfigerCtrl.cs b/V2RayGCon/Controllers/FormConfigerCtrl.cs index c3843847..a369eb85 100644 --- a/V2RayGCon/Controllers/FormConfigerCtrl.cs +++ b/V2RayGCon/Controllers/FormConfigerCtrl.cs @@ -24,8 +24,7 @@ public FormConfigerCtrl(string originalConfig) } #region public method - public void UpdateServerMenusLater() => - GetComponent()?.UpdateMenusLater(); + public void Cleanup() { diff --git a/V2RayGCon/Properties/AssemblyInfo.cs b/V2RayGCon/Properties/AssemblyInfo.cs index 68f86433..bdd7438b 100644 --- a/V2RayGCon/Properties/AssemblyInfo.cs +++ b/V2RayGCon/Properties/AssemblyInfo.cs @@ -33,10 +33,11 @@ // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0.4")] +[assembly: AssemblyVersion("1.4.0.5")] [assembly: AssemblyFileVersion("1.0.0.0")] /* + * v1.4.0.5 Create menu items on demand. * v1.4.0.4 Fix a bug in Misc:RandHex(). * v1.4.0.3 Add v2fly as core update source. * v1.4.0.2 Custom inbounds support. diff --git a/V2RayGCon/Resources/Files/lua/libs/COPYING.txt b/V2RayGCon/Resources/Files/lua/libs/COPYING.txt new file mode 100644 index 00000000..841be480 --- /dev/null +++ b/V2RayGCon/Resources/Files/lua/libs/COPYING.txt @@ -0,0 +1,27 @@ +All files in the source distribution of lua-bencode may be copied under the +same terms as Lua 5.0, 5.1, and 5.2. These terms are also known as the "MIT/X +Consortium License". + +For reasons of clarity, a copy of these terms is included below. + +Copyright (c) 2009, 2010, 2011, 2012, 2014, 2016 by Moritz Wilhelmy +Copyright (c) 2012, 2014 by Jorge Visca +Copyright (c) 2009 by Kristofer Karlsson + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/V2RayGCon/Services/Notifier.cs b/V2RayGCon/Services/Notifier.cs index add9015f..d3eca93a 100644 --- a/V2RayGCon/Services/Notifier.cs +++ b/V2RayGCon/Services/Notifier.cs @@ -26,7 +26,6 @@ public class Notifier : static readonly int UpdateInterval = VgcApis.Models.Consts.Intervals.NotifierMenuUpdateIntreval; Bitmap orgIcon; - bool isMenuOpened = false; VgcApis.Libs.Tasks.LazyGuy lazyNotifierMenuUpdater; @@ -91,6 +90,7 @@ public void Run( BindServerEvents(); RefreshNotifyIconLater(); + NotifyIconMenuOpenHandler(this, EventArgs.Empty); } #region hotkey window @@ -409,9 +409,6 @@ private void BindNiMenuEvents(NotifyIcon ni) } }; - ni.ContextMenuStrip.Opening += (s, a) => isMenuOpened = true; - ni.ContextMenuStrip.Closed += (s, a) => isMenuOpened = false; - ni.MouseClick += (s, a) => { switch (a.Button) @@ -424,6 +421,17 @@ private void BindNiMenuEvents(NotifyIcon ni) break; } }; + + ni.ContextMenuStrip.Opening += NotifyIconMenuOpenHandler; + } + + void NotifyIconMenuOpenHandler(object sender, EventArgs args) + { + VgcApis.Misc.Utils.RunInBackground(() => + { + VgcApis.Misc.Utils.Sleep(10); + UpdateServersMenuThen(); + }); } private void BindServerEvents() @@ -589,8 +597,17 @@ void ReplaceServersMenuWith( miServersRoot.Visible = true; } - void UpdateServersMenuThen(Action done = null) + VgcApis.Libs.Tasks.Bar serversMenuUpdateBar = new VgcApis.Libs.Tasks.Bar(); + + void UpdateServersMenuThen() { + if (!serversMenuUpdateBar.Install()) + { + return; + } + + Action done = () => serversMenuUpdateBar.Remove(); + var serverList = servers.GetAllServersOrderByIndex(); var num = VgcApis.Models.Consts.Config.QuickSwitchMenuItemNum; var groupSize = VgcApis.Models.Consts.Config.MenuItemGroupSize; @@ -614,7 +631,7 @@ void UpdateNotifyIconWorker(Action done) return; } - if (isMenuOpened || setting.IsScreenLocked()) + if (setting.IsScreenLocked()) { VgcApis.Misc.Utils.RunInBackground(() => { @@ -634,7 +651,6 @@ void UpdateNotifyIconWorker(Action done) done(); }); - Action next = () => UpdateServersMenuThen(finished); try { var list = servers.GetAllServersOrderByIndex() @@ -651,13 +667,13 @@ void UpdateNotifyIconWorker(Action done) org?.Dispose(); } }); - UpdateNotifyIconTextThen(list, next); + UpdateNotifyIconTextThen(list, finished); } catch (Exception e) { VgcApis.Libs.Sys.FileLogger.Error($"Notifier update icon error!\n{e}"); + done(); } - done(); } private Bitmap CreateNotifyIconImage(List coreCtrls) diff --git a/V2RayGCon/Views/WinForms/FormConfiger.cs b/V2RayGCon/Views/WinForms/FormConfiger.cs index b60b59fa..d107c7f5 100644 --- a/V2RayGCon/Views/WinForms/FormConfiger.cs +++ b/V2RayGCon/Views/WinForms/FormConfiger.cs @@ -99,12 +99,8 @@ private void FormConfiger_Load(object sender, EventArgs e) setting.SaveFormRect(this); setting.LazyGC(); }; - - configer.UpdateServerMenusLater(); } - - #region UI event handler private void tboxVMessID_TextChanged(object sender, EventArgs e) { @@ -399,14 +395,10 @@ void InitToolsPanel() #region private method private void ReleaseServerEvents() { - servers.OnServerCountChange -= MenuUpdateHandler; - servers.OnServerPropertyChange -= MenuUpdateHandler; } private void BindServerEvents() { - servers.OnServerCountChange += MenuUpdateHandler; - servers.OnServerPropertyChange += MenuUpdateHandler; } public void SetTitle(string name) @@ -455,10 +447,6 @@ void ToggleToolsPanel(bool visible) isShowPanel = visible; } - void MenuUpdateHandler(object sender, EventArgs args) - { - configer.UpdateServerMenusLater(); - } void OnMouseEnterToolsPanel(object sender, EventArgs e) { diff --git a/V2RayGCon/Views/WinForms/FormOption.resx b/V2RayGCon/Views/WinForms/FormOption.resx index 7ab14bca..62e2eff7 100644 --- a/V2RayGCon/Views/WinForms/FormOption.resx +++ b/V2RayGCon/Views/WinForms/FormOption.resx @@ -1249,7 +1249,7 @@ ForcedVertical - 428, 109 + 434, 167 1 @@ -1276,7 +1276,7 @@ 13, 164 - 449, 140 + 449, 198 8 diff --git a/VgcApis/Models/Consts/Intervals.cs b/VgcApis/Models/Consts/Intervals.cs index d5fd0b08..a2cf2944 100644 --- a/VgcApis/Models/Consts/Intervals.cs +++ b/VgcApis/Models/Consts/Intervals.cs @@ -19,7 +19,6 @@ static public class Intervals public const int SiFormLogRefreshInterval = 500; public const int LuaPluginLogRefreshInterval = 500; - public const int FormConfigerMenuUpdateDelay = 1500; public const int FormQrcodeMenuUpdateDelay = 1000; } } diff --git a/VgcApis/Models/Consts/Webs.cs b/VgcApis/Models/Consts/Webs.cs index 4f01741f..51e8f21a 100644 --- a/VgcApis/Models/Consts/Webs.cs +++ b/VgcApis/Models/Consts/Webs.cs @@ -13,7 +13,7 @@ public static class Webs @"https://github.com/vrnobody/V2RayGCon/releases/download/{0}/V2RayGCon.zip"; public static string LoopBackIP = System.Net.IPAddress.Loopback.ToString(); - public static int DefaultProxyPort = 8080; + public static int DefaultProxyPort = 18080; public const string FakeRequestUrl = @"http://localhost:3000/pac/?&t=abc1234"; public const string GoogleDotCom = @"https://www.google.com"; From 2b831a4f53605899fa4f60b5ede3a038b5d9e390 Mon Sep 17 00:00:00 2001 From: nobody Date: Tue, 9 Jun 2020 01:45:05 +0800 Subject: [PATCH 08/14] Try to fix a dead lock. --- Plugins/Luna/Models/Apis/Components/Server.cs | 11 ++-- .../CoreServerComponent/Configer.cs | 38 ++++++-------- .../CoreServerComponent/CoreStates.cs | 2 +- V2RayGCon/Controllers/CoreServerCtrl.cs | 14 ++--- .../FormMainComponent/MenuItemsServer.cs | 3 +- V2RayGCon/Properties/AssemblyInfo.cs | 3 +- V2RayGCon/Services/Servers.cs | 52 +++++-------------- V2RayGCon/Services/ShareLinkMgr.cs | 3 +- .../CoreCtrlComponents/IConfiger.cs | 2 +- .../Interfaces/Services/IServersService.cs | 4 +- VgcApis/Libs/Tasks/LazyGuy.cs | 1 + 11 files changed, 47 insertions(+), 86 deletions(-) diff --git a/Plugins/Luna/Models/Apis/Components/Server.cs b/Plugins/Luna/Models/Apis/Components/Server.cs index a07ffce8..6e004deb 100644 --- a/Plugins/Luna/Models/Apis/Components/Server.cs +++ b/Plugins/Luna/Models/Apis/Components/Server.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using System.Threading; namespace Luna.Models.Apis.Components { @@ -19,7 +18,7 @@ public Server( } public void UpdateAllSummary() => - vgcServers.UpdateAllServersSummarySync(); + vgcServers.UpdateAllServersSummary(); public void ResetIndexes() => vgcServers.ResetIndexQuiet(); @@ -46,12 +45,8 @@ public void SortSelectedServersBySummary() => public void SortSelectedServersBySpeedTest() => vgcServers.SortSelectedBySpeedTest(); - public void StopAllServers() - { - var evDone = new AutoResetEvent(false); - vgcServers.StopAllServersThen(() => evDone.Set()); - evDone.WaitOne(); - } + public void StopAllServers() => + vgcServers.StopAllServers(); public bool RunSpeedTestOnSelectedServers() => vgcServers.RunSpeedTestOnSelectedServers(); diff --git a/V2RayGCon/Controllers/CoreServerComponent/Configer.cs b/V2RayGCon/Controllers/CoreServerComponent/Configer.cs index 31799d3f..dd441520 100644 --- a/V2RayGCon/Controllers/CoreServerComponent/Configer.cs +++ b/V2RayGCon/Controllers/CoreServerComponent/Configer.cs @@ -67,32 +67,27 @@ public JObject GetFinalConfig() public string GetConfig() => coreInfo.config; - public void UpdateSummaryThen(Action next = null) + public void UpdateSummary() { - VgcApis.Misc.Utils.RunInBackground(() => + try { var configString = coreInfo.isInjectImport ? configMgr.InjectImportTpls(coreInfo.config, false, true) : coreInfo.config; - JObject finalConfig = null; - try - { - finalConfig = JObject.Parse(configString); - finalConfig = configMgr.ParseImport(configString); - } - catch { } + JObject finalConfig = JObject.Parse(configString); + finalConfig = configMgr.ParseImport(configString); + if (finalConfig != null) { + // update summary should not clear status + // this.status = string.Empty; UpdateSummary(finalConfig); } - - // update summary should not clear status - // this.status = string.Empty; - GetParent().InvokeEventOnPropertyChange(); - next?.Invoke(); - }); + } + catch { } + GetParent().InvokeEventOnPropertyChange(); } public bool IsSuitableToBeUsedAsSysProxy( @@ -130,13 +125,13 @@ public void SetConfig(string newConfig) } coreInfo.config = trimed; - UpdateSummaryThen(() => + UpdateSummary(); + + if (coreCtrl.IsCoreRunning()) { - if (coreCtrl.IsCoreRunning()) - { - coreCtrl.RestartCoreThen(); - } - }); + coreCtrl.RestartCoreThen(); + } + } public void GetterInfoForNotifyIconf(Action next) @@ -211,7 +206,6 @@ void UpdateSummary(JObject config) var name = Misc.Utils.GetAliasFromConfig(config); coreInfo.name = name; coreInfo.summary = Misc.Utils.GetSummaryFromConfig(config); - coreInfo.ClearCachedString(); } diff --git a/V2RayGCon/Controllers/CoreServerComponent/CoreStates.cs b/V2RayGCon/Controllers/CoreServerComponent/CoreStates.cs index 760fd515..d8b6503a 100644 --- a/V2RayGCon/Controllers/CoreServerComponent/CoreStates.cs +++ b/V2RayGCon/Controllers/CoreServerComponent/CoreStates.cs @@ -98,7 +98,7 @@ public void SetIsUntrack(bool isUntrack) => public void SetIsInjectImport(bool IsInjectImport) { SetSettingsPropertyOnDemand(ref coreInfo.isInjectImport, IsInjectImport, true); - configer.UpdateSummaryThen(() => GetParent().InvokeEventOnPropertyChange()); + configer.UpdateSummary(); } public VgcApis.Models.Datas.CoreInfo GetAllRawCoreInfo() => coreInfo; diff --git a/V2RayGCon/Controllers/CoreServerCtrl.cs b/V2RayGCon/Controllers/CoreServerCtrl.cs index 7c067f09..df64f615 100644 --- a/V2RayGCon/Controllers/CoreServerCtrl.cs +++ b/V2RayGCon/Controllers/CoreServerCtrl.cs @@ -147,17 +147,11 @@ public void UpdateCoreSettings(CoreServSettings coreServSettings) ci.isInjectImport = cs.isGlobalImport; ci.isInjectSkipCNSite = cs.isBypassCnSite; - - VgcApis.Misc.Utils.RunInBackground(() => + GetConfiger().UpdateSummary(); + if (restartCore && GetCoreCtrl().IsCoreRunning()) { - GetConfiger().UpdateSummaryThen(() => - { - if (restartCore && GetCoreCtrl().IsCoreRunning()) - { - GetCoreCtrl().RestartCore(); - } - }); - }); + GetCoreCtrl().RestartCore(); + } } public ICoreStates GetCoreStates() => states; diff --git a/V2RayGCon/Controllers/FormMainComponent/MenuItemsServer.cs b/V2RayGCon/Controllers/FormMainComponent/MenuItemsServer.cs index 389ff142..aecfc61f 100644 --- a/V2RayGCon/Controllers/FormMainComponent/MenuItemsServer.cs +++ b/V2RayGCon/Controllers/FormMainComponent/MenuItemsServer.cs @@ -172,7 +172,8 @@ private void InitCtrlMisc( refreshSummary.Click += (s, a) => { cache.html.Clear(); - servers.UpdateAllServersSummaryBg(); + VgcApis.Misc.Utils.RunInBackground( + servers.UpdateAllServersSummary); }; deleteAllItems.Click += (s, a) => diff --git a/V2RayGCon/Properties/AssemblyInfo.cs b/V2RayGCon/Properties/AssemblyInfo.cs index bdd7438b..18fbf741 100644 --- a/V2RayGCon/Properties/AssemblyInfo.cs +++ b/V2RayGCon/Properties/AssemblyInfo.cs @@ -33,10 +33,11 @@ // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0.5")] +[assembly: AssemblyVersion("1.4.0.6")] [assembly: AssemblyFileVersion("1.0.0.0")] /* + * v1.4.0.6 Try to fix a dead lock. * v1.4.0.5 Create menu items on demand. * v1.4.0.4 Fix a bug in Misc:RandHex(). * v1.4.0.3 Add v2fly as core update source. diff --git a/V2RayGCon/Services/Servers.cs b/V2RayGCon/Services/Servers.cs index 84aa359d..188e1fe3 100644 --- a/V2RayGCon/Services/Servers.cs +++ b/V2RayGCon/Services/Servers.cs @@ -578,18 +578,14 @@ void worker(int index, Action next) Misc.Utils.ChainActionHelperAsync(servs.Count, worker, finish); } - public void UpdateAllServersSummarySync() + public void UpdateAllServersSummary() { - var list = coreServList; - AutoResetEvent isFinished = new AutoResetEvent(false); - - - void worker(int index, Action next) + var list = coreServList.ToList(); // clone + foreach (var core in list) { - var core = list[index]; - try { + core.GetConfiger().UpdateSummary(); if (core.GetCoreStates().GetLastModifiedUtcTicks() == 0) { var utcTicks = DateTime.UtcNow.Ticks; @@ -597,34 +593,12 @@ void worker(int index, Action next) } } catch { } - - try - { - core.GetConfiger().UpdateSummaryThen(next); - } - catch - { - // skip if something goes wrong - next(); - } - } - - void done() - { - setting.LazyGC(); - lazyServerSettingsRecorder.Deadline(); - RequireFormMainUpdate(); - InvokeEventOnServerPropertyChange(this, EventArgs.Empty); - isFinished.Set(); } - Misc.Utils.ChainActionHelper(list.Count, worker, done); - notifier.BlockingWaitOne(isFinished); - } - - public void UpdateAllServersSummaryBg() - { - VgcApis.Misc.Utils.RunInBackground(() => UpdateAllServersSummarySync()); + RequireFormMainUpdate(); + setting.LazyGC(); + lazyServerSettingsRecorder.Deadline(); + InvokeEventOnServerPropertyChange(this, EventArgs.Empty); } public void DeleteServerByConfig(string config) @@ -716,12 +690,10 @@ public bool AddServer(string config, string mark, bool quiet = false) BindEventsTo(newServer); if (!quiet) { - newServer.GetConfiger().UpdateSummaryThen(() => - { - // UpdateSummaryThen will invoke OnServerPropertyChange. - InvokeEventOnServerCountChange(this, EventArgs.Empty); - RequireFormMainUpdate(); - }); + newServer.GetConfiger().UpdateSummary(); + // UpdateSummaryThen will invoke OnServerPropertyChange. + InvokeEventOnServerCountChange(this, EventArgs.Empty); + RequireFormMainUpdate(); } setting.LazyGC(); lazyServerSettingsRecorder.Deadline(); diff --git a/V2RayGCon/Services/ShareLinkMgr.cs b/V2RayGCon/Services/ShareLinkMgr.cs index e04e9a49..3144601a 100644 --- a/V2RayGCon/Services/ShareLinkMgr.cs +++ b/V2RayGCon/Services/ShareLinkMgr.cs @@ -202,7 +202,8 @@ void ShowImportResults(IEnumerable results) if (IsAddNewServer(list)) { - servers.UpdateAllServersSummaryBg(); + VgcApis.Misc.Utils.RunInBackground( + servers.UpdateAllServersSummary); } VgcApis.Misc.Utils.RunInBackground(() => diff --git a/VgcApis/Interfaces/CoreCtrlComponents/IConfiger.cs b/VgcApis/Interfaces/CoreCtrlComponents/IConfiger.cs index d1571a89..e3bcd7ca 100644 --- a/VgcApis/Interfaces/CoreCtrlComponents/IConfiger.cs +++ b/VgcApis/Interfaces/CoreCtrlComponents/IConfiger.cs @@ -13,7 +13,7 @@ public interface IConfiger bool IsSuitableToBeUsedAsSysProxy(bool isGlobal, out bool isSocks, out int port); - void UpdateSummaryThen(Action next = null); + void UpdateSummary(); void GetterInfoForNotifyIconf(Action next); } diff --git a/VgcApis/Interfaces/Services/IServersService.cs b/VgcApis/Interfaces/Services/IServersService.cs index 5dbb08b5..b07f70c3 100644 --- a/VgcApis/Interfaces/Services/IServersService.cs +++ b/VgcApis/Interfaces/Services/IServersService.cs @@ -25,9 +25,11 @@ public interface IServersService void SortSelectedBySummary(); + void StopAllServers(); + void StopAllServersThen(Action lambda = null); - void UpdateAllServersSummarySync(); + void UpdateAllServersSummary(); string PackSelectedServersIntoV4Package( string orgUid, string pkgName); diff --git a/VgcApis/Libs/Tasks/LazyGuy.cs b/VgcApis/Libs/Tasks/LazyGuy.cs index 68019a8e..a94cea82 100644 --- a/VgcApis/Libs/Tasks/LazyGuy.cs +++ b/VgcApis/Libs/Tasks/LazyGuy.cs @@ -11,6 +11,7 @@ public class LazyGuy : BaseClasses.Disposable private readonly int interval; private readonly long ticks; private readonly int expectedWorkTime; + AutoResetEvent jobToken = new AutoResetEvent(true); AutoResetEvent waitToken = new AutoResetEvent(true); From a918fd242e4d7e72b5cc20aab386219646a00e1e Mon Sep 17 00:00:00 2001 From: nobody Date: Tue, 9 Jun 2020 22:40:21 +0800 Subject: [PATCH 09/14] Refactoring. --- V2RayGCon/Properties/AssemblyInfo.cs | 3 +- V2RayGCon/Services/Notifier.cs | 133 ++++++++++++++++++--------- 2 files changed, 94 insertions(+), 42 deletions(-) diff --git a/V2RayGCon/Properties/AssemblyInfo.cs b/V2RayGCon/Properties/AssemblyInfo.cs index 18fbf741..e42b7e61 100644 --- a/V2RayGCon/Properties/AssemblyInfo.cs +++ b/V2RayGCon/Properties/AssemblyInfo.cs @@ -33,10 +33,11 @@ // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0.6")] +[assembly: AssemblyVersion("1.4.0.7")] [assembly: AssemblyFileVersion("1.0.0.0")] /* + * v1.4.0.7 Refactoring. * v1.4.0.6 Try to fix a dead lock. * v1.4.0.5 Create menu items on demand. * v1.4.0.4 Fix a bug in Misc:RandHex(). diff --git a/V2RayGCon/Services/Notifier.cs b/V2RayGCon/Services/Notifier.cs index d3eca93a..0eee1a4d 100644 --- a/V2RayGCon/Services/Notifier.cs +++ b/V2RayGCon/Services/Notifier.cs @@ -623,6 +623,19 @@ void UpdateServersMenuThen() }, done); } + enum SysTrayIconTypes + { + None = 0, + ProxyDirect = 1, + ProxyPac = 1 << 1, + ProxyGlobal = 1 << 2, + NoServRunning = 1 << 3, + FirstServRunning = 1 << 4, + OthServRunning = 1 << 5, + MultiServRunning = 1 << 6, + } + + SysTrayIconTypes curSysTrayIconType = SysTrayIconTypes.None; void UpdateNotifyIconWorker(Action done) { if (setting.IsClosing()) @@ -657,16 +670,19 @@ void UpdateNotifyIconWorker(Action done) .Where(s => s.GetCoreCtrl().IsCoreRunning()) .ToList(); - Invoke(() => + var iconType = AnalyzeSysTrayIconType(list); + + if (iconType != curSysTrayIconType) { - var icon = CreateNotifyIconImage(list); - if (icon != null) + Invoke(() => { + var icon = GetNotifyIconFromCache(iconType); var org = ni.Icon; ni.Icon = Icon.FromHandle(icon.GetHicon()); org?.Dispose(); - } - }); + }); + curSysTrayIconType = iconType; + } UpdateNotifyIconTextThen(list, finished); } catch (Exception e) @@ -676,21 +692,56 @@ void UpdateNotifyIconWorker(Action done) } } - private Bitmap CreateNotifyIconImage(List coreCtrls) + SysTrayIconTypes AnalyzeSysTrayIconType(List coreCtrls) { - var activeServNum = coreCtrls.Count; - var isFirstServ = false; + var r = SysTrayIconTypes.None; - if (activeServNum == 1) + // corner mark + switch (coreCtrls.Count) { - var idx = coreCtrls.First().GetCoreStates().GetIndex(); - if ((int)idx == 1) - { - isFirstServ = true; - } + case 0: + r |= SysTrayIconTypes.NoServRunning; + break; + case 1: + var idx = coreCtrls.First().GetCoreStates().GetIndex(); + r |= (idx == 1 ? SysTrayIconTypes.FirstServRunning : SysTrayIconTypes.OthServRunning); + break; + default: + r |= SysTrayIconTypes.MultiServRunning; + break; + } + + // proxy type + switch (ProxySetter.Libs.Sys.WinInet.GetProxySettings().proxyMode) + { + case (int)ProxySetter.Libs.Sys.WinInet.ProxyModes.PAC: + r |= SysTrayIconTypes.ProxyPac; + break; + case (int)ProxySetter.Libs.Sys.WinInet.ProxyModes.Proxy: + r |= SysTrayIconTypes.ProxyGlobal; + break; + default: + r |= SysTrayIconTypes.ProxyDirect; + break; } - var icon = orgIcon.Clone() as Bitmap; + return r; + } + + ConcurrentDictionary sysTrayIconCache = new ConcurrentDictionary(); + Bitmap GetNotifyIconFromCache(SysTrayIconTypes iconType) + { + if (!sysTrayIconCache.TryGetValue(iconType, out var icon)) + { + icon = CreateNotifyIconImage(iconType); + sysTrayIconCache.TryAdd(iconType, icon); + } + return icon.Clone() as Bitmap; + } + + private Bitmap CreateNotifyIconImage(SysTrayIconTypes iconType) + { + var icon = new Bitmap(orgIcon); var size = icon.Size; using (Graphics g = Graphics.FromImage(icon)) @@ -698,29 +749,25 @@ private Bitmap CreateNotifyIconImage(List coreCtrls) g.InterpolationMode = InterpolationMode.High; g.CompositingQuality = CompositingQuality.HighQuality; - DrawProxyModeCornerCircle(g, size); - DrawIsRunningCornerMark(g, size, activeServNum, isFirstServ); + DrawProxyModeCornerCircle(g, size, iconType); + DrawIsRunningCornerMark(g, size, iconType); } return icon; } void DrawProxyModeCornerCircle( - Graphics graphics, Size size) + Graphics graphics, Size size, SysTrayIconTypes iconType) { - Brush br; + Brush br = Brushes.ForestGreen; - switch (ProxySetter.Libs.Sys.WinInet.GetProxySettings().proxyMode) + if (0 != (iconType & SysTrayIconTypes.ProxyPac)) { - case (int)ProxySetter.Libs.Sys.WinInet.ProxyModes.PAC: - br = Brushes.DeepPink; - break; - case (int)ProxySetter.Libs.Sys.WinInet.ProxyModes.Proxy: - br = Brushes.Blue; - break; - default: - br = Brushes.ForestGreen; - break; + br = Brushes.DeepPink; + } + else if (0 != (iconType & SysTrayIconTypes.ProxyGlobal)) + { + br = Brushes.Blue; } var w = size.Width; @@ -730,23 +777,27 @@ void DrawProxyModeCornerCircle( } private void DrawIsRunningCornerMark( - Graphics graphics, Size size, int activeServNum, bool isFirstServ) + Graphics graphics, Size size, SysTrayIconTypes iconType) { var w = size.Width; var cx = w * 0.7f; - switch (activeServNum) + if (0 != (iconType & SysTrayIconTypes.FirstServRunning)) { - case 0: - DrawOneLine(graphics, w, cx, false); - break; - case 1: - DrawTriangle(graphics, w, cx, isFirstServ); - break; - default: - DrawOneLine(graphics, w, cx, false); - DrawOneLine(graphics, w, cx, true); - break; + DrawTriangle(graphics, w, cx, true); + } + else if (0 != (iconType & SysTrayIconTypes.OthServRunning)) + { + DrawTriangle(graphics, w, cx, false); + } + else if (0 != (iconType & SysTrayIconTypes.MultiServRunning)) + { + DrawOneLine(graphics, w, cx, false); + DrawOneLine(graphics, w, cx, true); + } + else + { + DrawOneLine(graphics, w, cx, false); } } From 661f466b9d194878d193c1038fbe26de287a0034 Mon Sep 17 00:00:00 2001 From: nobody Date: Tue, 9 Jun 2020 23:03:26 +0800 Subject: [PATCH 10/14] Keep current selections in searching. --- V2RayGCon/Controllers/FormMainComponent/FlyServer.cs | 4 ++-- V2RayGCon/Properties/AssemblyInfo.cs | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/V2RayGCon/Controllers/FormMainComponent/FlyServer.cs b/V2RayGCon/Controllers/FormMainComponent/FlyServer.cs index 8ad38ebc..10295bf7 100644 --- a/V2RayGCon/Controllers/FormMainComponent/FlyServer.cs +++ b/V2RayGCon/Controllers/FormMainComponent/FlyServer.cs @@ -353,8 +353,8 @@ void ShowSearchResultNow() // 如果不RemoveAll会乱序 RemoveAllServersConrol(); - // 修改搜索项时应该清除选择,否则会有可显示列表外的选中项 - servers.SetAllServerIsSelected(false); + // 2020-06-09 改为保留选中状态 + // servers.SetAllServerIsSelected(false); lazyFlyPanelUpdater?.Postpone(); } diff --git a/V2RayGCon/Properties/AssemblyInfo.cs b/V2RayGCon/Properties/AssemblyInfo.cs index e42b7e61..5d28368e 100644 --- a/V2RayGCon/Properties/AssemblyInfo.cs +++ b/V2RayGCon/Properties/AssemblyInfo.cs @@ -33,10 +33,11 @@ // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0.7")] +[assembly: AssemblyVersion("1.4.0.8")] [assembly: AssemblyFileVersion("1.0.0.0")] /* + * v1.4.0.8 Keep current selections in searching. * v1.4.0.7 Refactoring. * v1.4.0.6 Try to fix a dead lock. * v1.4.0.5 Create menu items on demand. From 2654a5dfb4a415a1fed5a80b36c7abdda49dfd38 Mon Sep 17 00:00:00 2001 From: nobody Date: Wed, 10 Jun 2020 14:09:33 +0800 Subject: [PATCH 11/14] Remove HtmlAgilityPack. --- Plugins/Luna/Luna.csproj | 10 ++++---- Plugins/Luna/Models/Apis/Components/Web.cs | 3 --- Plugins/Luna/app.config | 8 ++++++ Plugins/Luna/packages.config | 6 ++--- .../ProxySetterTests/ProxySetterTests.csproj | 12 ++++----- Plugins/ProxySetterTests/app.config | 8 +++--- Plugins/ProxySetterTests/packages.config | 4 +-- README.md | 1 - V2RayGCon/Libs/Lua/ApiComponents/WebApi.cs | 2 -- V2RayGCon/Misc/Utils.cs | 25 ------------------- V2RayGCon/Properties/AssemblyInfo.cs | 3 ++- V2RayGCon/V2RayGCon.csproj | 19 ++++++-------- V2RayGCon/app.config | 8 ++++++ V2RayGCon/packages.config | 9 +++---- V2RayGConTests/LibTest.cs | 10 +------- V2RayGConTests/V2RayGConTests.csproj | 15 +++++------ V2RayGConTests/app.config | 8 ++++++ V2RayGConTests/packages.config | 5 ++-- VgcApis/Interfaces/Lua/ILuaWeb.cs | 2 -- VgcApis/Interfaces/Services/IWebService.cs | 2 +- VgcApisTests/VgcApisTests.csproj | 12 ++++----- VgcApisTests/app.config | 8 +++--- VgcApisTests/packages.config | 4 +-- 23 files changed, 80 insertions(+), 104 deletions(-) diff --git a/Plugins/Luna/Luna.csproj b/Plugins/Luna/Luna.csproj index 7377ace0..1b4586ab 100644 --- a/Plugins/Luna/Luna.csproj +++ b/Plugins/Luna/Luna.csproj @@ -40,7 +40,7 @@ ..\..\packages\AutoCompleteMenu-ScintillaNET.1.6.1\lib\net40\AutocompleteMenu-ScintillaNET.dll - ..\..\packages\Castle.Core.4.4.0\lib\net45\Castle.Core.dll + ..\..\packages\Castle.Core.4.4.1\lib\net45\Castle.Core.dll ..\..\packages\KeraLua.1.0.26\lib\net45\KeraLua.dll @@ -61,11 +61,11 @@ - - ..\..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll + + ..\..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll - - ..\..\packages\System.Threading.Tasks.Extensions.4.5.1\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll + + ..\..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll diff --git a/Plugins/Luna/Models/Apis/Components/Web.cs b/Plugins/Luna/Models/Apis/Components/Web.cs index f2336282..420d2382 100644 --- a/Plugins/Luna/Models/Apis/Components/Web.cs +++ b/Plugins/Luna/Models/Apis/Components/Web.cs @@ -116,9 +116,6 @@ public string Search(string keywords, int first, int proxyPort) => public string PatchHref(string url, string href) => vgcWeb.PatchHref(url, href); - public List FindAllHrefs(string text) => - vgcWeb.FindAllHrefs(text); - #endregion diff --git a/Plugins/Luna/app.config b/Plugins/Luna/app.config index 48820ce0..eaaff819 100644 --- a/Plugins/Luna/app.config +++ b/Plugins/Luna/app.config @@ -6,6 +6,14 @@ + + + + + + + + diff --git a/Plugins/Luna/packages.config b/Plugins/Luna/packages.config index 4f29df1c..e9cfbbf5 100644 --- a/Plugins/Luna/packages.config +++ b/Plugins/Luna/packages.config @@ -1,12 +1,12 @@  - + - - + + \ No newline at end of file diff --git a/Plugins/ProxySetterTests/ProxySetterTests.csproj b/Plugins/ProxySetterTests/ProxySetterTests.csproj index 102c5ffa..905f0121 100644 --- a/Plugins/ProxySetterTests/ProxySetterTests.csproj +++ b/Plugins/ProxySetterTests/ProxySetterTests.csproj @@ -1,6 +1,6 @@  - + Debug @@ -44,10 +44,10 @@ - ..\..\packages\MSTest.TestFramework.2.1.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + ..\..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll - ..\..\packages\MSTest.TestFramework.2.1.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + ..\..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll @@ -79,8 +79,8 @@ 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 - - + + - + \ No newline at end of file diff --git a/Plugins/ProxySetterTests/app.config b/Plugins/ProxySetterTests/app.config index 55d1d7ae..48820ce0 100644 --- a/Plugins/ProxySetterTests/app.config +++ b/Plugins/ProxySetterTests/app.config @@ -1,11 +1,11 @@ - + - - + + - + diff --git a/Plugins/ProxySetterTests/packages.config b/Plugins/ProxySetterTests/packages.config index 7b9ccb7c..d5750748 100644 --- a/Plugins/ProxySetterTests/packages.config +++ b/Plugins/ProxySetterTests/packages.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file diff --git a/README.md b/README.md index 2daa0471..94247867 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,6 @@ Require .net framework 4.5+. [diegonehab/luasocket](https://github.com/diegonehab/luasocket.git) Lua socket [FourierTransformer/lua-complete](https://github.com/FourierTransformer/lua-complete.git) lua模块补全 [haf/DotNetZip.Semverd](https://github.com/haf/DotNetZip.Semverd) .net 4.0解压zip文件 -[HtmlAgilityPack](https://html-agility-pack.net/) HTML解释器 [jacobslusser/ScintillaNET](https://github.com/jacobslusser/ScintillaNET) 编辑器 [JamesNK/Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) 处理json [micjahn/ZXing.Net](https://github.com/micjahn/ZXing.Net/) 处理二维码 diff --git a/V2RayGCon/Libs/Lua/ApiComponents/WebApi.cs b/V2RayGCon/Libs/Lua/ApiComponents/WebApi.cs index bf45f810..1e352dd0 100644 --- a/V2RayGCon/Libs/Lua/ApiComponents/WebApi.cs +++ b/V2RayGCon/Libs/Lua/ApiComponents/WebApi.cs @@ -9,8 +9,6 @@ public sealed class WebApi : public string PatchHref(string url, string href) => Misc.Utils.PatchHref(url, href); - public List FindAllHrefs(string text) => - Misc.Utils.FindAllHrefs(text); public List ExtractLinks( string text, diff --git a/V2RayGCon/Misc/Utils.cs b/V2RayGCon/Misc/Utils.cs index 0658805b..e81dc0b7 100644 --- a/V2RayGCon/Misc/Utils.cs +++ b/V2RayGCon/Misc/Utils.cs @@ -969,31 +969,6 @@ public static string PatchHref(string url, string href) return baseUrl + href; } - public static List FindAllHrefs(string text) - { - var empty = new List(); - - if (string.IsNullOrEmpty(text)) - { - return empty; - } - - try - { - HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); - doc.LoadHtml(text); - - var result = doc.DocumentNode.SelectNodes("//a") - ?.Select(p => p.GetAttributeValue("href", "")) - ?.Where(s => !string.IsNullOrEmpty(s)) - ?.ToList(); - - return result ?? empty; - } - catch { } - return empty; - } - public static string GenSearchUrl(string query, int start) { var url = VgcApis.Models.Consts.Webs.SearchUrlPrefix + UrlEncode(query); diff --git a/V2RayGCon/Properties/AssemblyInfo.cs b/V2RayGCon/Properties/AssemblyInfo.cs index 5d28368e..1751a804 100644 --- a/V2RayGCon/Properties/AssemblyInfo.cs +++ b/V2RayGCon/Properties/AssemblyInfo.cs @@ -36,7 +36,8 @@ [assembly: AssemblyVersion("1.4.0.8")] [assembly: AssemblyFileVersion("1.0.0.0")] -/* +/* + * v1.4.0.9 Remove HtmlAgilityPack. * v1.4.0.8 Keep current selections in searching. * v1.4.0.7 Refactoring. * v1.4.0.6 Try to fix a dead lock. diff --git a/V2RayGCon/V2RayGCon.csproj b/V2RayGCon/V2RayGCon.csproj index 42984cf5..a79b51ef 100644 --- a/V2RayGCon/V2RayGCon.csproj +++ b/V2RayGCon/V2RayGCon.csproj @@ -92,13 +92,10 @@ ..\packages\Autoupdater.NET.Official.1.5.8\lib\net40\AutoUpdater.NET.dll - ..\packages\Castle.Core.4.4.0\lib\net45\Castle.Core.dll + ..\packages\Castle.Core.4.4.1\lib\net45\Castle.Core.dll - - ..\packages\DotNetZip.1.13.5\lib\net40\DotNetZip.dll - - - ..\packages\HtmlAgilityPack.1.11.18\lib\Net45\HtmlAgilityPack.dll + + ..\packages\DotNetZip.1.13.8\lib\net40\DotNetZip.dll ..\packages\KeraLua.1.0.26\lib\net45\KeraLua.dll @@ -119,11 +116,11 @@ - - ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll + + ..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll - - ..\packages\System.Threading.Tasks.Extensions.4.5.1\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll @@ -587,7 +584,7 @@ set "libsDir=libs\" set "copyFolderList=lua templates" -set "allDlls=KeraLua liblua53 lua53 Nlua AutocompleteMenu-ScintillaNET Luna ProxySetter Statistics Pacman HtmlAgilityPack DotNetZip Newtonsoft ScintillaNET VgcApis zxing AutoUpdater.NET Castle.Core Moq System.Runtime.CompilerServices.Unsafe System.Threading.Tasks.Extensions" +set "allDlls=KeraLua liblua53 lua53 Nlua AutocompleteMenu-ScintillaNET Luna ProxySetter Statistics Pacman DotNetZip Newtonsoft ScintillaNET VgcApis zxing AutoUpdater.NET Castle.Core Moq System.Runtime.CompilerServices.Unsafe System.Threading.Tasks.Extensions" call:CreateFoldersOnDemand "%25libsDir%25 %25copyFolderList%25" call:MoveFilesByList "%25allDlls%25" diff --git a/V2RayGCon/app.config b/V2RayGCon/app.config index b5d2edb0..abd81aaf 100644 --- a/V2RayGCon/app.config +++ b/V2RayGCon/app.config @@ -12,6 +12,14 @@ + + + + + + + + diff --git a/V2RayGCon/packages.config b/V2RayGCon/packages.config index 6d20b8ae..e60c048b 100644 --- a/V2RayGCon/packages.config +++ b/V2RayGCon/packages.config @@ -2,15 +2,14 @@ - - - + + - - + + \ No newline at end of file diff --git a/V2RayGConTests/LibTest.cs b/V2RayGConTests/LibTest.cs index 6ac980b3..63b99a25 100644 --- a/V2RayGConTests/LibTest.cs +++ b/V2RayGConTests/LibTest.cs @@ -313,15 +313,7 @@ public void Str2ListStr() } } - [DataTestMethod] - [DataRow("http://abc.com https://def.com", 0)] - [DataRow(" https://def.com", 1)] - [DataRow(" https://def.com", 1)] - public void FindAllHrefTest(string html, int count) - { - var links = Misc.Utils.FindAllHrefs(html); - Assert.AreEqual(count, links.Count()); - } + [TestMethod] public void ExtractLinks_HttpLink() diff --git a/V2RayGConTests/V2RayGConTests.csproj b/V2RayGConTests/V2RayGConTests.csproj index 694962f5..1686e028 100644 --- a/V2RayGConTests/V2RayGConTests.csproj +++ b/V2RayGConTests/V2RayGConTests.csproj @@ -1,6 +1,6 @@  - + Debug AnyCPU @@ -44,14 +44,11 @@ 7.1 - - ..\packages\HtmlAgilityPack.1.11.18\lib\Net45\HtmlAgilityPack.dll - - ..\packages\MSTest.TestFramework.2.1.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + ..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll - ..\packages\MSTest.TestFramework.2.1.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + ..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll @@ -111,8 +108,8 @@ 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 - - + + - + \ No newline at end of file diff --git a/V2RayGConTests/app.config b/V2RayGConTests/app.config index 48820ce0..eaaff819 100644 --- a/V2RayGConTests/app.config +++ b/V2RayGConTests/app.config @@ -6,6 +6,14 @@ + + + + + + + + diff --git a/V2RayGConTests/packages.config b/V2RayGConTests/packages.config index d0bf778b..393c1878 100644 --- a/V2RayGConTests/packages.config +++ b/V2RayGConTests/packages.config @@ -1,7 +1,6 @@  - - - + + \ No newline at end of file diff --git a/VgcApis/Interfaces/Lua/ILuaWeb.cs b/VgcApis/Interfaces/Lua/ILuaWeb.cs index 850c990d..f6c8def9 100644 --- a/VgcApis/Interfaces/Lua/ILuaWeb.cs +++ b/VgcApis/Interfaces/Lua/ILuaWeb.cs @@ -17,8 +17,6 @@ public interface ILuaWeb bool Download(string url, string filename, int millSeconds); bool Download(string url, string filename, int proxyPort, int millSeconds); - List FindAllHrefs(string text); - // the first running http server's port number int GetProxyPort(); diff --git a/VgcApis/Interfaces/Services/IWebService.cs b/VgcApis/Interfaces/Services/IWebService.cs index 89d69397..db446389 100644 --- a/VgcApis/Interfaces/Services/IWebService.cs +++ b/VgcApis/Interfaces/Services/IWebService.cs @@ -5,7 +5,7 @@ namespace VgcApis.Interfaces.Services public interface IWebService { string PatchHref(string url, string href); - List FindAllHrefs(string text); + List ExtractLinks(string text, Models.Datas.Enums.LinkTypes linkType); string Search(string query, int start, int proxyPort, int timeout); diff --git a/VgcApisTests/VgcApisTests.csproj b/VgcApisTests/VgcApisTests.csproj index 5c643650..9a199f93 100644 --- a/VgcApisTests/VgcApisTests.csproj +++ b/VgcApisTests/VgcApisTests.csproj @@ -1,6 +1,6 @@  - + Debug @@ -44,10 +44,10 @@ - ..\packages\MSTest.TestFramework.2.1.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + ..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll - ..\packages\MSTest.TestFramework.2.1.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + ..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll @@ -86,8 +86,8 @@ 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 - - + + - + \ No newline at end of file diff --git a/VgcApisTests/app.config b/VgcApisTests/app.config index 55d1d7ae..48820ce0 100644 --- a/VgcApisTests/app.config +++ b/VgcApisTests/app.config @@ -1,11 +1,11 @@ - + - - + + - + diff --git a/VgcApisTests/packages.config b/VgcApisTests/packages.config index 034ea1ef..aa2f734f 100644 --- a/VgcApisTests/packages.config +++ b/VgcApisTests/packages.config @@ -1,6 +1,6 @@  - - + + \ No newline at end of file From 7ab1e1a0ad0229a68f8226d8e746bce9d08feace Mon Sep 17 00:00:00 2001 From: nobody Date: Wed, 10 Jun 2020 17:22:51 +0800 Subject: [PATCH 12/14] Print server index in logs. --- .../Controllers/CoreServerComponent/Logger.cs | 2 +- V2RayGCon/Properties/AssemblyInfo.cs | 5 +- V2RayGCon/Views/WinForms/FormLog.Designer.cs | 120 +++++++++++++----- V2RayGCon/Views/WinForms/FormLog.cs | 36 ++++++ V2RayGCon/Views/WinForms/FormLog.resx | 92 +++++++++++++- V2RayGCon/Views/WinForms/FormLog.zh-CN.resx | 12 ++ 6 files changed, 229 insertions(+), 38 deletions(-) diff --git a/V2RayGCon/Controllers/CoreServerComponent/Logger.cs b/V2RayGCon/Controllers/CoreServerComponent/Logger.cs index 01a513d8..9938b7d4 100644 --- a/V2RayGCon/Controllers/CoreServerComponent/Logger.cs +++ b/V2RayGCon/Controllers/CoreServerComponent/Logger.cs @@ -18,7 +18,7 @@ public void Log(string message) qLogger.Log(message); try { - setting.SendLog($"[{coreInfo.GetShortName()}] {message}"); + setting.SendLog($"[{coreInfo.GetIndex()}.{coreInfo.GetShortName()}] {message}"); } catch { } } diff --git a/V2RayGCon/Properties/AssemblyInfo.cs b/V2RayGCon/Properties/AssemblyInfo.cs index 1751a804..29b17857 100644 --- a/V2RayGCon/Properties/AssemblyInfo.cs +++ b/V2RayGCon/Properties/AssemblyInfo.cs @@ -33,10 +33,11 @@ // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0.8")] +[assembly: AssemblyVersion("1.4.0.10")] [assembly: AssemblyFileVersion("1.0.0.0")] -/* +/* + * v1.4.0.10 Print server index in logs. * v1.4.0.9 Remove HtmlAgilityPack. * v1.4.0.8 Keep current selections in searching. * v1.4.0.7 Refactoring. diff --git a/V2RayGCon/Views/WinForms/FormLog.Designer.cs b/V2RayGCon/Views/WinForms/FormLog.Designer.cs index 883ce4f4..57bcdbea 100644 --- a/V2RayGCon/Views/WinForms/FormLog.Designer.cs +++ b/V2RayGCon/Views/WinForms/FormLog.Designer.cs @@ -28,40 +28,98 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormLog)); - this.rtBoxLogger = new VgcApis.UserControls.ExRichTextBox(); - this.panel1 = new System.Windows.Forms.Panel(); - this.panel1.SuspendLayout(); - this.SuspendLayout(); - // - // rtBoxLogger - // - this.rtBoxLogger.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.rtBoxLogger.DetectUrls = false; - resources.ApplyResources(this.rtBoxLogger, "rtBoxLogger"); - this.rtBoxLogger.Name = "rtBoxLogger"; - this.rtBoxLogger.ReadOnly = true; - // - // panel1 - // - this.panel1.Controls.Add(this.rtBoxLogger); - resources.ApplyResources(this.panel1, "panel1"); - this.panel1.Name = "panel1"; - // - // FormLog - // - resources.ApplyResources(this, "$this"); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.panel1); - this.Name = "FormLog"; - this.Load += new System.EventHandler(this.FormLog_Load); - this.panel1.ResumeLayout(false); - this.ResumeLayout(false); - + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormLog)); + this.rtBoxLogger = new VgcApis.UserControls.ExRichTextBox(); + this.panel1 = new System.Windows.Forms.Panel(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.actionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.pauseToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.copyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator(); + this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.panel1.SuspendLayout(); + this.menuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // rtBoxLogger + // + this.rtBoxLogger.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.rtBoxLogger.DetectUrls = false; + resources.ApplyResources(this.rtBoxLogger, "rtBoxLogger"); + this.rtBoxLogger.Name = "rtBoxLogger"; + this.rtBoxLogger.ReadOnly = true; + // + // panel1 + // + this.panel1.Controls.Add(this.rtBoxLogger); + resources.ApplyResources(this.panel1, "panel1"); + this.panel1.Name = "panel1"; + // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.actionToolStripMenuItem}); + resources.ApplyResources(this.menuStrip1, "menuStrip1"); + this.menuStrip1.Name = "menuStrip1"; + // + // actionToolStripMenuItem + // + this.actionToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.copyToolStripMenuItem, + this.pauseToolStripMenuItem, + this.toolStripMenuItem1, + this.exitToolStripMenuItem}); + this.actionToolStripMenuItem.Name = "actionToolStripMenuItem"; + resources.ApplyResources(this.actionToolStripMenuItem, "actionToolStripMenuItem"); + // + // pauseToolStripMenuItem + // + this.pauseToolStripMenuItem.Name = "pauseToolStripMenuItem"; + resources.ApplyResources(this.pauseToolStripMenuItem, "pauseToolStripMenuItem"); + this.pauseToolStripMenuItem.Click += new System.EventHandler(this.pauseToolStripMenuItem_Click); + // + // copyToolStripMenuItem + // + this.copyToolStripMenuItem.Name = "copyToolStripMenuItem"; + resources.ApplyResources(this.copyToolStripMenuItem, "copyToolStripMenuItem"); + this.copyToolStripMenuItem.Click += new System.EventHandler(this.copyToolStripMenuItem_Click); + // + // toolStripMenuItem1 + // + this.toolStripMenuItem1.Name = "toolStripMenuItem1"; + resources.ApplyResources(this.toolStripMenuItem1, "toolStripMenuItem1"); + // + // exitToolStripMenuItem + // + this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; + resources.ApplyResources(this.exitToolStripMenuItem, "exitToolStripMenuItem"); + this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); + // + // FormLog + // + resources.ApplyResources(this, "$this"); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.panel1); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "FormLog"; + this.Load += new System.EventHandler(this.FormLog_Load); + this.panel1.ResumeLayout(false); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion private VgcApis.UserControls.ExRichTextBox rtBoxLogger; - private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.MenuStrip menuStrip1; + private System.Windows.Forms.ToolStripMenuItem actionToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem pauseToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem copyToolStripMenuItem; + private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; } } diff --git a/V2RayGCon/Views/WinForms/FormLog.cs b/V2RayGCon/Views/WinForms/FormLog.cs index bdcdecd5..d9459c26 100644 --- a/V2RayGCon/Views/WinForms/FormLog.cs +++ b/V2RayGCon/Views/WinForms/FormLog.cs @@ -15,6 +15,7 @@ public partial class FormLog : Form Services.Settings setting; VgcApis.UserControls.RepaintController repaintCtrl; + bool isPaused = false; long updateTimeStamp = DateTime.Now.Ticks; Timer updateLogTimer = new Timer { Interval = 500 }; VgcApis.Libs.Tasks.Bar bar = new VgcApis.Libs.Tasks.Bar(); @@ -44,6 +45,7 @@ private void FormLog_Load(object sender, EventArgs e) repaintCtrl = new VgcApis.UserControls.RepaintController(rtBoxLogger); updateLogTimer.Tick += UpdateLog; updateLogTimer.Start(); + SetIsPause(false); // throw new NullReferenceException("for debugging"); } @@ -58,6 +60,11 @@ private void ScrollToBottom() void UpdateLog(object sender, EventArgs args) { + if (isPaused) + { + return; + } + if (!bar.Install()) { return; @@ -85,6 +92,35 @@ void UpdateLog(object sender, EventArgs args) bar.Remove(); } } + + void SetIsPause(bool isPaused) + { + this.isPaused = isPaused; + pauseToolStripMenuItem.Checked = isPaused; + } #endregion + + #region UI events + private void exitToolStripMenuItem_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void pauseToolStripMenuItem_Click(object sender, EventArgs e) + { + SetIsPause(!isPaused); + } + private void copyToolStripMenuItem_Click(object sender, EventArgs e) + { + var logs = setting.GetLogContent(); + var msg = VgcApis.Misc.Utils.CopyToClipboard(logs) ? + Resources.Resx.I18N.CopySuccess : + Resources.Resx.I18N.CopyFail; + VgcApis.Misc.UI.MsgBoxAsync(msg); + } + + #endregion + + } } diff --git a/V2RayGCon/Views/WinForms/FormLog.resx b/V2RayGCon/Views/WinForms/FormLog.resx index 2fd4ddfc..d925eec7 100644 --- a/V2RayGCon/Views/WinForms/FormLog.resx +++ b/V2RayGCon/Views/WinForms/FormLog.resx @@ -129,7 +129,7 @@ Vertical - 667, 321 + 667, 296 @@ -142,7 +142,7 @@ rtBoxLogger - System.Windows.Forms.RichTextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + VgcApis.UserControls.ExRichTextBox, VgcApis, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null panel1 @@ -154,13 +154,13 @@ Fill - 0, 0 + 0, 25 2, 2, 2, 2 - 667, 321 + 667, 296 2 @@ -177,6 +177,60 @@ 0 + + 17, 17 + + + 180, 22 + + + Copy + + + 180, 22 + + + Pause + + + 177, 6 + + + 180, 22 + + + Exit + + + 56, 21 + + + Action + + + 0, 0 + + + 667, 25 + + + 3 + + + menuStrip1 + + + menuStrip1 + + + System.Windows.Forms.MenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + True @@ -192,6 +246,36 @@ Log + + actionToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + pauseToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + copyToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + toolStripMenuItem1 + + + System.Windows.Forms.ToolStripSeparator, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + exitToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + FormLog diff --git a/V2RayGCon/Views/WinForms/FormLog.zh-CN.resx b/V2RayGCon/Views/WinForms/FormLog.zh-CN.resx index f7937080..a581841a 100644 --- a/V2RayGCon/Views/WinForms/FormLog.zh-CN.resx +++ b/V2RayGCon/Views/WinForms/FormLog.zh-CN.resx @@ -117,6 +117,18 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 暂停 + + + 复制 + + + 退出 + + + 操作 + 日志 From 8f52c9eab082f8aa82951051a9cc0068a4433590 Mon Sep 17 00:00:00 2001 From: nobody Date: Thu, 11 Jun 2020 19:47:03 +0800 Subject: [PATCH 13/14] 18080->8080 --- V2RayGCon/Properties/AssemblyInfo.cs | 3 ++- VgcApis/Models/Consts/Webs.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/V2RayGCon/Properties/AssemblyInfo.cs b/V2RayGCon/Properties/AssemblyInfo.cs index 29b17857..fdb93d33 100644 --- a/V2RayGCon/Properties/AssemblyInfo.cs +++ b/V2RayGCon/Properties/AssemblyInfo.cs @@ -33,10 +33,11 @@ // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0.10")] +[assembly: AssemblyVersion("1.4.0.11")] [assembly: AssemblyFileVersion("1.0.0.0")] /* + * v1.4.0.11 18080 -> 8080 * v1.4.0.10 Print server index in logs. * v1.4.0.9 Remove HtmlAgilityPack. * v1.4.0.8 Keep current selections in searching. diff --git a/VgcApis/Models/Consts/Webs.cs b/VgcApis/Models/Consts/Webs.cs index 51e8f21a..4f01741f 100644 --- a/VgcApis/Models/Consts/Webs.cs +++ b/VgcApis/Models/Consts/Webs.cs @@ -13,7 +13,7 @@ public static class Webs @"https://github.com/vrnobody/V2RayGCon/releases/download/{0}/V2RayGCon.zip"; public static string LoopBackIP = System.Net.IPAddress.Loopback.ToString(); - public static int DefaultProxyPort = 18080; + public static int DefaultProxyPort = 8080; public const string FakeRequestUrl = @"http://localhost:3000/pac/?&t=abc1234"; public const string GoogleDotCom = @"https://www.google.com"; From a98a3c5894d063fbae23d27d7cc9deec08796024 Mon Sep 17 00:00:00 2001 From: nobody Date: Fri, 12 Jun 2020 11:28:40 +0800 Subject: [PATCH 14/14] Bump version to v1.4.1.0. --- V2RayGCon/Properties/AssemblyInfo.cs | 3 ++- V2RayGCon/Services/Settings.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/V2RayGCon/Properties/AssemblyInfo.cs b/V2RayGCon/Properties/AssemblyInfo.cs index fdb93d33..5875fcc0 100644 --- a/V2RayGCon/Properties/AssemblyInfo.cs +++ b/V2RayGCon/Properties/AssemblyInfo.cs @@ -33,10 +33,11 @@ // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0.11")] +[assembly: AssemblyVersion("1.4.1.0")] [assembly: AssemblyFileVersion("1.0.0.0")] /* + * ------------------------------------------------ * v1.4.0.11 18080 -> 8080 * v1.4.0.10 Print server index in logs. * v1.4.0.9 Remove HtmlAgilityPack. diff --git a/V2RayGCon/Services/Settings.cs b/V2RayGCon/Services/Settings.cs index 19eadcce..c12ece05 100644 --- a/V2RayGCon/Services/Settings.cs +++ b/V2RayGCon/Services/Settings.cs @@ -462,7 +462,7 @@ public void SaveV2RayCoreVersionList(List versions) public ReadOnlyCollection GetV2RayCoreVersionList() { var result = userSettings.V2RayCoreDownloadVersionList ?? - new List { "v3.48", "v3.47", "v3.46" }; + new List { "v4.23.4", "v4.22.1", "v4.21.3" }; return result.AsReadOnly(); }