diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs index 56c63c23..05a3f2fa 100644 --- a/v2rayN/v2rayN/Forms/MainForm.cs +++ b/v2rayN/v2rayN/Forms/MainForm.cs @@ -43,6 +43,7 @@ namespace v2rayN.Forms { ConfigHandler.LoadConfig(ref config); ConfigHandler.InitBuiltinRouting(ref config); + MainFormHandler.Instance.BackupGuiNConfig(config, true); v2rayHandler = new V2rayHandler(); v2rayHandler.ProcessEvent += v2rayHandler_ProcessEvent; @@ -929,7 +930,7 @@ namespace v2rayN.Forms { if (!Utils.IsNullOrEmpty(MsgFilter)) { - if (!Regex.IsMatch(text,MsgFilter)) + if (!Regex.IsMatch(text, MsgFilter)) { return; } diff --git a/v2rayN/v2rayN/Handler/MainFormHandler.cs b/v2rayN/v2rayN/Handler/MainFormHandler.cs index 6b74923f..054cf476 100644 --- a/v2rayN/v2rayN/Handler/MainFormHandler.cs +++ b/v2rayN/v2rayN/Handler/MainFormHandler.cs @@ -236,31 +236,44 @@ namespace v2rayN.Handler } } - - public void BackupGuiNConfig(Config config) + + public void BackupGuiNConfig(Config config, bool auto = false) { - SaveFileDialog fileDialog = new SaveFileDialog + string fileName = string.Empty; + if (auto) { - Filter = "guiNConfig|*.json", - FilterIndex = 2, - RestoreDirectory = true - }; - if (fileDialog.ShowDialog() != DialogResult.OK) - { - return; + fileName = Utils.GetTempPath($"guiNConfig{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.json"); + } + else + { + SaveFileDialog fileDialog = new SaveFileDialog + { + Filter = "guiNConfig|*.json", + FilterIndex = 2, + RestoreDirectory = true + }; + if (fileDialog.ShowDialog() != DialogResult.OK) + { + return; + } + fileName = fileDialog.FileName; } - string fileName = fileDialog.FileName; if (Utils.IsNullOrEmpty(fileName)) { return; } - if (Utils.ToJsonFile(config, fileName) == 0) + var ret = Utils.ToJsonFile(config, fileName); + if (!auto) { - UI.Show(UIRes.I18N("OperationSuccess")); - } - else - { - UI.ShowWarning(UIRes.I18N("OperationFailed")); + if (ret == 0) + { + + UI.Show(UIRes.I18N("OperationSuccess")); + } + else + { + UI.ShowWarning(UIRes.I18N("OperationFailed")); + } } } diff --git a/v2rayN/v2rayN/Program.cs b/v2rayN/v2rayN/Program.cs index cd3e1559..4d37d44f 100644 --- a/v2rayN/v2rayN/Program.cs +++ b/v2rayN/v2rayN/Program.cs @@ -34,7 +34,7 @@ namespace v2rayN if (!IsDuplicateInstance()) { - Utils.SaveLog("v2rayN start up " + Utils.GetVersion()); + Utils.SaveLog($"v2rayN start up | {Utils.GetVersion()} | {Utils.GetExePath()}"); //设置语言环境 string lang = Utils.RegReadValue(Global.MyRegPath, Global.MyRegKeyLanguage, "zh-Hans"); @@ -81,7 +81,7 @@ namespace v2rayN string name = Utils.GetExePath(); // Allow different locations to run name = name.Replace("\\", "/"); // https://stackoverflow.com/questions/20714120/could-not-find-a-part-of-the-path-error-while-creating-mutex - + Global.mutexObj = new Mutex(false, name, out bool bCreatedNew); return !bCreatedNew; }