diff --git a/Controls/Manage_Cores/ManageCores.cs b/Controls/Manage_Cores/ManageCores.cs index baace70..82c3254 100644 --- a/Controls/Manage_Cores/ManageCores.cs +++ b/Controls/Manage_Cores/ManageCores.cs @@ -11,6 +11,7 @@ using pannella.analoguepocket; using System.Text.Json; using Pocket_Updater.Forms.Message_Box; +using System.Xml.Linq; namespace Pocket_Updater.Controls.Manage_Cores { @@ -137,7 +138,22 @@ public async Task LoadCores() string Core_Author = Identifier.Substring(0, (Identifier.Length - 1)); //array containing the data for the 3 columns - object[] rows = { !_settingsManager.GetCoreSettings(core.identifier).skip, core.platform.name, Core_Author }; + //the core platform name from the api + var platform = core.ReadPlatformFile(); + + //readt he platform json file + var name = core.platform.name; + + //if it finds one, use the name from there instead + if (platform != null) + { + name = platform.name; + } + if (core.requires_license) + { + name += " (Beta Key Required from Patreon)"; + } + object[] rows = { !_settingsManager.GetCoreSettings(core.identifier).skip, name, Core_Author }; int index = dataGridView1.Rows.Add(rows); dataGridView1.Rows[index].Tag = core.identifier; diff --git a/Controls/Update_Pocket/Update_Pocket.cs b/Controls/Update_Pocket/Update_Pocket.cs index 9bff077..5e79eb5 100644 --- a/Controls/Update_Pocket/Update_Pocket.cs +++ b/Controls/Update_Pocket/Update_Pocket.cs @@ -262,7 +262,7 @@ private void _updater_UpdateProcessComplete(object? sender, UpdateProcessComplet { //No Updates Found - if (e.InstalledCores.Count == 0 && e.InstalledAssets.Count == 0 && e.FirmwareUpdated == "") + if (e.InstalledCores.Count == 0 && e.InstalledAssets.Count == 0 && e.FirmwareUpdated == "" && e.MissingBetaKeys.Count == 0) { //Summary.Close(); Message_Box form = new Message_Box(); @@ -277,12 +277,8 @@ private void _updater_UpdateProcessComplete(object? sender, UpdateProcessComplet } //Updates Found - if (e.InstalledCores.Count > 0 || e.InstalledAssets.Count > 0 || e.FirmwareUpdated != "") + if (e.InstalledCores.Count > 0 || e.InstalledAssets.Count > 0 || e.FirmwareUpdated != "" || e.MissingBetaKeys.Count > 0) { - //Message_Box form = new Message_Box(); - //form.label1.Text = "Updates Complete!"; - //form.Show(); - //Status.Close(); Summary.Show(); comboBox1.Enabled = true; @@ -338,7 +334,22 @@ private void _updater_UpdateProcessComplete(object? sender, UpdateProcessComplet } Summary.textBox1.AppendText(Environment.NewLine); } + //JT Beta Key + if (e.MissingBetaKeys.Count > 0) + { + Summary.textBox1.AppendText(Environment.NewLine); + Summary.textBox1.AppendText("Missing/Incorrect JT Beta Key For:"); + Summary.textBox1.AppendText(Environment.NewLine); + Summary.textBox1.AppendText("-----------------------"); + Summary.textBox1.AppendText(Environment.NewLine); + foreach (string core in e.MissingBetaKeys) + { + Summary.textBox1.AppendText(core); + Summary.textBox1.AppendText(Environment.NewLine); + } + Summary.textBox1.AppendText(Environment.NewLine); + } //Firmware Installed if (e.FirmwareUpdated != "") { diff --git a/Forms/Main/Form1.Designer.cs b/Forms/Main/Form1.Designer.cs index 48ae69f..3b7df5a 100644 --- a/Forms/Main/Form1.Designer.cs +++ b/Forms/Main/Form1.Designer.cs @@ -133,7 +133,7 @@ private void InitializeComponent() guna2HtmlLabel1.Name = "guna2HtmlLabel1"; guna2HtmlLabel1.Size = new Size(212, 30); guna2HtmlLabel1.TabIndex = 0; - guna2HtmlLabel1.Text = "Pocket Updater v1.5.8"; + guna2HtmlLabel1.Text = "Pocket Updater v1.5.9"; // // guna2ControlBox1 // @@ -493,6 +493,7 @@ private void InitializeComponent() update_Pocket1.Pocket_Drive = null; update_Pocket1.Size = new Size(1136, 616); update_Pocket1.TabIndex = 0; + update_Pocket1.Load += update_Pocket1_Load; // // image_Packs1 // diff --git a/Forms/Main/Form1.cs b/Forms/Main/Form1.cs index 24241c7..9f75ca4 100644 --- a/Forms/Main/Form1.cs +++ b/Forms/Main/Form1.cs @@ -9,7 +9,7 @@ namespace Pocket_Updater { public partial class Form1 : Form { - private const string VERSION = "1.5.8"; + private const string VERSION = "1.5.9"; private const string API_URL = "https://api.github.com/repos/RetroDriven/Pocket_Updater/releases"; private const string RELEASE_URL = "https://github.com/RetroDriven/Pocket_Updater/releases/latest"; @@ -158,5 +158,10 @@ private void About_Click(object sender, EventArgs e) Hide_Controls(); about1.Visible = true; } + + private void update_Pocket1_Load(object sender, EventArgs e) + { + + } } } diff --git a/Lib/Updater/models/Analogue/AnalogueDataSlot.cs b/Lib/Updater/models/Analogue/AnalogueDataSlot.cs index 4b86c1e..a4854e2 100644 --- a/Lib/Updater/models/Analogue/AnalogueDataSlot.cs +++ b/Lib/Updater/models/Analogue/AnalogueDataSlot.cs @@ -13,6 +13,8 @@ public class DataSlot public string[]? alternate_filenames{ get; set; } + public string? md5 { get; set; } + public bool isCoreSpecific() { if(parameters == null) { diff --git a/Pocket_Updater.csproj b/Pocket_Updater.csproj index 7c47e84..e632a78 100644 --- a/Pocket_Updater.csproj +++ b/Pocket_Updater.csproj @@ -3,7 +3,7 @@ WinExe net6.0-windows - 1.5.8 + 1.5.9 Pocket_Updater enable true diff --git a/lib/Updater/Updater.cs b/lib/Updater/Updater.cs index 37a611a..1469443 100644 --- a/lib/Updater/Updater.cs +++ b/lib/Updater/Updater.cs @@ -91,6 +91,7 @@ private async Task LoadPlatformFiles() private async Task LoadArchive() { + _writeMessage("Loading Assets Index..."); if(Factory.GetGlobals().SettingsManager.GetConfig().use_custom_archive) { var custom = Factory.GetGlobals().SettingsManager.GetConfig().custom_archive; Uri baseUrl = new Uri(custom["url"]); @@ -203,7 +204,8 @@ public async Task RunUpdates(string? id = null) List> installed = new List>(); List installedAssets = new List(); List skippedAssets = new List(); - Dictionary> results = new Dictionary>(); + List missingBetaKeys = new List(); + Dictionary results = new Dictionary(); string firmwareDownloaded = ""; if(Factory.GetGlobals().Cores == null) { throw new Exception("Must initialize updater before running update process"); @@ -245,11 +247,14 @@ public async Task RunUpdates(string? id = null) if(mostRecentRelease == null) { _writeMessage("No releases found. Skipping"); + await CopyBetaKey(core); results = await core.DownloadAssets(); - installedAssets.AddRange(results["installed"]); - skippedAssets.AddRange(results["skipped"]); + installedAssets.AddRange(results["installed"] as List); + skippedAssets.AddRange(results["skipped"] as List); + if((bool)results["missingBetaKey"]) { + missingBetaKeys.Add(core.identifier); + } await JotegoRename(core); - await CopyBetaKey(core); Divide(); continue; } @@ -266,11 +271,14 @@ public async Task RunUpdates(string? id = null) if (mostRecentRelease != localVersion){ _writeMessage("Updating core"); } else { + await CopyBetaKey(core); results = await core.DownloadAssets(); await JotegoRename(core); - await CopyBetaKey(core); - installedAssets.AddRange(results["installed"]); - skippedAssets.AddRange(results["skipped"]); + installedAssets.AddRange(results["installed"] as List); + skippedAssets.AddRange(results["skipped"] as List); + if((bool)results["missingBetaKey"]) { + missingBetaKeys.Add(core.identifier); + } _writeMessage("Up to date. Skipping core"); Divide(); continue; @@ -289,8 +297,11 @@ public async Task RunUpdates(string? id = null) await JotegoRename(core); await CopyBetaKey(core); results = await core.DownloadAssets(); - installedAssets.AddRange(results["installed"]); - skippedAssets.AddRange(results["skipped"]); + installedAssets.AddRange(results["installed"] as List); + skippedAssets.AddRange(results["skipped"] as List); + if((bool)results["missingBetaKey"]) { + missingBetaKeys.Add(core.identifier); + } _writeMessage("Installation complete."); Divide(); @@ -305,6 +316,7 @@ public async Task RunUpdates(string? id = null) args.InstalledCores = installed; args.InstalledAssets = installedAssets; args.SkippedAssets = skippedAssets; + args.MissingBetaKeys = missingBetaKeys; args.FirmwareUpdated = firmwareDownloaded; OnUpdateProcessComplete(args); } @@ -354,7 +366,8 @@ public async Task RunAssetDownloader(string? id = null) { List installedAssets = new List(); List skippedAssets = new List(); - Dictionary> results = new Dictionary>(); + List missingBetaKeys = new List(); + Dictionary results = new Dictionary(); if(Factory.GetGlobals().Cores == null) { throw new Exception("Must initialize updater before running update process"); } @@ -377,8 +390,11 @@ public async Task RunAssetDownloader(string? id = null) } _writeMessage(core.identifier); results = await core.DownloadAssets(); - installedAssets.AddRange(results["installed"]); - skippedAssets.AddRange(results["skipped"]); + installedAssets.AddRange(results["installed"] as List); + skippedAssets.AddRange(results["skipped"] as List); + if((bool)results["missingBetaKey"]) { + missingBetaKeys.Add(core.identifier); + } Divide(); } catch(Exception e) { _writeMessage("Uh oh something went wrong."); @@ -390,6 +406,7 @@ public async Task RunAssetDownloader(string? id = null) args.Message = "All Done"; args.InstalledAssets = installedAssets; args.SkippedAssets = skippedAssets; + args.MissingBetaKeys = missingBetaKeys; OnUpdateProcessComplete(args); } @@ -521,4 +538,5 @@ public class UpdateProcessCompleteEventArgs : EventArgs public List InstalledAssets { get; set; } public List SkippedAssets { get; set; } public string FirmwareUpdated { get; set; } = ""; + public List MissingBetaKeys { get; set; } } diff --git a/lib/Updater/models/Core.cs b/lib/Updater/models/Core.cs index d7fa471..fa7fc39 100644 --- a/lib/Updater/models/Core.cs +++ b/lib/Updater/models/Core.cs @@ -16,6 +16,7 @@ public class Core : Base public string? download_url { get; set; } public string? date_release { get; set; } public string? version { get; set; } + public string? betaSlotId = null; public bool requires_license { get; set; } = false; @@ -155,14 +156,16 @@ public bool UpdatePlatform(string title, string category = null) return true; } - public async Task>> DownloadAssets() + public async Task> DownloadAssets() { List installed = new List(); List skipped = new List(); + bool missingBetaKey = false; if(!downloadAssets || !Factory.GetGlobals().SettingsManager.GetCoreSettings(this.identifier).download_assets) { - return new Dictionary>{ + return new Dictionary{ {"installed", installed }, - {"skipped", skipped } + {"skipped", skipped }, + {"missingBetaKey", missingBetaKey } }; } checkUpdateDirectory(); @@ -208,17 +211,19 @@ public async Task>> DownloadAssets() } if(this.identifier == "Mazamars312.NeoGeo" || this.identifier == "Mazamars312.NeoGeo_Overdrive") { - return new Dictionary>{ + return new Dictionary{ {"installed", installed }, - {"skipped", skipped } + {"skipped", skipped }, + {"missingBetaKey", false } }; //nah } if(CheckInstancePackager()) { BuildInstanceJSONs(); - return new Dictionary>{ + return new Dictionary{ {"installed", installed }, - {"skipped", skipped } + {"skipped", skipped }, + {"missingBetaKey", missingBetaKey } }; } @@ -237,6 +242,10 @@ public async Task>> DownloadAssets() if(instance.instance.data_slots.Length > 0) { string data_path = instance.instance.data_path; foreach(Analogue.DataSlot slot in instance.instance.data_slots) { + if(!CheckBetaMD5(slot, info.metadata.platform_ids[0])) { + _writeMessage("Invalid or missing beta key."); + missingBetaKey = true; + } if(!Factory.GetGlobals().Blacklist.Contains(slot.filename) && !slot.filename.EndsWith(".sav")) { string path = Path.Combine(UpdateDirectory, "Assets", info.metadata.platform_ids[0], "common", data_path, slot.filename); if(File.Exists(path) && CheckCRC(path)) { @@ -257,9 +266,10 @@ public async Task>> DownloadAssets() } } } - Dictionary> results = new Dictionary>{ + Dictionary results = new Dictionary{ {"installed", installed }, - {"skipped", skipped } + {"skipped", skipped }, + {"missingBetaKey", missingBetaKey } }; return results; } @@ -352,6 +362,22 @@ private bool CheckCRC(string filepath) return false; } + //return false if a beta ley is required and missing or wrong + private bool CheckBetaMD5(Analogue.DataSlot slot, string platform) + { + if(slot.md5 != null && (betaSlotId != null && slot.id == betaSlotId)) { + string UpdateDirectory = Factory.GetGlobals().UpdateDirectory; + string path = Path.Combine(UpdateDirectory, "Assets", platform); + string filepath = Path.Combine(path, "common", slot.filename); + if(!File.Exists(filepath)) { + return false; + } + return Util.CompareChecksum(filepath, slot.md5, Util.HashTypes.MD5); + } + + return true; + } + public void BuildInstanceJSONs(bool overwrite = true) { if(!buildInstances) { @@ -470,9 +496,16 @@ public Analogue.DataJSON ReadDataJSON() public bool JTBetaCheck() { var data = ReadDataJSON(); - return data.data.data_slots.Any(x=>x.name=="JTBETA"); + bool check = data.data.data_slots.Any(x=>x.name=="JTBETA"); + + if (check) { + betaSlotId = data.data.data_slots.Where(x=>x.name=="JTBETA").First().id; + } + + return check; } } + public class myReverserClass : IComparer { // Calls CaseInsensitiveComparer.Compare with the parameters reversed.