From 2a11fe11e8957052666cddb156aed3bbdafd5bc9 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 29 Apr 2022 10:58:51 +0800 Subject: [PATCH] Fix issue when saving gui config --- v2rayN/v2rayN/Handler/ConfigHandler.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs index 2445e384..9c138ca1 100644 --- a/v2rayN/v2rayN/Handler/ConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs @@ -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); + } } }