diff --git a/src/Updater.cs b/src/Updater.cs index 47fb45d..1f12166 100644 --- a/src/Updater.cs +++ b/src/Updater.cs @@ -245,6 +245,8 @@ public async Task RunUpdates(string? id = null) _writeMessage("Checking Core: " + name); var mostRecentRelease = core.version; + await core.ReplaceCheck(); + if(mostRecentRelease == null) { _writeMessage("No releases found. Skipping"); await CopyBetaKey(core); diff --git a/src/models/Core.cs b/src/models/Core.cs index 3fdad85..e1f2ca0 100644 --- a/src/models/Core.cs +++ b/src/models/Core.cs @@ -14,8 +14,9 @@ public class Core : Base public string platform_id { get; set; } public Sponsor? sponsor { get; set; } public string? download_url { get; set; } - public string? date_release { get; set; } + public string? release_date { get; set; } public string? version { get; set; } + public string[]? replaces { get; set; } public string? betaSlotId = null; public bool requires_license { get; set; } = false; @@ -292,6 +293,28 @@ public async Task> DownloadAssets() return config; } + public Updater.Substitute[]? getSubstitutes() + { + checkUpdateDirectory(); + string file = Path.Combine(Factory.GetGlobals().UpdateDirectory, "Cores", this.identifier, "updaters.json"); + if (!File.Exists(file)) + { + return null; + } + string json = File.ReadAllText(file); + var options = new JsonSerializerOptions() + { + AllowTrailingCommas = true + }; + Updater.Updaters? config = JsonSerializer.Deserialize(json, options); + + if (config == null) { + return null; + } + + return config.previous; + } + public bool isInstalled() { checkUpdateDirectory(); @@ -504,6 +527,19 @@ public bool JTBetaCheck() return check; } + + public async Task ReplaceCheck() + { + if (replaces != null) { + foreach(string id in replaces) { + Core c = new Core(){identifier = id}; + if (c.isInstalled()) { + c.Uninstall(); + _writeMessage($"Uninstalled {id}. It was replaced by this core."); + } + } + } + } } public class myReverserClass : IComparer { diff --git a/src/models/Updater/Substitute.cs b/src/models/Updater/Substitute.cs new file mode 100644 index 0000000..130fb19 --- /dev/null +++ b/src/models/Updater/Substitute.cs @@ -0,0 +1,8 @@ +namespace pannella.analoguepocket.Updater; + +public class Substitute +{ + public string? platform{ get; set; } + public string? author { get; set; } + public string? shortname { get; set; } +} \ No newline at end of file diff --git a/src/models/Updater/Updaters.cs b/src/models/Updater/Updaters.cs new file mode 100644 index 0000000..42007f8 --- /dev/null +++ b/src/models/Updater/Updaters.cs @@ -0,0 +1,6 @@ +namespace pannella.analoguepocket.Updater; + +public class Updaters +{ + public Substitute[]? previous; +} \ No newline at end of file