1+ using System . CommandLine ;
2+ using System . CommandLine . NamingConventionBinder ;
3+ using System . Text . Json ;
4+ using Yura . Shared . Archive ;
5+ using Yura . Shared . IO ;
6+
7+ // Define all command line options
8+ var command = new RootCommand ( "Scan a folder for archives and dump all unique hashes" )
9+ {
10+ new Argument < DirectoryInfo > (
11+ name : "path" ,
12+ description : "The path of the folder to scan" ) ,
13+
14+ new Argument < FileInfo > (
15+ name : "output" ,
16+ description : "The path of the output file" ) ,
17+
18+ new Option < Game > (
19+ name : "--game" ,
20+ description : "The game of the files" ,
21+ getDefaultValue : ( ) => Game . Legend ) ,
22+
23+ new Option < Endianness > (
24+ name : "--endianness" ,
25+ description : "The endianness of the files" ,
26+ getDefaultValue : ( ) => Endianness . LittleEndian ) ,
27+
28+ new Option < string > (
29+ name : "--pattern" ,
30+ description : "The pattern of the archives to scan" ,
31+ getDefaultValue : ( ) => "*.000" ) ,
32+
33+ new Option < OutputFormat > (
34+ name : "--output-format" ,
35+ description : "The format to output the data in" ,
36+ getDefaultValue : ( ) => OutputFormat . Text ) ,
37+ } ;
38+
39+ command . Handler = CommandHandler . Create ( Execute ) ;
40+
41+ // Run the command
42+ await command . InvokeAsync ( args ) ;
43+
44+ static void Execute (
45+ DirectoryInfo path , FileInfo output , Game game , Endianness endianness , string pattern , OutputFormat outputFormat )
46+ {
47+ List < ulong > hashes = [ ] ;
48+
49+ foreach ( var file in path . GetFiles ( pattern ) )
50+ {
51+ Console . WriteLine ( file . Name ) ;
52+
53+ // Open the archive
54+ var options = new ArchiveOptions
55+ {
56+ Path = file . FullName ,
57+ Endianness = endianness
58+ } ;
59+
60+ var archive = Create ( game , options ) ;
61+ archive . Open ( ) ;
62+
63+ // Add all hashes
64+ foreach ( var record in archive . Records )
65+ {
66+ if ( ! hashes . Contains ( record . Hash ) )
67+ {
68+ hashes . Add ( record . Hash ) ;
69+ }
70+ }
71+ }
72+
73+ // Write the output
74+ switch ( outputFormat )
75+ {
76+ case OutputFormat . Text :
77+ File . WriteAllLines ( output . FullName , hashes . Select ( hash => hash . ToString ( "X8" ) ) ) ;
78+
79+ break ;
80+ case OutputFormat . Json :
81+ File . WriteAllText ( output . FullName , JsonSerializer . Serialize ( hashes ) ) ;
82+
83+ break ;
84+ }
85+ }
86+
87+ static ArchiveFile Create ( Game game , ArchiveOptions options ) => game switch
88+ {
89+ Game . Defiance => new DefianceArchive ( options ) ,
90+ Game . Legend => new LegendArchive ( options ) ,
91+ Game . DeusEx => new DeusExArchive ( options ) ,
92+ Game . Tiger => new TigerArchive ( options ) ,
93+
94+ _ => throw new NotImplementedException ( )
95+ } ;
96+
97+ enum Game
98+ {
99+ Defiance ,
100+ Legend ,
101+ DeusEx ,
102+ Tiger
103+ }
104+
105+ enum OutputFormat
106+ {
107+ Text ,
108+ Json
109+ }
0 commit comments