Skip to content

Commit

Permalink
Update GameResourcesResolveHelper.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
laolarou726 committed Dec 4, 2024
1 parent 46d4062 commit 3202d47
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions ProjBobcat/ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ public static async IAsyncEnumerable<GameModResolvedInfo> ResolveModListAsync(
ext.Equals(".disabled", StringComparison.OrdinalIgnoreCase)))
continue;

if (!ArchiveHelper.TryOpen(file, out var archive)) continue;
await using var fs = File.OpenRead(file);

if (!ArchiveHelper.TryOpen(fs, out var archive)) continue;

var modInfoEntry =
archive.Entries.FirstOrDefault(e =>
Expand Down Expand Up @@ -303,7 +305,10 @@ public static async IAsyncEnumerable<GameModResolvedInfo> ResolveModListAsync(
var ext = Path.GetExtension(file);

if (!ext.Equals(".zip", StringComparison.OrdinalIgnoreCase)) return null;
if (!ArchiveHelper.TryOpen(file, out var archive)) return null;

await using var fs = File.OpenRead(file);

if (!ArchiveHelper.TryOpen(fs, out var archive)) return null;

var packIconEntry =
archive.Entries.FirstOrDefault(e => e.Key?.Equals("pack.png", StringComparison.OrdinalIgnoreCase) ?? false);
Expand Down Expand Up @@ -407,9 +412,11 @@ public static async IAsyncEnumerable<GameResourcePackResolvedInfo> ResolveResour
}
}

static GameShaderPackResolvedInfo? ResolveShaderPackFile(string file)
static async Task<GameShaderPackResolvedInfo?> ResolveShaderPackFile(string file)
{
if (!ArchiveHelper.TryOpen(file, out var archive)) return null;
await using var fs = File.OpenRead(file);

if (!ArchiveHelper.TryOpen(fs, out var archive)) return null;
if (!archive.Entries.Any(e =>
Path.GetFileName(e.Key?.TrimEnd('/'))
?.Equals("shaders", StringComparison.OrdinalIgnoreCase) ?? false))
Expand All @@ -429,17 +436,17 @@ public static async IAsyncEnumerable<GameResourcePackResolvedInfo> ResolveResour
return new GameShaderPackResolvedInfo(Path.GetFileName(dir), true);
}

public static IEnumerable<GameShaderPackResolvedInfo> ResolveShaderPack(
public static async IAsyncEnumerable<GameShaderPackResolvedInfo> ResolveShaderPack(
IEnumerable<(string, bool)> paths,
CancellationToken ct)
[EnumeratorCancellation] CancellationToken ct)
{
foreach (var (path, isDir) in paths)
{
if (ct.IsCancellationRequested) yield break;

if (!isDir)
{
var result = ResolveShaderPackFile(path);
var result = await ResolveShaderPackFile(path);

if (result == null) continue;

Expand Down

0 comments on commit 3202d47

Please sign in to comment.