Skip to content

Commit

Permalink
Restored local cores discovery and support (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
hallem authored Feb 9, 2024
1 parent 56052de commit bc204b7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/helpers/GlobalHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,35 @@ public static async Task Initialize(string path)
UpdateDirectory = path;
SettingsManager = new SettingsManager(path);
Cores = await CoresService.GetCores();
Cores.AddRange(GetLocalCores());
SettingsManager.InitializeCoreSettings(Cores);
RefreshInstalledCores();
Blacklist = await AssetsService.GetBlacklist();
}
}

private static List<Core> GetLocalCores()
{
string coresDirectory = Path.Combine(UpdateDirectory, "Cores");
string[] directories = Directory.GetDirectories(coresDirectory, "*", SearchOption.TopDirectoryOnly);
List<Core> all = new List<Core>();

foreach (string name in directories)
{
string n = Path.GetFileName(name);
var matches = Cores.Where(i => i.identifier == n);

if (!matches.Any())
{
Core c = new Core { identifier = n };
c.platform = c.ReadPlatformFile();
all.Add(c);
}
}

return all;
}

public static void ReloadSettings()
{
SettingsManager = new SettingsManager(UpdateDirectory, Cores);
Expand Down
20 changes: 19 additions & 1 deletion src/models/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,24 @@ public void Uninstall(bool nuke = false)
Divide();
}

public Platform ReadPlatformFile()
{
var info = this.GetConfig();

if (info == null)
{
return this.platform;
}

string updateDirectory = GlobalHelper.UpdateDirectory;
// cores with multiple platforms won't work...not sure any exist right now?
string platformsFolder = Path.Combine(updateDirectory, "Platforms");
string dataFile = Path.Combine(platformsFolder, info.metadata.platform_ids[0] + ".json");
var p = JsonSerializer.Deserialize<Dictionary<string, Platform>>(File.ReadAllText(dataFile));

return p["platform"];
}

public async Task<Dictionary<string, object>> DownloadAssets()
{
List<string> installed = new List<string>();
Expand Down Expand Up @@ -198,7 +216,7 @@ public async Task<Dictionary<string, object>> DownloadAssets()
if (slot.filename != null && !slot.filename.EndsWith(".sav") &&
!GlobalHelper.Blacklist.Contains(slot.filename))
{

if (slot.IsCoreSpecific())
{
path = Path.Combine(platformPath, this.identifier);
Expand Down

0 comments on commit bc204b7

Please sign in to comment.