From 3c1c718bc7e6fe7262f05794db90a58c5796e28a Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Thu, 15 Jul 2021 17:14:20 -0400 Subject: [PATCH] don't attempt to overwrite advanced settings file if contents are unchanged --- FileManager/Configuration.cs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/FileManager/Configuration.cs b/FileManager/Configuration.cs index 8df08b87..1a946063 100644 --- a/FileManager/Configuration.cs +++ b/FileManager/Configuration.cs @@ -118,12 +118,13 @@ namespace FileManager } private string getLiberationFilesSettingFromJson() { + string startingContents = null; try { if (File.Exists(APPSETTINGS_JSON)) { - var appSettingsContents = File.ReadAllText(APPSETTINGS_JSON); - var jObj = JObject.Parse(appSettingsContents); + startingContents = File.ReadAllText(APPSETTINGS_JSON); + var jObj = JObject.Parse(startingContents); if (jObj.ContainsKey(LIBATION_FILES)) { @@ -137,7 +138,11 @@ namespace FileManager } catch { } - File.WriteAllText(APPSETTINGS_JSON, new JObject { { LIBATION_FILES, APP_DIR } }.ToString(Formatting.Indented)); + var endingContents = new JObject { { LIBATION_FILES, APP_DIR } }.ToString(Formatting.Indented); + + if (startingContents != endingContents) + File.WriteAllText(APPSETTINGS_JSON, endingContents); + return APP_DIR; } @@ -174,13 +179,14 @@ namespace FileManager libationFilesPathCache = null; - var contents = File.ReadAllText(APPSETTINGS_JSON); - var jObj = JObject.Parse(contents); + var startingContents = File.ReadAllText(APPSETTINGS_JSON); + var jObj = JObject.Parse(startingContents); jObj[LIBATION_FILES] = directory; - var output = JsonConvert.SerializeObject(jObj, Formatting.Indented); - File.WriteAllText(APPSETTINGS_JSON, output); + var endingContents = JsonConvert.SerializeObject(jObj, Formatting.Indented); + if (startingContents != endingContents) + File.WriteAllText(APPSETTINGS_JSON, endingContents); return true;