Skip to content

Commit

Permalink
Merge pull request #79 from RetroDriven/JT-Beta-Key-Check
Browse files Browse the repository at this point in the history
Jt beta key check
  • Loading branch information
RetroDriven authored Nov 20, 2023
2 parents 1e3b9fe + 6ffe327 commit dff6704
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 32 deletions.
18 changes: 17 additions & 1 deletion Controls/Manage_Cores/ManageCores.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 17 additions & 6 deletions Controls/Update_Pocket/Update_Pocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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 != "")
{
Expand Down
3 changes: 2 additions & 1 deletion Forms/Main/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Forms/Main/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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)
{

}
}
}
2 changes: 2 additions & 0 deletions Lib/Updater/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
2 changes: 1 addition & 1 deletion Pocket_Updater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Version>1.5.8</Version>
<Version>1.5.9</Version>
<RootNamespace>Pocket_Updater</RootNamespace>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
Expand Down
42 changes: 30 additions & 12 deletions lib/Updater/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 @@ -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<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 @@ -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<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 @@ -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<string>);
skippedAssets.AddRange(results["skipped"] as List<string>);
if((bool)results["missingBetaKey"]) {
missingBetaKeys.Add(core.identifier);
}
_writeMessage("Installation complete.");
Divide();

Expand All @@ -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);
}
Expand Down Expand Up @@ -354,7 +366,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 @@ -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<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 @@ -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);
}

Expand Down Expand Up @@ -521,4 +538,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; }
}
53 changes: 43 additions & 10 deletions lib/Updater/models/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -155,14 +156,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 @@ -208,17 +211,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 @@ -237,6 +242,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 @@ -257,9 +266,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 @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit dff6704

Please sign in to comment.