Skip to content

Commit 0476876

Browse files
Add TLFDBX support, upgrade to net10
1 parent ead23ef commit 0476876

18 files changed

Lines changed: 290 additions & 80 deletions

TalesOfTools.sln

Lines changed: 0 additions & 27 deletions
This file was deleted.

TalesOfTools.slnx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Solution>
2+
<Folder Name="/tools/">
3+
<Project Path="tools/TLTool/TLTool.csproj" />
4+
</Folder>
5+
</Solution>

tools/TLTool/Commands/AnalyzeNamesCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void Execute(InvocationContext context)
4949
mapper = new TLDataNameDictionary();
5050
}
5151

52-
mapper.AddNamesFromFile(context.ParseResult.GetValueForArgument(FileDictionaryPath));
52+
mapper.AddNamesFromList(context.ParseResult.GetValueForArgument(FileDictionaryPath));
5353
var entriesNamed = 0;
5454
var longestExtension = "Type".Length;
5555
int longestCount = int.Max(data.Entries.Count.ToString().Length, "Count".Length);

tools/TLTool/Commands/DumpNamesCommand.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void Execute(InvocationContext context)
4242
AddNamesFromDependFiles(header, mapper, bigEndian, is32Bit);
4343
BruteForceDependFromPhysical(header, mapper, "TOTEXB_D", "TOTEXP_P");
4444
BruteForceDependFromPhysical(header, mapper, "TOMDLB_D", "TOMDLP_P");
45-
mapper.Write(Console.Out);
45+
mapper.WriteNameList(Console.Out);
4646
}
4747

4848
private static void AddNamesFromDependFiles(TLDataHeader header, TLDataNameDictionary mapper, bool bigEndian, bool is32Bit)
@@ -51,7 +51,13 @@ private static void AddNamesFromDependFiles(TLDataHeader header, TLDataNameDicti
5151
{
5252
if (entry.Extension.EndsWith("_D", StringComparison.OrdinalIgnoreCase))
5353
{
54-
AddNamesFromDependFile(entry, mapper, bigEndian, is32Bit);
54+
try
55+
{
56+
AddNamesFromDependFile(entry, mapper, bigEndian, is32Bit);
57+
}
58+
catch
59+
{
60+
}
5561
}
5662
}
5763
}

tools/TLTool/Commands/ListNamesCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void Execute(InvocationContext context)
3030
var mapper = new TLDataNameDictionary();
3131
var is32Bit = context.ParseResult.GetValueForOption(Is32Bit);
3232
var bigEndian = context.ParseResult.GetValueForOption(IsBigEndian);
33-
mapper.AddNamesFromFile(context.ParseResult.GetValueForArgument(FileDictionaryPath)!);
33+
mapper.AddNamesFromList(context.ParseResult.GetValueForArgument(FileDictionaryPath)!);
3434

3535
using (var stream = File.OpenRead(context.ParseResult.GetValueForArgument(HeaderPath)))
3636
header.ReadFrom(new BinaryStream(stream, bigEndian), is32Bit);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.CommandLine;
2+
using System.CommandLine.Invocation;
3+
4+
namespace TLTool;
5+
6+
public sealed class MergeFileMapsCommand
7+
{
8+
public Command Command { get; } = new("merge-tlfdbx");
9+
10+
public Argument<string> OutputPath { get; } = new("output", "Path to output TLFDBX");
11+
12+
public Argument<string[]> Paths { get; } = new("paths", "Path to each TLFDBX file");
13+
14+
public MergeFileMapsCommand()
15+
{
16+
Command.AddArgument(OutputPath);
17+
Command.AddArgument(Paths);
18+
Handler.SetHandler(Command, Execute);
19+
}
20+
21+
public void Execute(InvocationContext context)
22+
{
23+
var mapper = new TLDataNameDictionary();
24+
var inputs = context.ParseResult.GetValueForArgument(Paths)!;
25+
var output = context.ParseResult.GetValueForArgument(OutputPath)!;
26+
27+
foreach (var input in inputs)
28+
mapper.AddNamesFromXml(input);
29+
30+
using var writer = new StreamWriter(output);
31+
mapper.WriteFileDatabase(writer);
32+
}
33+
}

tools/TLTool/Commands/QueryFileCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void Execute(InvocationContext context)
4141
data.ReadFrom(new BinaryStream(stream, bigEndian), is32Bit);
4242

