-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d33f47
commit d0b0af9
Showing
4 changed files
with
86 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.IO; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using System.Threading.Tasks; | ||
using System.Windows.Media; | ||
using ImageMagick; | ||
|
||
namespace TextureMagic; | ||
|
||
public class SettingsStorage | ||
{ | ||
|
||
// Generate magick colour | ||
[JsonIgnore] | ||
public MagickColor BackgroundColorMagick => new(BackgroundColor.R, BackgroundColor.G, BackgroundColor.B); | ||
|
||
|
||
public Color BackgroundColor { get; set; } | ||
|
||
public static async Task Save(SettingsStorage settingsStorage) | ||
{ | ||
await File.WriteAllTextAsync("settings.json", JsonSerializer.Serialize(settingsStorage)); | ||
} | ||
|
||
public static async Task<SettingsStorage> Load() | ||
{ | ||
if (!File.Exists("settings.json")) | ||
{ | ||
var settings = new SettingsStorage(); | ||
|
||
await Save(settings); | ||
|
||
return settings; | ||
} | ||
|
||
var data = await File.ReadAllTextAsync("settings.json"); | ||
|
||
return JsonSerializer.Deserialize<SettingsStorage>(data) ?? new SettingsStorage(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters