-
Notifications
You must be signed in to change notification settings - Fork 0
/
MicroSDInstallStatusUpdaterSettings.cs
89 lines (78 loc) · 3.33 KB
/
MicroSDInstallStatusUpdaterSettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using Playnite.SDK;
using Playnite.SDK.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MicroSDInstallStatusUpdater
{
public class MicroSDInstallStatusUpdaterSettings : ObservableObject
{
private string option1 = string.Empty;
private bool option2 = false;
private bool optionThatWontBeSaved = false;
public string Option1 { get => option1; set => SetValue(ref option1, value); }
public bool Option2 { get => option2; set => SetValue(ref option2, value); }
// Playnite serializes settings object to a JSON object and saves it as text file.
// If you want to exclude some property from being saved then use `JsonDontSerialize` ignore attribute.
[DontSerialize]
public bool OptionThatWontBeSaved { get => optionThatWontBeSaved; set => SetValue(ref optionThatWontBeSaved, value); }
}
public class MicroSDInstallStatusUpdaterSettingsViewModel : ObservableObject, ISettings
{
private readonly MicroSDInstallStatusUpdater plugin;
private MicroSDInstallStatusUpdaterSettings editingClone { get; set; }
private MicroSDInstallStatusUpdaterSettings settings;
public MicroSDInstallStatusUpdaterSettings Settings
{
get => settings;
set
{
settings = value;
OnPropertyChanged();
}
}
public MicroSDInstallStatusUpdaterSettingsViewModel(MicroSDInstallStatusUpdater plugin)
{
// Injecting your plugin instance is required for Save/Load method because Playnite saves data to a location based on what plugin requested the operation.
this.plugin = plugin;
// Load saved settings.
var savedSettings = plugin.LoadPluginSettings<MicroSDInstallStatusUpdaterSettings>();
// LoadPluginSettings returns null if no saved data is available.
if (savedSettings != null)
{
Settings = savedSettings;
}
else
{
Settings = new MicroSDInstallStatusUpdaterSettings();
}
}
public void BeginEdit()
{
// Code executed when settings view is opened and user starts editing values.
editingClone = Serialization.GetClone(Settings);
}
public void CancelEdit()
{
// Code executed when user decides to cancel any changes made since BeginEdit was called.
// This method should revert any changes made to Option1 and Option2.
Settings = editingClone;
}
public void EndEdit()
{
// Code executed when user decides to confirm changes made since BeginEdit was called.
// This method should save settings made to Option1 and Option2.
plugin.SavePluginSettings(Settings);
}
public bool VerifySettings(out List<string> errors)
{
// Code execute when user decides to confirm changes made since BeginEdit was called.
// Executed before EndEdit is called and EndEdit is not called if false is returned.
// List of errors is presented to user if verification fails.
errors = new List<string>();
return true;
}
}
}