Fix issue when saving gui config

This commit is contained in:
2dust 2022-05-06 10:54:10 +08:00
parent b29fb1e2a3
commit 36aad4424e
2 changed files with 15 additions and 9 deletions

View file

@ -123,7 +123,10 @@ namespace v2rayN.Forms
{ {
try try
{ {
v2rayHandler.V2rayStop(); Utils.SaveLog("MyAppExit Begin");
StorageUI();
ConfigHandler.SaveConfig(ref config);
//HttpProxyHandle.CloseHttpAgent(config); //HttpProxyHandle.CloseHttpAgent(config);
if (blWindowsShutDown) if (blWindowsShutDown)
@ -135,10 +138,11 @@ namespace v2rayN.Forms
SysProxyHandle.UpdateSysProxy(config, true); SysProxyHandle.UpdateSysProxy(config, true);
} }
StorageUI();
ConfigHandler.SaveConfig(ref config);
statistics?.SaveToFile(); statistics?.SaveToFile();
statistics?.Close(); statistics?.Close();
v2rayHandler.V2rayStop();
Utils.SaveLog("MyAppExit End");
} }
catch { } catch { }
} }

View file

@ -15,8 +15,9 @@ namespace v2rayN.Handler
/// </summary> /// </summary>
class ConfigHandler class ConfigHandler
{ {
private static string configRes = Global.ConfigFileName; //private static string configRes = Global.ConfigFileName;
private static readonly object objLock = new object(); private static readonly object objLock = new object();
private string configResPath = Utils.GetPath(Global.ConfigFileName);
#region ConfigHandler #region ConfigHandler
@ -212,18 +213,19 @@ namespace v2rayN.Handler
{ {
//save temp file //save temp file
var temp = $"{configRes}_temp"; var tempPath = Utils.GetPath($"{configRes}_temp");
if (Utils.ToJsonFile(config, Utils.GetPath(temp)) != 0) var resPath = Utils.GetPath(configRes);
if (Utils.ToJsonFile(config, tempPath) != 0)
{ {
return; return;
} }
if (File.Exists(configRes)) if (File.Exists(resPath))
{ {
File.Delete(configRes); File.Delete(resPath);
} }
//rename //rename
File.Move(temp, configRes); File.Move(tempPath, resPath);
} }
catch (Exception ex) catch (Exception ex)
{ {