Fix issue when saving gui config

pull/2295/head
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
{
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 { }
}

View File

@ -15,8 +15,9 @@ namespace v2rayN.Handler
/// </summary>
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)
{