From 36aad4424e10909cd942ceab19b5f967e5682804 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 6 May 2022 10:54:10 +0800 Subject: [PATCH] Fix issue when saving gui config --- v2rayN/v2rayN/Forms/MainForm.cs | 10 +++++++--- v2rayN/v2rayN/Handler/ConfigHandler.cs | 14 ++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs index 6fbcf91e..73af80ad 100644 --- a/v2rayN/v2rayN/Forms/MainForm.cs +++ b/v2rayN/v2rayN/Forms/MainForm.cs @@ -123,7 +123,10 @@ namespace v2rayN.Forms { try { - v2rayHandler.V2rayStop(); + Utils.SaveLog("MyAppExit Begin"); + + StorageUI(); + ConfigHandler.SaveConfig(ref config); //HttpProxyHandle.CloseHttpAgent(config); if (blWindowsShutDown) @@ -135,10 +138,11 @@ namespace v2rayN.Forms SysProxyHandle.UpdateSysProxy(config, true); } - StorageUI(); - ConfigHandler.SaveConfig(ref config); statistics?.SaveToFile(); statistics?.Close(); + + v2rayHandler.V2rayStop(); + Utils.SaveLog("MyAppExit End"); } catch { } } diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs index 21cecfd3..a22204cf 100644 --- a/v2rayN/v2rayN/Handler/ConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs @@ -15,8 +15,9 @@ namespace v2rayN.Handler /// class ConfigHandler { - private static string configRes = Global.ConfigFileName; + //private static string configRes = Global.ConfigFileName; private static readonly object objLock = new object(); + private string configResPath = Utils.GetPath(Global.ConfigFileName); #region ConfigHandler @@ -212,18 +213,19 @@ namespace v2rayN.Handler { //save temp file - var temp = $"{configRes}_temp"; - if (Utils.ToJsonFile(config, Utils.GetPath(temp)) != 0) + var tempPath = Utils.GetPath($"{configRes}_temp"); + var resPath = Utils.GetPath(configRes); + if (Utils.ToJsonFile(config, tempPath) != 0) { return; } - if (File.Exists(configRes)) + if (File.Exists(resPath)) { - File.Delete(configRes); + File.Delete(resPath); } //rename - File.Move(temp, configRes); + File.Move(tempPath, resPath); } catch (Exception ex) {