4343
if (context.ParseResult.HasOption(Dictionary))
44-
mapper.AddNamesFromFile(context.ParseResult.GetValueForOption(Dictionary)!);
44+
mapper.AddNamesFromList(context.ParseResult.GetValueForOption(Dictionary)!);
4545

4646
foreach (var entry in data.Entries)
4747
{

tools/TLTool/Commands/QueryNamesCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public QueryNamesCommand()
2222
public void Execute(InvocationContext context)
2323
{
2424
var mapper = new TLDataNameDictionary();
25-
mapper.AddNamesFromFile(context.ParseResult.GetValueForArgument(Dictionary));
25+
mapper.AddNamesFromList(context.ParseResult.GetValueForArgument(Dictionary));
2626

2727
foreach (string query in context.ParseResult.GetValueForArgument(Hashes))
2828
{

tools/TLTool/Commands/UnZarcCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void Execute(InvocationContext context)
3535
var mapper = new ZArcNameDictionary(archive.PathCaseConversion);
3636

3737
if (context.ParseResult.HasOption(FileDictionaryPath))
38-
mapper.AddNamesFromFile(context.ParseResult.GetValueForOption(FileDictionaryPath)!);
38+
mapper.AddNamesFromList(context.ParseResult.GetValueForOption(FileDictionaryPath)!);
3939

4040
Parallel.ForEach(archive.Entries, entry =>
4141
{

tools/TLTool/Commands/UnpackCommand.cs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public sealed class UnpackCommand
2222

2323
public Option<bool> IsBigEndian { get; } = new("--big-endian", "File is big-endian");
2424

25+
public Option<bool> IsFileMap { get; } = new("--file-map", "Name dictionary is a TLFDBX file");
26+
2527
public UnpackCommand()
2628
{
2729
Command.AddArgument(HeaderPath);
@@ -31,6 +33,7 @@ public UnpackCommand()
3133
Command.AddOption(Is32Bit);
3234
Command.AddOption(IsBigEndian);
3335
Command.AddOption(Encrypted);
36+
Command.AddOption(IsFileMap);
3437
Handler.SetHandler(Command, Execute);
3538
}
3639

@@ -54,15 +57,45 @@ public void Execute(InvocationContext context)
5457
header.ReadFrom(new BinaryStream(stream, bigEndian), new FileInfo(context.ParseResult.GetValueForArgument(TLFilePath)), is32Bit);
5558

5659
if (context.ParseResult.HasOption(FileDictionaryPath))
57-
mapper.AddNamesFromFile(context.ParseResult.GetValueForOption(FileDictionaryPath)!);
60+
{
61+
var path = context.ParseResult.GetValueForOption(FileDictionaryPath)!;
62+
var extension = Path.GetExtension(path);
63+
64+
if (extension.Equals(".TLFDBX", StringComparison.OrdinalIgnoreCase) || context.ParseResult.GetValueForOption(IsFileMap))
65+
{
66+
mapper.AddNamesFromXml(path);
67+
}
68+
else
69+
{
70+
mapper.AddNamesFromList(path);
71+
}
72+
}
5873

5974
Parallel.ForEach(header.Entries, entry =>
6075
{
6176
var name = mapper.GetNameOrFallback(entry.NameHash, entry.Extension);
62-
Directory.CreateDirectory(Path.Combine(output, entry.Extension));
63-
using var source = GetStream((TLFileDataSource)entry.DataSource, encrypt);
64-
using var stream = File.Create(Path.Combine(output, entry.Extension, name));
65-
source.CopyTo(stream);
77+
var path = Path.Combine(Path.Combine(output, entry.Extension), name);
78+
var time = 0L;
79+
80+
if (mapper.TryGetFileMap(entry.NameHash, entry.Extension, out var map))
81+
{
82+
if (!string.IsNullOrEmpty(map.FullPath))
83+
path = Path.Combine(output, map.FullPath.TrimStart('/', '\\'));
84+
85+
time = map.TimeStamp;
86+
}
87+
88+
Directory.CreateDirectory(Path.GetDirectoryName(path) ?? output);
89+
using (var source = GetStream((TLFileDataSource)entry.DataSource, encrypt))
90+
using (var stream = File.Create(path))
91+
{
92+
source.CopyTo(stream);
93+
}
94+
95+
if (time > 0)
96+
{
97+
File.SetLastWriteTimeUtc(path, DateTime.FromFileTimeUtc(time));
98+
}
6699
});
67100
}
68101

0 commit comments

Comments
 (0)