@@ -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