From 03dec5b6047bd16a8fdb4f8c07a341b0351c99db Mon Sep 17 00:00:00 2001
From: 2dust <31833384+2dust@users.noreply.github.com>
Date: Tue, 11 May 2021 20:11:15 +0800
Subject: [PATCH] BackupGuiConfig
---
v2rayN/v2rayN/Forms/MainForm.Designer.cs | 19 +++-
v2rayN/v2rayN/Forms/MainForm.cs | 63 ++++++------
v2rayN/v2rayN/Forms/MainForm.zh-Hans.resx | 114 +++++++++++-----------
v2rayN/v2rayN/Handler/MainFormHandler.cs | 27 +++++
4 files changed, 133 insertions(+), 90 deletions(-)
diff --git a/v2rayN/v2rayN/Forms/MainForm.Designer.cs b/v2rayN/v2rayN/Forms/MainForm.Designer.cs
index b69bff7e..15a2db24 100644
--- a/v2rayN/v2rayN/Forms/MainForm.Designer.cs
+++ b/v2rayN/v2rayN/Forms/MainForm.Designer.cs
@@ -110,6 +110,8 @@
this.tsbSetting = new System.Windows.Forms.ToolStripDropDownButton();
this.tsbOptionSetting = new System.Windows.Forms.ToolStripMenuItem();
this.tsbRoutingSetting = new System.Windows.Forms.ToolStripMenuItem();
+ this.toolStripSeparator14 = new System.Windows.Forms.ToolStripSeparator();
+ this.tsbBackupGuiNConfig = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator();
this.tsbReload = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator7 = new System.Windows.Forms.ToolStripSeparator();
@@ -711,7 +713,9 @@
resources.ApplyResources(this.tsbSetting, "tsbSetting");
this.tsbSetting.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tsbOptionSetting,
- this.tsbRoutingSetting});
+ this.tsbRoutingSetting,
+ this.toolStripSeparator14,
+ this.tsbBackupGuiNConfig});
this.tsbSetting.Image = global::v2rayN.Properties.Resources.option;
this.tsbSetting.Name = "tsbSetting";
//
@@ -727,6 +731,17 @@
this.tsbRoutingSetting.Name = "tsbRoutingSetting";
this.tsbRoutingSetting.Click += new System.EventHandler(this.tsbRoutingSetting_Click);
//
+ // toolStripSeparator14
+ //
+ resources.ApplyResources(this.toolStripSeparator14, "toolStripSeparator14");
+ this.toolStripSeparator14.Name = "toolStripSeparator14";
+ //
+ // tsbBackupGuiNConfig
+ //
+ resources.ApplyResources(this.tsbBackupGuiNConfig, "tsbBackupGuiNConfig");
+ this.tsbBackupGuiNConfig.Name = "tsbBackupGuiNConfig";
+ this.tsbBackupGuiNConfig.Click += new System.EventHandler(this.tsbBackupGuiNConfig_Click);
+ //
// toolStripSeparator5
//
resources.ApplyResources(this.toolStripSeparator5, "toolStripSeparator5");
@@ -970,6 +985,8 @@
private System.Windows.Forms.ToolStripMenuItem menuMsgBoxCopy;
private System.Windows.Forms.ToolStripMenuItem menuMsgBoxAddRoutingRule;
private System.Windows.Forms.ToolStripMenuItem menuMsgBoxCopyAll;
+ private System.Windows.Forms.ToolStripSeparator toolStripSeparator14;
+ private System.Windows.Forms.ToolStripMenuItem tsbBackupGuiNConfig;
}
}
diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs
index 08783e41..fb38528e 100644
--- a/v2rayN/v2rayN/Forms/MainForm.cs
+++ b/v2rayN/v2rayN/Forms/MainForm.cs
@@ -33,14 +33,7 @@ namespace v2rayN.Forms
Application.ApplicationExit += (sender, args) =>
{
- v2rayHandler.V2rayStop();
-
- //HttpProxyHandle.CloseHttpAgent(config);
- HttpProxyHandle.UpdateSysProxy(config, true);
-
- ConfigHandler.SaveConfig(ref config);
- statistics?.SaveToFile();
- statistics?.Close();
+ MyAppExit();
};
}
@@ -85,12 +78,19 @@ namespace v2rayN.Forms
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
- if (e.CloseReason == CloseReason.UserClosing)
+ switch (e.CloseReason)
{
- StorageUI();
- e.Cancel = true;
- HideForm();
- return;
+ case CloseReason.UserClosing:
+ StorageUI();
+ e.Cancel = true;
+ HideForm();
+ break;
+ case CloseReason.ApplicationExitCall:
+ case CloseReason.FormOwnerClosing:
+ case CloseReason.TaskManagerClosing:
+ case CloseReason.WindowsShutDown:
+ MyAppExit();
+ break;
}
}
@@ -105,26 +105,21 @@ namespace v2rayN.Forms
//}
}
+ private void MyAppExit()
+ {
+ try
+ {
+ v2rayHandler.V2rayStop();
+ //HttpProxyHandle.CloseHttpAgent(config);
+ HttpProxyHandle.UpdateSysProxy(config, true);
- //private const int WM_QUERYENDSESSION = 0x0011;
- //protected override void WndProc(ref Message m)
- //{
- // switch (m.Msg)
- // {
- // case WM_QUERYENDSESSION:
- // Utils.SaveLog("Windows shutdown UnsetProxy");
-
- // ConfigHandler.ToJsonFile(config);
- // statistics?.SaveToFile();
- // ProxySetting.UnsetProxy();
- // m.Result = (IntPtr)1;
- // break;
- // default:
- // base.WndProc(ref m);
- // break;
- // }
- //}
+ ConfigHandler.SaveConfig(ref config);
+ statistics?.SaveToFile();
+ statistics?.Close();
+ }
+ catch { }
+ }
private void RestoreUI()
{
@@ -883,6 +878,10 @@ namespace v2rayN.Forms
UpdateSubscriptionProcess();
}
+ private void tsbBackupGuiNConfig_Click(object sender, EventArgs e)
+ {
+ MainFormHandler.Instance.BackupGuiNConfig(config);
+ }
#endregion
@@ -1406,7 +1405,7 @@ namespace v2rayN.Forms
RefreshServers();
}
};
- MainFormHandler.Instance.UpdateSubscriptionProcess(config, _updateUI);
+ MainFormHandler.Instance.UpdateSubscriptionProcess(config, _updateUI);
}
private void tsbQRCodeSwitch_CheckedChanged(object sender, EventArgs e)
diff --git a/v2rayN/v2rayN/Forms/MainForm.zh-Hans.resx b/v2rayN/v2rayN/Forms/MainForm.zh-Hans.resx
index c4e9f00c..b51b78f3 100644
--- a/v2rayN/v2rayN/Forms/MainForm.zh-Hans.resx
+++ b/v2rayN/v2rayN/Forms/MainForm.zh-Hans.resx
@@ -318,6 +318,15 @@
ZW0uRHJhd2luZy5HcmFwaGljc1VuaXQBAAAAB3ZhbHVlX18ACAMAAAADAAAACw==
+
+ 196, 170
+
+
+ 195, 22
+
+
+ 系统代理
+
172, 22
@@ -336,12 +345,6 @@
不改变系统代理
-
- 195, 22
-
-
- 系统代理
-
195, 22
@@ -384,12 +387,15 @@
退出
-
- 196, 170
-
服务器列表
+
+ 信息
+
+
+ 222, 92
+
221, 22
@@ -414,27 +420,9 @@
快速添加路由规则 (Ctrl+V)
-
- 222, 114
-
网速显示未启用
-
- 信息
-
-
- 124, 22
-
-
- 订阅设置
-
-
- 124, 22
-
-
- 更新订阅
-
61, 53
@@ -447,18 +435,18 @@
分享
-
- 124, 22
-
参数设置
-
- 124, 22
-
路由设置
+
+ 189, 22
+
+
+ 备份v2rayN配置文件
+
61, 53
@@ -482,36 +470,12 @@
重启服务
-
- 135, 22
-
-
- v2rayN
-
-
- 135, 22
-
-
- v2fly-Core
-
-
- 135, 22
-
-
- Xray-Core
-
85, 53
检查更新
-
- v2rayN 项目
-
-
- V2Ray 官网
-
69, 53
@@ -537,4 +501,40 @@
关闭窗口
+
+ 124, 22
+
+
+ 订阅设置
+
+
+ 124, 22
+
+
+ 更新订阅
+
+
+ 135, 22
+
+
+ v2rayN
+
+
+ 135, 22
+
+
+ v2fly-Core
+
+
+ 135, 22
+
+
+ Xray-Core
+
+
+ v2rayN 项目
+
+
+ V2Ray 官网
+
\ No newline at end of file
diff --git a/v2rayN/v2rayN/Handler/MainFormHandler.cs b/v2rayN/v2rayN/Handler/MainFormHandler.cs
index 6842a5b9..6b74923f 100644
--- a/v2rayN/v2rayN/Handler/MainFormHandler.cs
+++ b/v2rayN/v2rayN/Handler/MainFormHandler.cs
@@ -236,6 +236,33 @@ namespace v2rayN.Handler
}
}
+
+ public void BackupGuiNConfig(Config config)
+ {
+ SaveFileDialog fileDialog = new SaveFileDialog
+ {
+ Filter = "guiNConfig|*.json",
+ FilterIndex = 2,
+ RestoreDirectory = true
+ };
+ if (fileDialog.ShowDialog() != DialogResult.OK)
+ {
+ return;
+ }
+ string fileName = fileDialog.FileName;
+ if (Utils.IsNullOrEmpty(fileName))
+ {
+ return;
+ }
+ if (Utils.ToJsonFile(config, fileName) == 0)
+ {
+ UI.Show(UIRes.I18N("OperationSuccess"));
+ }
+ else
+ {
+ UI.ShowWarning(UIRes.I18N("OperationFailed"));
+ }
+ }
}
}