-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18d5133
commit b25fb42
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.CommandLine; | ||
using System.CommandLine.Invocation; | ||
|
||
namespace TLTool; | ||
|
||
public sealed class ListNamesCommand | ||
{ | ||
public Command Command { get; } = new("list-names"); | ||
|
||
public Argument<string> HeaderPath { get; } = new("header-path", "Path to FILEHEADER.TOFHDB"); | ||
|
||
public Argument<string> FileDictionaryPath { get; } = new("--dictionary", "Path to name dictionary file"); | ||
|
||
public Option<bool> Is32Bit { get; } = new("--bit32", "File is 32-bit (Xillia, Zestiria)"); | ||
|
||
public Option<bool> IsBigEndian { get; } = new("--big-endian", "File is big-endian"); | ||
|
||
public ListNamesCommand() | ||
{ | ||
Command.AddArgument(HeaderPath); | ||
Command.AddArgument(FileDictionaryPath); | ||
Command.AddOption(Is32Bit); | ||
Command.AddOption(IsBigEndian); | ||
Handler.SetHandler(Command, Execute); | ||
} | ||
|
||
public void Execute(InvocationContext context) | ||
{ | ||
var header = new DataHeader(); | ||
var mapper = new NameDictionary(); | ||
var is32Bit = context.ParseResult.GetValueForOption(Is32Bit); | ||
var bigEndian = context.ParseResult.GetValueForOption(IsBigEndian); | ||
mapper.AddNamesFromFile(context.ParseResult.GetValueForArgument(FileDictionaryPath)!); | ||
|
||
using (var stream = File.OpenRead(context.ParseResult.GetValueForArgument(HeaderPath))) | ||
using (var reader = bigEndian ? new BigEndianBinaryReader(stream) : new BinaryReader(stream)) | ||
header.ReadFrom(reader, new FileInfo("."), is32Bit); | ||
|
||
// Sort the entries by data offset, which can reveal the original filesystem folder groupings. | ||
var entries = header.Entries.Where(pair => pair.Value.DataSource is TLFileDataSource).ToArray(); | ||
Array.Sort(entries, CompareDataSourceOffsets); | ||
|
||
foreach (var (hash, entry) in entries) | ||
{ | ||
Console.WriteLine(mapper.GetNameOrFallback(hash, entry.Extension)); | ||
} | ||
} | ||
|
||
private static int CompareDataSourceOffsets(KeyValuePair<uint, DataHeaderEntry> a, KeyValuePair<uint, DataHeaderEntry> b) | ||
{ | ||
var offset1 = ((TLFileDataSource)a.Value.DataSource).Offset; | ||
var offset2 = ((TLFileDataSource)b.Value.DataSource).Offset; | ||
return offset1.CompareTo(offset2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters