Skip to content

Commit

Permalink
Implement extension guessing for unknown files (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
Crauzer committed Mar 11, 2023
1 parent 6c6cac6 commit 16d33c8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
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),
};
}
}

0 comments on commit 16d33c8

Please sign in to comment.