Skip to content

Commit

Permalink
Merge branch 'main' into core-substitute
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpannella authored Nov 24, 2023
2 parents 0a9f188 + 4d81402 commit c063009
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 60 deletions.
35 changes: 0 additions & 35 deletions blacklist.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,6 @@
"019.BIN",
"avoxrom.bin",
"avoxee.bin",
"captcmmb.rom",
"sf2m4.rom",
"sf2thdr2.rom",
"sf2amf2.rom",
"sf2dongb.rom",
"sf2m2.rom",
"sf2ceblp.rom",
"sf2m5.rom",
"sf2rk.rom",
"sf2m7.rom",
"sf2ef.rom",
"sf2accp2.rom",
"sf2amf.rom",
"sf2amf3.rom",
"varthb2.rom",
"sf2thndr.rom",
"sf2m8.rom",
"sf2koryu.rom",
"sf2ue.rom",
"sf2m6.rom",
"sf2dkot2.rom",
"sf2rules.rom",
"sf2ebbl2.rom",
"sf2bhh.rom",
"sf2ebbl.rom",
"pang3b3.rom",
"sf2rb.rom",
"knighsb2.rom",
"sf2stt.rom",
"sf2ee.rom",
"sf2yyc.rom",
"pang3b2.rom",
"sf2ebbl3.rom",
"sf2rb2.rom",
"sf2um.rom",
"bios_1_0_usa.pce",
"savestate.ss",
"MegaAGS-Pocket.hdf",
Expand Down
2 changes: 1 addition & 1 deletion pocket_updater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>2.36.1</Version>
<Version>2.37.0</Version>
<Description>Keep your Analogue Pocket up to date</Description>
<Copyright>2023 Matt Pannella</Copyright>
<Authors>Matt Pannella</Authors>
Expand Down
17 changes: 15 additions & 2 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,14 @@ static async Task RunCoreSelector(List<Core> cores, string message = "Select you
}
foreach(Core core in cores) {
current++;
if ((current <= (offset + pageSize)) && (current > offset)) {
if ((current <= (offset + pageSize)) && (current >= offset)) {
var coreSettings = settings.GetCoreSettings(core.identifier);
var selected = !coreSettings.skip;
var title = settingsMenuItem(core.identifier, selected);
var name = core.identifier;
if (core.requires_license) {
name += " (Requires beta access)";
}
var title = settingsMenuItem(name, selected);
menu.Add(title, (thisMenu) => {
selected = !selected;
if (!selected) {
Expand Down Expand Up @@ -543,6 +547,13 @@ static void updater_UpdateProcessComplete(object sender, UpdateProcessCompleteEv
Console.WriteLine(e.FirmwareUpdated);
Console.WriteLine("");
}
if(e.MissingBetaKeys.Count > 0) {
Console.WriteLine("Missing or incorrect Beta Key for the following cores:");
foreach(string core in e.MissingBetaKeys) {
Console.WriteLine(core);
}
Console.WriteLine("");
}
ShowSponsorLinks();
FunFacts();
}
Expand Down Expand Up @@ -667,6 +678,8 @@ async static Task<bool> CheckVersion(string path)
Console.WriteLine("Download complete.");
Console.WriteLine(saveLocation);
Console.WriteLine("Go to " + releases[0].html_url + " for a change log");
} else {
Console.WriteLine("Up to date.");
}
return check;
}
Expand Down
42 changes: 30 additions & 12 deletions src/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
Expand Down Expand Up @@ -203,7 +204,8 @@ public async Task RunUpdates(string? id = null)
List<Dictionary<string, string>> installed = new List<Dictionary<string, string>>();
List<string> installedAssets = new List<string>();
List<string> skippedAssets = new List<string>();
Dictionary<string, List<string>> results = new Dictionary<string, List<string>>();
List<string> missingBetaKeys = new List<string>();
Dictionary<string, Object> results = new Dictionary<string, Object>();
string firmwareDownloaded = "";
if(Factory.GetGlobals().Cores == null) {
throw new Exception("Must initialize updater before running update process");
Expand Down Expand Up @@ -247,11 +249,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<string>);
skippedAssets.AddRange(results["skipped"] as List<string>);
if((bool)results["missingBetaKey"]) {
missingBetaKeys.Add(core.identifier);
}
await JotegoRename(core);
await CopyBetaKey(core);
Divide();
continue;
}
Expand All @@ -268,11 +273,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<string>);
skippedAssets.AddRange(results["skipped"] as List<string>);
if((bool)results["missingBetaKey"]) {
missingBetaKeys.Add(core.identifier);
}
_writeMessage("Up to date. Skipping core");
Divide();
continue;
Expand All @@ -291,8 +299,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<string>);
skippedAssets.AddRange(results["skipped"] as List<string>);
if((bool)results["missingBetaKey"]) {
missingBetaKeys.Add(core.identifier);
}
_writeMessage("Installation complete.");
Divide();

