Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement extension guessing for unknown files #150

Merged
merged 1 commit into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Obsidian/Data/Wad/WadTabModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ public void Rebuild()

foreach (var (_, chunk) in this.Wad.Chunks)
{
string path = this.Hashtable.GetChunkPath(chunk);
string path = this.Hashtable.TryGetChunkPath(chunk, out path) switch
{
true => path,
false => this.Hashtable.GuessChunkPath(chunk, this.Wad),
};
string[] pathComponents = path.Split('/');

if (pathComponents.Length is 1)
Expand Down
20 changes: 19 additions & 1 deletion Obsidian/Services/HashtableService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using LeagueToolkit.Core.Wad;
using CommunityToolkit.HighPerformance;
using LeagueToolkit.Core.Wad;
using LeagueToolkit.Utils;
using Obsidian.Data;
using Octokit;
using Serilog;
Expand Down Expand Up @@ -236,4 +238,20 @@ public string GetChunkPath(WadChunk chunk)

return string.Format("{0:x16}", chunk.PathHash);
}

public bool TryGetChunkPath(WadChunk chunk, out string path) =>
this.Hashes.TryGetValue(chunk.PathHash, out path);

public string GuessChunkPath(WadChunk chunk, WadFile wad)
{
using Stream stream = wad.LoadChunkDecompressed(chunk).AsStream();

string extension = LeagueFile.GetExtension(LeagueFile.GetFileType(stream));

return string.IsNullOrEmpty(extension) switch
{
true => string.Format("{0:x16}", chunk.PathHash),
false => string.Format("{0:x16}.{1}", chunk.PathHash, extension),
};
}
}