From 6c06de63e40e0e882e4a6adaae27eb09c9f3db7a Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Mon, 15 Aug 2022 19:53:38 +0800 Subject: [PATCH] Restore gui config --- v2rayN/v2rayN/Forms/MainForm.Designer.cs | 42 ++- v2rayN/v2rayN/Forms/MainForm.cs | 29 +- v2rayN/v2rayN/Forms/MainForm.resx | 342 +++++++++++---------- v2rayN/v2rayN/Forms/MainForm.zh-Hans.resx | 3 + v2rayN/v2rayN/Handler/MainFormHandler.cs | 40 +++ v2rayN/v2rayN/Handler/StatisticsHandler.cs | 19 +- 6 files changed, 275 insertions(+), 200 deletions(-) diff --git a/v2rayN/v2rayN/Forms/MainForm.Designer.cs b/v2rayN/v2rayN/Forms/MainForm.Designer.cs index 4cad06ba..98c1b436 100644 --- a/v2rayN/v2rayN/Forms/MainForm.Designer.cs +++ b/v2rayN/v2rayN/Forms/MainForm.Designer.cs @@ -42,11 +42,11 @@ this.menuAddServers = new System.Windows.Forms.ToolStripMenuItem(); this.menuScanScreen = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); + this.menuServerFilter = new System.Windows.Forms.ToolStripMenuItem(); this.menuRemoveServer = new System.Windows.Forms.ToolStripMenuItem(); this.menuRemoveDuplicateServer = new System.Windows.Forms.ToolStripMenuItem(); this.menuCopyServer = new System.Windows.Forms.ToolStripMenuItem(); this.menuSetDefaultServer = new System.Windows.Forms.ToolStripMenuItem(); - this.menuServerFilter = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); this.menuMoveToGroup = new System.Windows.Forms.ToolStripMenuItem(); this.menuMoveEvent = new System.Windows.Forms.ToolStripMenuItem(); @@ -68,9 +68,9 @@ this.menuExport2ServerConfig = new System.Windows.Forms.ToolStripMenuItem(); this.menuExport2ShareUrl = new System.Windows.Forms.ToolStripMenuItem(); this.menuExport2SubContent = new System.Windows.Forms.ToolStripMenuItem(); - this.tsbServer = new System.Windows.Forms.ToolStripDropDownButton(); this.tabGroup = new System.Windows.Forms.TabControl(); this.qrCodeControl = new v2rayN.Forms.QRCodeControl(); + this.tsbServer = new System.Windows.Forms.ToolStripDropDownButton(); this.scBig = new System.Windows.Forms.SplitContainer(); this.gbServers = new System.Windows.Forms.GroupBox(); this.mainMsgControl = new v2rayN.Forms.MainMsgControl(); @@ -130,6 +130,7 @@ this.tsbPromotion = new System.Windows.Forms.ToolStripButton(); this.toolStripSeparator11 = new System.Windows.Forms.ToolStripSeparator(); this.tsbClose = new System.Windows.Forms.ToolStripButton(); + this.tsbRestoreGuiNConfig = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.scServers)).BeginInit(); this.scServers.Panel1.SuspendLayout(); this.scServers.Panel2.SuspendLayout(); @@ -216,6 +217,7 @@ this.menuExport2ShareUrl, this.menuExport2SubContent}); this.cmsLv.Name = "cmsLv"; + this.cmsLv.OwnerItem = this.tsbServer; resources.ApplyResources(this.cmsLv, "cmsLv"); // // menuAddVmessServer @@ -271,6 +273,12 @@ this.toolStripSeparator1.Name = "toolStripSeparator1"; resources.ApplyResources(this.toolStripSeparator1, "toolStripSeparator1"); // + // menuServerFilter + // + this.menuServerFilter.Name = "menuServerFilter"; + resources.ApplyResources(this.menuServerFilter, "menuServerFilter"); + this.menuServerFilter.Click += new System.EventHandler(this.menuServerFilter_Click); + // // menuRemoveServer // this.menuRemoveServer.Name = "menuRemoveServer"; @@ -295,12 +303,6 @@ resources.ApplyResources(this.menuSetDefaultServer, "menuSetDefaultServer"); this.menuSetDefaultServer.Click += new System.EventHandler(this.menuSetDefaultServer_Click); // - // menuServerFilter - // - this.menuServerFilter.Name = "menuServerFilter"; - resources.ApplyResources(this.menuServerFilter, "menuServerFilter"); - this.menuServerFilter.Click += new System.EventHandler(this.menuServerFilter_Click); - // // toolStripSeparator3 // this.toolStripSeparator3.Name = "toolStripSeparator3"; @@ -428,13 +430,6 @@ resources.ApplyResources(this.menuExport2SubContent, "menuExport2SubContent"); this.menuExport2SubContent.Click += new System.EventHandler(this.menuExport2SubContent_Click); // - // tsbServer - // - this.tsbServer.DropDown = this.cmsLv; - this.tsbServer.Image = global::v2rayN.Properties.Resources.server; - resources.ApplyResources(this.tsbServer, "tsbServer"); - this.tsbServer.Name = "tsbServer"; - // // tabGroup // resources.ApplyResources(this.tabGroup, "tabGroup"); @@ -447,6 +442,13 @@ resources.ApplyResources(this.qrCodeControl, "qrCodeControl"); this.qrCodeControl.Name = "qrCodeControl"; // + // tsbServer + // + this.tsbServer.DropDown = this.cmsLv; + this.tsbServer.Image = global::v2rayN.Properties.Resources.server; + resources.ApplyResources(this.tsbServer, "tsbServer"); + this.tsbServer.Name = "tsbServer"; + // // scBig // resources.ApplyResources(this.scBig, "scBig"); @@ -672,7 +674,8 @@ this.tsbGlobalHotkeySetting, this.tsbGroupSetting, this.toolStripSeparator14, - this.tsbBackupGuiNConfig}); + this.tsbBackupGuiNConfig, + this.tsbRestoreGuiNConfig}); this.tsbSetting.Image = global::v2rayN.Properties.Resources.option; resources.ApplyResources(this.tsbSetting, "tsbSetting"); this.tsbSetting.Name = "tsbSetting"; @@ -863,6 +866,12 @@ this.tsbClose.Name = "tsbClose"; this.tsbClose.Click += new System.EventHandler(this.tsbClose_Click); // + // tsbRestoreGuiNConfig + // + this.tsbRestoreGuiNConfig.Name = "tsbRestoreGuiNConfig"; + resources.ApplyResources(this.tsbRestoreGuiNConfig, "tsbRestoreGuiNConfig"); + this.tsbRestoreGuiNConfig.Click += new System.EventHandler(this.tsbRestoreGuiNConfig_Click); + // // MainForm // resources.ApplyResources(this, "$this"); @@ -998,6 +1007,7 @@ private System.Windows.Forms.ToolStripMenuItem tsbCheckUpdateSagerNetCore; private System.Windows.Forms.ToolStripMenuItem tsbSubGroupUpdate; private System.Windows.Forms.ToolStripMenuItem tsbSubGroupUpdateViaProxy; + private System.Windows.Forms.ToolStripMenuItem tsbRestoreGuiNConfig; } } diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs index 7ba19c28..c5118ed7 100644 --- a/v2rayN/v2rayN/Forms/MainForm.cs +++ b/v2rayN/v2rayN/Forms/MainForm.cs @@ -811,6 +811,7 @@ namespace v2rayN.Forms if (statistics != null) { statistics.ClearAllServerStatistics(); + RefreshServers(); } } @@ -1082,6 +1083,14 @@ namespace v2rayN.Forms { MainFormHandler.Instance.BackupGuiNConfig(config); } + + private void tsbRestoreGuiNConfig_Click(object sender, EventArgs e) + { + if (MainFormHandler.Instance.RestoreGuiNConfig(ref config)) + { + RefreshServers(); + } + } #endregion @@ -1469,6 +1478,15 @@ namespace v2rayN.Forms { UpdateSubscriptionProcess("", true); } + private void tsbSubGroupUpdate_Click(object sender, EventArgs e) + { + UpdateSubscriptionProcess(_groupId, true); + } + + private void tsbSubGroupUpdateViaProxy_Click(object sender, EventArgs e) + { + UpdateSubscriptionProcess(_groupId, true); + } /// /// the subscription update process @@ -1581,14 +1599,5 @@ namespace v2rayN.Forms } #endregion - private void tsbSubGroupUpdate_Click(object sender, EventArgs e) - { - UpdateSubscriptionProcess(_groupId, true); - } - - private void tsbSubGroupUpdateViaProxy_Click(object sender, EventArgs e) - { - UpdateSubscriptionProcess(_groupId, true); - } } -} +} \ No newline at end of file diff --git a/v2rayN/v2rayN/Forms/MainForm.resx b/v2rayN/v2rayN/Forms/MainForm.resx index 241c477c..ebf2419a 100644 --- a/v2rayN/v2rayN/Forms/MainForm.resx +++ b/v2rayN/v2rayN/Forms/MainForm.resx @@ -218,30 +218,6 @@ Move to Group - - 192, 22 - - - Move to top (T) - - - 192, 22 - - - Up (U) - - - 192, 22 - - - Down (D) - - - 192, 22 - - - Move to bottom (B) - 355, 22 @@ -326,8 +302,20 @@ Export subscription (base64) share to clipboard + + Magenta + + + 64, 53 + + + Servers + + + ImageAboveText + - 356, 644 + 356, 622 cmsLv @@ -476,17 +464,29 @@ 0 - - Magenta + + 192, 22 - - 64, 53 + + Move to top (T) - - Servers + + 192, 22 - - ImageAboveText + + Up (U) + + + 192, 22 + + + Down (D) + + + 192, 22 + + + Move to bottom (B) Fill @@ -599,6 +599,27 @@ NoControl + + 278, 192 + + + cmsMain + + + System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + v2rayN + + + True + + + 277, 22 + + + System proxy + 243, 22 @@ -617,12 +638,6 @@ Do not change system proxy - - 277, 22 - - - System proxy - 277, 22 @@ -671,21 +686,6 @@ Exit - - 278, 192 - - - cmsMain - - - System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - v2rayN - - - True - Top @@ -716,36 +716,6 @@ 6, 56 - - 317, 22 - - - Settings - - - 317, 22 - - - Update subscription without proxy - - - 317, 22 - - - Update subscription with proxy - - - 317, 22 - - - Update group subscription without proxy - - - 317, 22 - - - Update group subscription with proxy - Magenta @@ -809,6 +779,12 @@ BackupGuiConfig + + 195, 22 + + + RestoreGuiNConfig + Magenta @@ -842,54 +818,6 @@ 6, 56 - - 219, 22 - - - v2rayN (this software) - - - 219, 22 - - - Update v2fly Core - - - 219, 22 - - - Update SagerNet Core - - - 219, 22 - - - Update Xray Core - - - 216, 6 - - - 219, 22 - - - Update clash Core - - - 219, 22 - - - Update Clash.Meta Core - - - 216, 6 - - - 219, 22 - - - Update Geo files - Magenta @@ -905,33 +833,6 @@ 6, 56 - - 187, 22 - - - v2rayN Project - - - 187, 22 - - - V2Ray Website - - - 184, 6 - - - 187, 22 - - - Language-[English] - - - 187, 22 - - - 语言-[中文简体] - Magenta @@ -992,6 +893,111 @@ 4 + + 317, 22 + + + Settings + + + 317, 22 + + + Update subscription without proxy + + + 317, 22 + + + Update subscription with proxy + + + 317, 22 + + + Update group subscription without proxy + + + 317, 22 + + + Update group subscription with proxy + + + 219, 22 + + + v2rayN (this software) + + + 219, 22 + + + Update v2fly Core + + + 219, 22 + + + Update SagerNet Core + + + 219, 22 + + + Update Xray Core + + + 216, 6 + + + 219, 22 + + + Update clash Core + + + 219, 22 + + + Update Clash.Meta Core + + + 216, 6 + + + 219, 22 + + + Update Geo files + + + 187, 22 + + + v2rayN Project + + + 187, 22 + + + V2Ray Website + + + 184, 6 + + + 187, 22 + + + Language-[English] + + + 187, 22 + + + 语言-[中文简体] + True @@ -1064,6 +1070,12 @@ System.Windows.Forms.ToolStripSeparator, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + menuServerFilter + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + menuRemoveServer @@ -1088,12 +1100,6 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - menuServerFilter - - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - toolStripSeparator3 @@ -1544,6 +1550,12 @@ System.Windows.Forms.ToolStripButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + tsbRestoreGuiNConfig + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + MainForm diff --git a/v2rayN/v2rayN/Forms/MainForm.zh-Hans.resx b/v2rayN/v2rayN/Forms/MainForm.zh-Hans.resx index 40bf1982..e8e04d0d 100644 --- a/v2rayN/v2rayN/Forms/MainForm.zh-Hans.resx +++ b/v2rayN/v2rayN/Forms/MainForm.zh-Hans.resx @@ -579,4 +579,7 @@ 更新当前分组订阅(通过代理) + + 恢复v2rayN配置文件 + \ No newline at end of file diff --git a/v2rayN/v2rayN/Handler/MainFormHandler.cs b/v2rayN/v2rayN/Handler/MainFormHandler.cs index e67909ba..240d04ff 100644 --- a/v2rayN/v2rayN/Handler/MainFormHandler.cs +++ b/v2rayN/v2rayN/Handler/MainFormHandler.cs @@ -232,6 +232,46 @@ namespace v2rayN.Handler } } + public bool RestoreGuiNConfig(ref Config config) + { + var fileContent = string.Empty; + using (OpenFileDialog fileDialog = new OpenFileDialog()) + { + fileDialog.InitialDirectory = Utils.GetBackupPath(""); + fileDialog.Filter = "guiNConfig|*.json|All|*.*"; + fileDialog.FilterIndex = 2; + fileDialog.RestoreDirectory = true; + + if (fileDialog.ShowDialog() == DialogResult.OK) + { + fileContent = Utils.LoadResource(fileDialog.FileName); + } + else + { + return false; + } + } + if (Utils.IsNullOrEmpty(fileContent)) + { + UI.ShowWarning(ResUI.OperationFailed); + return false; + } + + var resConfig = Utils.FromJson(fileContent); + if (resConfig == null) + { + UI.ShowWarning(ResUI.OperationFailed); + return false; + } + //backup first + BackupGuiNConfig(config, true); + + config = resConfig; + LazyConfig.Instance.SetConfig(ref config); + + return true; + } + public void UpdateTask(Config config, Action update) { Task.Run(() => UpdateTaskRun(config, update)); diff --git a/v2rayN/v2rayN/Handler/StatisticsHandler.cs b/v2rayN/v2rayN/Handler/StatisticsHandler.cs index 32242e3f..c76105c5 100644 --- a/v2rayN/v2rayN/Handler/StatisticsHandler.cs +++ b/v2rayN/v2rayN/Handler/StatisticsHandler.cs @@ -190,15 +190,16 @@ namespace v2rayN.Handler { if (serverStatistics_ != null) { - foreach (var item in serverStatistics_.server) - { - item.todayUp = 0; - item.todayDown = 0; - item.totalUp = 0; - item.totalDown = 0; - // update ui display to zero - updateFunc_(0, 0, new List { item }); - } + //foreach (var item in serverStatistics_.server) + //{ + // item.todayUp = 0; + // item.todayDown = 0; + // item.totalUp = 0; + // item.totalDown = 0; + // // update ui display to zero + // updateFunc_(0, 0, new List { item }); + //} + serverStatistics_.server = new List(); // update statistic json file SaveToFile();