forked from jackgllghr/PlayniteEmudeck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmudeckPlayniteSettings.cs
More file actions
99 lines (84 loc) · 3.39 KB
/
EmudeckPlayniteSettings.cs
File metadata and controls
99 lines (84 loc) · 3.39 KB
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
90
91
92
93
94
95
96
97
98
99
using Playnite.SDK;
using Playnite.SDK.Data;
using System.Collections.Generic;
namespace EmudeckPlaynite
{
public class EmudeckPlayniteSettings : ObservableObject
{
private string pluginPreviouslyInstalledVersion = "";
public string PluginPreviouslyInstalledVersion { get => pluginPreviouslyInstalledVersion; set => SetValue(ref pluginPreviouslyInstalledVersion, value); }
private string emudeckInstallDir = "";
public string EmudeckInstallDir { get => emudeckInstallDir; set => SetValue(ref emudeckInstallDir, value); }
}
public class EmudeckPlayniteSettingsViewModel : ObservableObject, ISettings
{
private readonly EmudeckPlaynite plugin;
private EmudeckPlayniteSettings editingClone { get; set; }
private EmudeckPlayniteSettings settings;
public EmudeckPlayniteSettings Settings
{
get => settings;
set
{
settings = value;
OnPropertyChanged();
}
}
public EmudeckPlayniteSettingsViewModel(EmudeckPlaynite 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<EmudeckPlayniteSettings>();
// LoadPluginSettings returns null if no saved data is available.
if (savedSettings != null)
{
Settings = savedSettings;
}
else
{
Settings = new EmudeckPlayniteSettings();
}
}
public RelayCommand<object> BrowseCommand
{
get => new RelayCommand<object>((a) =>
{
var filePath = Playnite.SDK.API.Instance.Dialogs.SelectFolder();
settings.EmudeckInstallDir = filePath;
});
}
public RelayCommand<object> ReloadCommand
{
get => new RelayCommand<object>((a) =>
{
settings.EmudeckInstallDir = $"{settings.EmudeckInstallDir}";
});
}
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;
}
}
}