Skip to content

Commit

Permalink
Added support for downloading the Game & Watch ROMs (mattpannella#235)
Browse files Browse the repository at this point in the history
GlobalHelper:
- made the ArchiveFiles property populate on first use.
- added GameAndWatchArchiveFiles
Archive:
- changed files to be a List<> vs an array so items could be easily removed
- updated some variable names to camel casing
Config:
-added new config setting to set the archive name for game and watch
Program
- awaited the Global Helper Initialize as it wasn't done populating when testing updating the game and watch core
- removed commented out code
Core:
- moved ad hoc string concats to string interpolation
- removed unused method ReadPlatformFile
- made Download Asset more generic so it can support downloading the ROMs for Game & Watch
- added code to download the Game & Watch ROMs from ArchiveOrg
- made Check CRC more generic so it can support Game & Watch
- replaced "" with string.Empty
- collapsed Build Asset Url code into Download Asset to make it easier to be more generic
  • Loading branch information
hallem authored Feb 8, 2024
1 parent 42b7ce9 commit 99e0405
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 94 deletions.
4 changes: 1 addition & 3 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private static async Task Main(string[] args)

#endregion

GlobalHelper.Initialize(path);
await GlobalHelper.Initialize(path);

if (!CLI_MODE)
{
Expand Down Expand Up @@ -259,8 +259,6 @@ private static async Task Main(string[] args)
coreUpdater.DownloadAssets(GlobalHelper.SettingsManager.GetConfig().download_assets);
coreUpdater.BackupSaves(GlobalHelper.SettingsManager.GetConfig().backup_saves, GlobalHelper.SettingsManager.GetConfig().backup_saves_location);

//await coreUpdater.Initialize();

// If we have any missing cores, handle them.
if (GlobalHelper.SettingsManager.GetMissingCores().Any())
{
Expand Down
69 changes: 50 additions & 19 deletions src/helpers/GlobalHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,55 @@ namespace Pannella.Helpers;

public static class GlobalHelper
{
public static Archive ArchiveFiles { get; private set; }
private static Archive archiveFiles;

public static Archive ArchiveFiles
{
get
{
if (archiveFiles == null)
{
Console.WriteLine("Loading Assets Index...");

if (SettingsManager.GetConfig().use_custom_archive)
{
var custom = SettingsManager.GetConfig().custom_archive;
Uri baseUrl = new Uri(custom["url"]);
Uri url = new Uri(baseUrl, custom["index"]);

archiveFiles = ArchiveService.GetFilesCustom(url.ToString()).Result;
}
else
{
archiveFiles = ArchiveService.GetFiles(SettingsManager.GetConfig().archive_name).Result;
}
}

return archiveFiles;
}
}

private static Archive gameAndWatchArchiveFiles;

public static Archive GameAndWatchArchiveFiles
{
get
{
if (gameAndWatchArchiveFiles == null)
{
Console.WriteLine("Loading Game and Watch Assets Index...");

gameAndWatchArchiveFiles = ArchiveService.GetFiles(SettingsManager.GetConfig().gnw_archive_name).Result;

// remove the metadata files since we're processing the entire json list
gameAndWatchArchiveFiles.files.RemoveAll(file =>
Path.GetExtension(file.name) is ".sqlite" or ".torrent" or ".xml");
}

return gameAndWatchArchiveFiles;
}
}

public static SettingsManager SettingsManager { get; private set ;}
public static string UpdateDirectory { get; private set; }
public static string[] Blacklist { get; private set; }
Expand All @@ -15,7 +63,7 @@ public static class GlobalHelper

private static bool isInitialized;

public static async void Initialize(string path)
public static async Task Initialize(string path)
{
if (!isInitialized)
{
Expand All @@ -26,23 +74,6 @@ public static async void Initialize(string path)
SettingsManager.InitializeCoreSettings(Cores);
RefreshInstalledCores();
Blacklist = await AssetsService.GetBlacklist();

Console.WriteLine("Loading Assets Index...");

if (SettingsManager.GetConfig().use_custom_archive)
{
var custom = SettingsManager.GetConfig().custom_archive;
Uri baseUrl = new Uri(custom["url"]);
Uri url = new Uri(baseUrl, custom["index"]);

ArchiveFiles = await ArchiveService.GetFilesCustom(url.ToString());
}
else
{
ArchiveFiles = await ArchiveService.GetFiles(SettingsManager.GetConfig().archive_name);
}

RefreshInstalledCores();
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/models/Archive/Archive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ public class Archive
{
public int files_count { get; set; }
public int item_last_updated { get; set; }
public File[] files { get; set; }
public List<File> files { get; set; }

public File GetFile(string filename)
public File GetFile(string fileName)
{
File file = this.files.FirstOrDefault(file => file.name == filename);
File file = this.files.FirstOrDefault(file => file.name == fileName);

return file;
}
Expand Down
Loading

0 comments on commit 99e0405

Please sign in to comment.