-
Notifications
You must be signed in to change notification settings - Fork 1
/
EmudeckPlaynite.cs
140 lines (116 loc) · 5.37 KB
/
EmudeckPlaynite.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using EmudeckPlaynite.Model;
using Playnite.SDK;
using Playnite.SDK.Events;
using Playnite.SDK.Plugins;
using System;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Windows.Controls;
using YamlDotNet.Serialization.NamingConventions;
namespace EmudeckPlaynite
{
public class EmudeckPlaynite : GenericPlugin
{
private static readonly ILogger logger = LogManager.GetLogger();
private static readonly string currentVersion = "0.7";
private EmudeckPlayniteSettingsViewModel settings { get; set; }
private EmudeckConfigurator configurator { get; set; }
public override Guid Id { get; } = Guid.Parse("82cf60ec-8091-488d-9c85-63836ebee151");
private Configuration GetConfiguration() {
var configPath = Path.Combine(GetExtensionInstallPath(), "Resources", "emulators.yml");
try{
var deserializer = new YamlDotNet.Serialization.DeserializerBuilder()
.WithNamingConvention(new CamelCaseNamingConvention())
.Build();
var file = File.ReadAllText(configPath);
return deserializer.Deserialize<Configuration>(file);
} catch(Exception e){
PlayniteApi.Dialogs.ShowErrorMessage("Unable to read configuration file: " + configPath + "\n" + e.Message, "Emudeck");
return new Configuration();
}
}
private string GetExtensionInstallPath(){
return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}
public EmudeckPlaynite(IPlayniteAPI api) : base(api)
{
settings = new EmudeckPlayniteSettingsViewModel(this);
Properties = new GenericPluginProperties
{
HasSettings = true
};
settings.Settings.PropertyChanged += Reset;
}
public void Reset(){
configurator = new EmudeckConfigurator(
settings.Settings.EmudeckInstallDir,
GetConfiguration()
);
configurator.RemoveAllEmulators();
configurator.AddEmulators();
API.Instance.Notifications.Add(id: "Emudeck" + Guid.NewGuid(), text: "Emudeck emulator configurations have been updated.", NotificationType.Info);
}
public void Reset(object sender, PropertyChangedEventArgs args){
Reset();
}
public override void OnGameInstalled(OnGameInstalledEventArgs args)
{
// Add code to be executed when game is finished installing.
}
public override void OnGameStarted(OnGameStartedEventArgs args)
{
// Add code to be executed when game is started running.
}
public override void OnGameStarting(OnGameStartingEventArgs args)
{
// Add code to be executed when game is preparing to be started.
}
public override void OnGameStopped(OnGameStoppedEventArgs args)
{
// Add code to be executed when game is preparing to be started.
}
public override void OnGameUninstalled(OnGameUninstalledEventArgs args)
{
// Add code to be executed when game is uninstalled.
}
public override void OnApplicationStarted(OnApplicationStartedEventArgs args)
{
// Check if configured
if(settings.Settings.EmudeckInstallDir == "")
{
API.Instance.Dialogs.ShowMessage("Emudeck Plugin has not been configured yet. Please select the path to your Emudeck installation:", "Emudeck Setup", System.Windows.MessageBoxButton.OK);
string folder = API.Instance.Dialogs.SelectFolder();
if(folder != "")
{
settings.Settings.EmudeckInstallDir = folder;
settings.Settings.PluginPreviouslyInstalledVersion = currentVersion;
settings.EndEdit();
API.Instance.Dialogs.ShowMessage("You're all set to start using Emudeck through Playnite! \n\nIf your games aren't appearing in your library, simply select \n\nUpdate Game Library > Update Emulated Folders > Update All\n\nAll your emulator and auto-scan configurations can be viewed and edited in \nLibrary > Configure Emulators...", "Emudeck Setup", System.Windows.MessageBoxButton.OK);
}
}
// Check if running older configuration and update automatically if so
else if(settings.Settings.PluginPreviouslyInstalledVersion != currentVersion)
{
settings.Settings.PluginPreviouslyInstalledVersion = currentVersion;
settings.EndEdit();
}
}
public override void OnApplicationStopped(OnApplicationStoppedEventArgs args)
{
// Add code to be executed when Playnite is shutting down.
}
public override void OnLibraryUpdated(OnLibraryUpdatedEventArgs args)
{
// Add code to be executed when library is updated.
}
public override ISettings GetSettings(bool firstRunSettings)
{
return settings;
}
public override UserControl GetSettingsView(bool firstRunSettings)
{
return new EmudeckPlayniteSettingsView();
}
}
}