Skip to content

Commit

Permalink
Only write to config file if content has changed
Browse files Browse the repository at this point in the history
  • Loading branch information
0blu committed Nov 13, 2023
1 parent 2dc1de0 commit 169b1cf
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion WinterspringLauncher/LauncherConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class VersionedBaseConfig

public class LauncherConfig : VersionedBaseConfig
{
private string _internalLastLoadedJsonString = string.Empty;

public string LauncherLanguage { get; set; } = "en";
public string? GitHubApiMirror { get; set; } = null; // example "http://asia.cdn.everlook.aclon.cn/github-mirror/api/" + "/repos/{repoName}/releases/latest"
public string LastSelectedServerName { get; set; } = "";
Expand Down Expand Up @@ -119,7 +121,10 @@ public void SaveConfig(string configPath)
{
var options = new JsonSerializerOptions { WriteIndented = true };
string jsonString = JsonSerializer.Serialize(this, options);
File.WriteAllText(configPath, jsonString, Encoding.UTF8);
if (jsonString != _internalLastLoadedJsonString)
{
File.WriteAllText(configPath, jsonString, Encoding.UTF8);
}
}

public static LauncherConfig LoadOrCreateDefault(string configPath)
Expand All @@ -137,6 +142,7 @@ public static LauncherConfig LoadOrCreateDefault(string configPath)
if (loadedJson != null)
{
config = loadedJson;
config._internalLastLoadedJsonString = configTextContent;
}
else
{
Expand Down

0 comments on commit 169b1cf

Please sign in to comment.