diff --git a/Program.cs b/Program.cs index b19d7d9e..0c82a7be 100644 --- a/Program.cs +++ b/Program.cs @@ -15,12 +15,12 @@ private static async Task Main(string[] args) try { string location = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; string? path = Path.GetDirectoryName(location); - bool extractAll = false; bool coreSelector = false; bool preservePlatformsFolder = false; bool forceUpdate = false; bool forceInstanceGenerator = false; + Parser.Default.ParseArguments(args) .WithParsed(o => { @@ -29,10 +29,6 @@ private static async Task Main(string[] args) path = o.InstallPath; cliMode = true; } - if(o.ExtractAll) { - extractAll = true; - cliMode = true; - } if(o.CoreSelector) { coreSelector = true; cliMode = true; @@ -87,6 +83,7 @@ private static async Task Main(string[] args) updater.DeleteSkippedCores(settings.GetConfig().delete_skipped_cores); updater.SetGithubApiKey(settings.GetConfig().github_token); updater.DownloadFirmware(settings.GetConfig().download_firmware); + updater.RenameJotegoCores(settings.GetConfig().fix_jt_names); updater.StatusUpdated += updater_StatusUpdated; updater.UpdateProcessComplete += updater_UpdateProcessComplete; updater.DownloadAssets(settings.GetConfig().download_assets); @@ -202,6 +199,7 @@ static void SetUpdaterFlags(ref PocketCoreUpdater updater, ref SettingsManager s updater.SetGithubApiKey(settings.GetConfig().github_token); updater.DownloadFirmware(settings.GetConfig().download_firmware); updater.DownloadAssets(settings.GetConfig().download_assets); + updater.RenameJotegoCores(settings.GetConfig().fix_jt_names); } static async Task RunInstanceGenerator(PocketCoreUpdater updater, bool force = false) @@ -297,6 +295,19 @@ static void RunConfigWizard(ref SettingsManager settings) } Console.WriteLine(""); valid = false; + while(!valid) { + Console.Write("\nAutomatically rename Jotego cores during 'Update All'?[Y/n] "); + response = Console.ReadKey(false).Key; + if (response == ConsoleKey.N) { + settings.GetConfig().fix_jt_names = false; + valid = true; + } else if (response == ConsoleKey.Y || response == ConsoleKey.Enter) { + settings.GetConfig().fix_jt_names = true; + valid = true; + } + } + Console.WriteLine(""); + valid = false; while(!valid) { Console.Write("\nPreserve 'Platforms' folder during 'Update All'?[y/N] "); response = Console.ReadKey(false).Key; @@ -587,7 +598,7 @@ private static void AskAboutNewCores(ref SettingsManager settings, bool force = "Select Cores", "Download Platform Image Packs", "Generate Instance JSON Files", - "Configuration Wizard", + "Settings", "Exit" }; } @@ -599,9 +610,6 @@ public class Options [Option('p', "path", HelpText = "Absolute path to install location", Required = false)] public string? InstallPath { get; set; } - [Option ('a', "all", Required = false, HelpText = "Extract all release assets, instead of just ones containing openFPGA cores.")] - public bool ExtractAll { get; set; } - [Option ('c', "coreselector", Required = false, HelpText = "Run the core selector.")] public bool CoreSelector { get; set; } diff --git a/Updater.cs b/Updater.cs index 23581398..c6799b35 100644 --- a/Updater.cs +++ b/Updater.cs @@ -25,6 +25,7 @@ public class PocketCoreUpdater : Base private bool _downloadFirmare = true; private bool _deleteSkippedCores = true; private bool _useConsole = false; + private bool _renameJotegoCores = true; /// /// The directory where fpga cores will be installed and updated into /// @@ -41,6 +42,8 @@ public class PocketCoreUpdater : Base private archiveorg.Archive _archiveFiles; private string[] _blacklist; + private Dictionary _platformFiles = new Dictionary(); + /// /// Constructor /// @@ -60,14 +63,28 @@ public PocketCoreUpdater(string updateDirectory, string? settingsPath = null) public async Task Initialize() { - + await LoadPlatformFiles(); await LoadCores(); - // await LoadDependencies(); LoadSettings(); await LoadArchive(); await LoadBlacklist(); } + private async Task LoadPlatformFiles() + { + List files = await GithubApi.GetFiles("dyreschlock", "pocket-platform-images", "arcade/Platforms"); + Dictionary platformFiles = new Dictionary(); + foreach(Github.File file in files) { + string url = file.download_url; + string filename = file.name; + if (filename.EndsWith(".json")) { + string platform = Path.GetFileNameWithoutExtension(filename); + platformFiles.Add(platform, url); + } + } + _platformFiles = platformFiles; + } + private async Task LoadArchive() { _archiveFiles = await ArchiveService.GetFiles(this._settingsManager.GetConfig().archive_name); @@ -88,7 +105,6 @@ public async Task LoadCores() foreach(Core core in _cores) { core.StatusUpdated += updater_StatusUpdated; //attach handler to bubble event up } - // await LoadNonAPICores(); } public async Task LoadNonAPICores() @@ -112,6 +128,11 @@ public void PrintToConsole(bool set) _useConsole = set; } + public void RenameJotegoCores(bool set) + { + _renameJotegoCores = set; + } + /// /// Turn on/off the automatic BIOS downloader /// @@ -218,6 +239,7 @@ public async Task RunUpdates() results = await core.DownloadAssets(); installedAssets.AddRange(results["installed"]); skippedAssets.AddRange(results["skipped"]); + await JotegoRename(core); Divide(); continue; } @@ -235,6 +257,7 @@ public async Task RunUpdates() _writeMessage("Updating core"); } else { results = await core.DownloadAssets(); + await JotegoRename(core); installedAssets.AddRange(results["installed"]); skippedAssets.AddRange(results["skipped"]); _writeMessage("Up to date. Skipping core"); @@ -252,6 +275,7 @@ public async Task RunUpdates() summary.Add("platform", core.platform.name); installed.Add(summary); } + await JotegoRename(core); results = await core.DownloadAssets(); installedAssets.AddRange(results["installed"]); skippedAssets.AddRange(results["skipped"]); @@ -278,6 +302,22 @@ public async Task RunUpdates() OnUpdateProcessComplete(args); } + private async Task JotegoRename(Core core) + { + if(_renameJotegoCores && core.identifier.Contains("jotego")) { + core.platform_id = core.identifier.Split('.')[1]; //whatever + string path = Path.Combine(UpdateDirectory, "Platforms", core.platform_id + ".json"); + string json = File.ReadAllText(path); + Dictionary data = JsonSerializer.Deserialize>(json); + Platform platform = data["platform"]; + if(_platformFiles.ContainsKey(core.platform_id) && platform.name == core.platform_id) { + _writeMessage("Updating JT Platform Name..."); + await HttpHelper.DownloadFileAsync(_platformFiles[core.platform_id], path); + _writeMessage("Complete"); + } + } + } + public async Task RunAssetDownloader(string? id = null) { List installedAssets = new List(); diff --git a/models/Settings/Config.cs b/models/Settings/Config.cs index 4b129553..b059bffd 100644 --- a/models/Settings/Config.cs +++ b/models/Settings/Config.cs @@ -12,6 +12,7 @@ public class Config public string? download_new_cores { get; set; } public bool build_instance_jsons { get; set; } public bool crc_check { get; set; } + public bool fix_jt_names { get; set; } public Config() { @@ -24,5 +25,6 @@ public Config() download_new_cores = null; build_instance_jsons = true; crc_check = true; + fix_jt_names = true; } } \ No newline at end of file diff --git a/pocket_updater.csproj b/pocket_updater.csproj index 3937a465..e9c5d82a 100644 --- a/pocket_updater.csproj +++ b/pocket_updater.csproj @@ -6,7 +6,7 @@ net6.0 enable enable - 2.19.2 + 2.20.0 Keep your Analogue Pocket up to date 2023 Matt Pannella Matt Pannella diff --git a/services/GithubApiService.cs b/services/GithubApiService.cs index c2c12384..b479acdf 100644 --- a/services/GithubApiService.cs +++ b/services/GithubApiService.cs @@ -53,6 +53,16 @@ public static class GithubApi return file; } + public static async Task?> GetFiles(string user, string repository, string path, string? token = "") + { + string url = String.Format(CONTENTS, user, repository, path); + + var responseBody = await CallAPI(url, token); + List? files = JsonSerializer.Deserialize>(responseBody); + + return files; + } + private static async Task CallAPI(string url, string? token = "") { var client = new HttpClient();