Skip to content

Commit

Permalink
Read and write settings file
Browse files Browse the repository at this point in the history
  • Loading branch information
Perez-Smith, Fidel authored and Perez-Smith, Fidel committed Jun 30, 2024
1 parent 3bc13f6 commit 2261bd9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 5 additions & 3 deletions SimpleKVM/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,13 @@ public static string SerializeToJson(this object obj)

public static void WriteTextFile(string filename, string content)
{
var existingContent = File.ReadAllText(filename);
if (existingContent != content)
if (File.Exists(filename) && File.ReadAllText(filename) == content)
{
File.WriteAllText(filename, content);
//nothing's changed
return;
}

File.WriteAllText(filename, content);
}

public static string ToString(this IEnumerable<string> list, string separator)
Expand Down
9 changes: 6 additions & 3 deletions SimpleKVM/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,12 @@ private void BtnNewRule_Click(object sender, EventArgs e)

private static void LoadRules()
{
var rulesJson = File.ReadAllText(SettingsFilename);
var loadedRules = rulesJson?.DeserializJson<List<Rule>>() ?? [];
Rules.AddRange(loadedRules);
if (File.Exists(SettingsFilename))
{
var rulesJson = File.ReadAllText(SettingsFilename);
var loadedRules = rulesJson?.DeserializJson<List<Rule>>() ?? [];
Rules.AddRange(loadedRules);
}
}

private static void SaveRules()
Expand Down

0 comments on commit 2261bd9

Please sign in to comment.