Expand All @@ -307,6 +318,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);
}
Expand Down Expand Up @@ -356,7 +368,8 @@ public async Task RunAssetDownloader(string? id = null)
{
List<string> installedAssets = new List<string>();
List<string> skippedAssets = new List<string>();
Dictionary<string, List<string>> results = new Dictionary<string, List<string>>();
List<string> missingBetaKeys = new List<string>();
Dictionary<string, Object> results = new Dictionary<string, Object>();
if(Factory.GetGlobals().Cores == null) {
throw new Exception("Must initialize updater before running update process");
}
Expand All @@ -379,8 +392,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<string>);
skippedAssets.AddRange(results["skipped"] as List<string>);
if((bool)results["missingBetaKey"]) {
missingBetaKeys.Add(core.identifier);
}
Divide();
} catch(Exception e) {
_writeMessage("Uh oh something went wrong.");
Expand All @@ -392,6 +408,7 @@ public async Task RunAssetDownloader(string? id = null)
args.Message = "All Done";
args.InstalledAssets = installedAssets;
args.SkippedAssets = skippedAssets;
args.MissingBetaKeys = missingBetaKeys;
OnUpdateProcessComplete(args);
}

Expand Down Expand Up @@ -523,4 +540,5 @@ public class UpdateProcessCompleteEventArgs : EventArgs
public List<string> InstalledAssets { get; set; }
public List<string> SkippedAssets { get; set; }
public string FirmwareUpdated { get; set; } = "";
public List<string> MissingBetaKeys { get; set; }
}
2 changes: 2 additions & 0 deletions src/models/Analogue/AnalogueDataSlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class DataSlot

public string[]? alternate_filenames{ get; set; }

public string? md5 { get; set; }

public bool isCoreSpecific()
{
if(parameters == null) {
Expand Down
53 changes: 43 additions & 10 deletions src/models/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Core : Base
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;

Expand Down Expand Up @@ -156,14 +157,16 @@ public bool UpdatePlatform(string title, string category = null)
return true;
}

public async Task<Dictionary<string, List<string>>> DownloadAssets()
public async Task<Dictionary<string, Object>> DownloadAssets()
{
List<string> installed = new List<string>();
List<string> skipped = new List<string>();
bool missingBetaKey = false;
if(!downloadAssets || !Factory.GetGlobals().SettingsManager.GetCoreSettings(this.identifier).download_assets) {
return new Dictionary<string, List<string>>{
return new Dictionary<string, Object>{
{"installed", installed },
{"skipped", skipped }
{"skipped", skipped },
{"missingBetaKey", missingBetaKey }
};
}
checkUpdateDirectory();
Expand Down Expand Up @@ -209,17 +212,19 @@ public async Task<Dictionary<string, List<string>>> DownloadAssets()
}

if(this.identifier == "Mazamars312.NeoGeo" || this.identifier == "Mazamars312.NeoGeo_Overdrive") {
return new Dictionary<string, List<string>>{
return new Dictionary<string, Object>{
{"installed", installed },
{"skipped", skipped }
{"skipped", skipped },
{"missingBetaKey", false }
}; //nah
}

if(CheckInstancePackager()) {
BuildInstanceJSONs();
return new Dictionary<string, List<string>>{
return new Dictionary<string, Object>{
{"installed", installed },
{"skipped", skipped }
{"skipped", skipped },
{"missingBetaKey", missingBetaKey }
};
}

Expand All @@ -238,6 +243,10 @@ public async Task<Dictionary<string, List<string>>> 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)) {
Expand All @@ -258,9 +267,10 @@ public async Task<Dictionary<string, List<string>>> DownloadAssets()
}
}
}
Dictionary<string, List<string>> results = new Dictionary<string, List<string>>{
Dictionary<string, Object> results = new Dictionary<string, Object>{
{"installed", installed },
{"skipped", skipped }
{"skipped", skipped },
{"missingBetaKey", missingBetaKey }
};
return results;
}
Expand Down Expand Up @@ -375,6 +385,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) {
Expand Down Expand Up @@ -493,7 +519,13 @@ 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 async Task ReplaceCheck()
Expand All @@ -509,6 +541,7 @@ public async Task ReplaceCheck()
}
}
}

public class myReverserClass : IComparer {

// Calls CaseInsensitiveComparer.Compare with the parameters reversed.
Expand Down

0 comments on commit c063009

Please sign in to comment.