forked from RetroDriven/Pocket_Updater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoreManager.cs
96 lines (85 loc) · 2.68 KB
/
CoreManager.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
using System;
using System.Text.Json;
using System.IO;
using pannella.analoguepocket;
namespace Pocket_Updater
{
public class CoreManager
{
private pannella.analoguepocket.Settings _settings;
private string _settingsFile;
private string _coresFile;
private List<Core> _cores;
public CoreManager(string settingsFile, string coresFile)
{
_settings = new pannella.analoguepocket.Settings();
if (File.Exists(settingsFile))
{
string json = File.ReadAllText(settingsFile);
_settings = JsonSerializer.Deserialize<pannella.analoguepocket.Settings>(json);
}
_settingsFile = settingsFile;
if(File.Exists(coresFile))
{
_coresFile = coresFile;
string json = File.ReadAllText(coresFile);
_cores = JsonSerializer.Deserialize<List<Core>>(json);
}
else
{
throw new Exception("Unable to find cores json file.");
}
}
public bool SaveSettings()
{
var options = new JsonSerializerOptions { WriteIndented = true };
File.WriteAllText(_settingsFile, JsonSerializer.Serialize(_settings, options));
return true;
}
public void DisableCore(string platform)
{
if(_settings.coreSettings.ContainsKey(platform))
{
_settings.coreSettings[platform].skip = true;
}
else
{
CoreSettings core = new CoreSettings();
core.skip = true;
_settings.coreSettings.Add(platform, core);
}
}
public void EnableCore(string platform)
{
if (_settings.coreSettings.ContainsKey(platform))
{
_settings.coreSettings[platform].skip = false;
}
else
{
CoreSettings core = new CoreSettings();
core.skip = false;
_settings.coreSettings.Add(platform, core);
}
}
public void UpdateCore(CoreSettings core, string platform)
{
if (_settings.coreSettings.ContainsKey(platform))
{
_settings.coreSettings[platform] = core;
}
else
{
_settings.coreSettings.Add(platform, core);
}
}
public Dictionary<string, CoreSettings> GetCoreSettings()
{
return _settings.coreSettings;
}
public List<Core> GetCores()
{
return _cores;
}
}
}