Fix issue when saving gui config

pull/2295/head
2dust 2022-04-29 10:58:51 +08:00
parent 7ec0607fec
commit 2a11fe11e8
1 changed files with 20 additions and 1 deletions

View File

@ -6,6 +6,7 @@ using v2rayN.Mode;
using v2rayN.Base;
using System.Linq;
using v2rayN.Tool;
using System.Threading.Tasks;
namespace v2rayN.Handler
{
@ -207,7 +208,25 @@ namespace v2rayN.Handler
{
lock (objLock)
{
Utils.ToJsonFile(config, Utils.GetPath(configRes));
try
{
Task.Run(() =>
{
//save temp file
var temp = $"{configRes}_temp";
if (Utils.ToJsonFile(config, Utils.GetPath(temp)) != 0)
{
return;
}
//rename
File.Move(temp, configRes);
});
}
catch (Exception ex)
{
Utils.SaveLog("ToJsonFile", ex);
}
}
}