only write config file when contents have changed (memo)

This commit is contained in:
ig 2023-09-01 11:11:09 +02:00
parent b5436e64aa
commit 851b936217
1 changed files with 7 additions and 1 deletions

View File

@ -38,7 +38,7 @@ public class Config //TODO: let IE choose from config files (Json) and connect t
public required DeviceConfig Devices { get; set; } public required DeviceConfig Devices { get; set; }
public required S3Config? S3 { get; set; } public required S3Config? S3 { get; set; }
private static String? LastSavedData { get; set; }
#if DEBUG #if DEBUG
public static Config Default => new() public static Config Default => new()
@ -121,6 +121,12 @@ public class Config //TODO: let IE choose from config files (Json) and connect t
try try
{ {
var jsonString = Serialize(this, JsonOptions); var jsonString = Serialize(this, JsonOptions);
if (LastSavedData == jsonString)
return;
LastSavedData = jsonString;
File.WriteAllText(configFilePath, jsonString); File.WriteAllText(configFilePath, jsonString);
} }
catch (Exception e) catch (Exception e)