@@ -14,60 +14,104 @@ public static class Program
1414 {
1515 public static int Main ( string [ ] args )
1616 {
17- var analyzeCommand = new Command ( "analyze" , "Analyze AssetBundles or SerializedFiles." )
18- {
19- new Argument < DirectoryInfo > ( "path" , "The path to the directory containing the files to analyze" ) . ExistingOnly ( ) ,
20- new Option < string > ( aliases : new [ ] { "--output-file" , "-o" } , description : "Filename of the output database" , getDefaultValue : ( ) => "database.db" ) ,
21- new Option < bool > ( aliases : new [ ] { "--extract-references" , "-r" } , description : "Extract all object references and add them in the 'refs' table" ) ,
22- new Option < string > ( aliases : new [ ] { "--search-pattern" , "-p" } , description : "File search pattern" , getDefaultValue : ( ) => "*" ) ,
23- } ;
24- analyzeCommand . AddAlias ( "analyse" ) ;
25- analyzeCommand . Handler = CommandHandler . Create < DirectoryInfo , string , bool , string > ( HandleAnalyze ) ;
26-
27- var findRefsCommand = new Command ( "find-refs" , "Find reference chains to specified object(s)." )
28- {
29- new Argument < FileInfo > ( "databasePath" , "The path to the database generated by the 'analyze' command using --extract-references" ) . ExistingOnly ( ) ,
30- new Option < string > ( aliases : new [ ] { "--output-file" , "-o" } , description : "Output file" , getDefaultValue : ( ) => "references.txt" ) ,
31- new Option < bool > ( aliases : new [ ] { "--find-all" , "-a" } , description : "Find all reference chains originating from the same asset (instead of only one), can be very slow" ) ,
32- new Option < string > ( aliases : new [ ] { "--object-name" , "-n" } , description : "Object name" ) ,
33- new Option < string > ( aliases : new [ ] { "--object-type" , "-t" } , description : "Optional object type when searching by name" ) ,
34- new Option < long ? > ( aliases : new [ ] { "--object-id" , "-i" } , description : "Object id" ) ,
35- } ;
36- findRefsCommand . Handler = CommandHandler . Create < FileInfo , string , long ? , string , string , bool > ( HandleFindReferences ) ;
37-
38- var dumpCommand = new Command ( "dump" , "Dump the content of an AssetBundle or SerializedFile." )
39- {
40- new Argument < FileInfo > ( "filename" , "The path of the file to dump" ) . ExistingOnly ( ) ,
41- new Option < DumpFormat > ( aliases : new [ ] { "--output-format" , "-f" } , description : "Output format" , getDefaultValue : ( ) => DumpFormat . Text ) ,
42- new Option < bool > ( aliases : new [ ] { "--skip-large-arrays" , "-s" } , description : "Do not dump large arrays of basic data types" ) ,
43- } ;
44- dumpCommand . Handler = CommandHandler . Create < FileInfo , DumpFormat , bool > ( HandleDump ) ;
17+ var rootCommand = new RootCommand ( ) ;
4518
46- var extractArchiveCommand = new Command ( "extract" , "Extract the archive." )
4719 {
48- new Argument < FileInfo > ( "filename" , "The path of the archive file" ) . ExistingOnly ( ) ,
49- } ;
50- var listArchiveCommand = new Command ( "list" , "List the content of an archive." )
20+ var pathArg = new Argument < DirectoryInfo > ( "path" , "The path to the directory containing the files to analyze" ) . ExistingOnly ( ) ;
21+ var oOpt = new Option < string > ( aliases : new [ ] { "--output-file" , "-o" } , description : "Filename of the output database" , getDefaultValue : ( ) => "database.db" ) ;
22+ var rOpt = new Option < bool > ( aliases : new [ ] { "--extract-references" , "-r" } , description : "Extract all object references and add them in the 'refs' table" ) ;
23+ var pOpt = new Option < string > ( aliases : new [ ] { "--search-pattern" , "-p" } , description : "File search pattern" , getDefaultValue : ( ) => "*" ) ;
24+
25+ var analyzeCommand = new Command ( "analyze" , "Analyze AssetBundles or SerializedFiles." )
26+ {
27+ pathArg ,
28+ oOpt ,
29+ rOpt ,
30+ pOpt ,
31+ } ;
32+
33+ analyzeCommand . AddAlias ( "analyse" ) ;
34+ analyzeCommand . SetHandler (
35+ ( DirectoryInfo di , string o , bool r , string p ) => HandleAnalyze ( di , o , r , p ) ,
36+ pathArg , oOpt , rOpt , pOpt ) ;
37+
38+ rootCommand . AddCommand ( analyzeCommand ) ;
39+ }
40+
5141 {
52- new Argument < FileInfo > ( "filename" , "The path of the archive file" ) . ExistingOnly ( ) ,
53- } ;
54- var archiveCommand = new Command ( "archive" , "Unity Archive (AssetBundle) functions." )
42+ var pathArg = new Argument < FileInfo > ( "databasePath" , "The path to the database generated by the 'analyze' command using --extract-references" ) . ExistingOnly ( ) ;
43+ var oOpt = new Option < string > ( aliases : new [ ] { "--output-file" , "-o" } , description : "Output file" , getDefaultValue : ( ) => "references.txt" ) ;
44+ var aOpt = new Option < bool > ( aliases : new [ ] { "--find-all" , "-a" } , description : "Find all reference chains originating from the same asset (instead of only one), can be very slow" ) ;
45+ var nOpt = new Option < string > ( aliases : new [ ] { "--object-name" , "-n" } , description : "Object name" ) ;
46+ var tOpt = new Option < string > ( aliases : new [ ] { "--object-type" , "-t" } , description : "Optional object type when searching by name" ) ;
47+ var iOpt = new Option < long ? > ( aliases : new [ ] { "--object-id" , "-i" } , description : "Object id" ) ;
48+
49+ var findRefsCommand = new Command ( "find-refs" , "Find reference chains to specified object(s)." )
50+ {
51+ pathArg ,
52+ oOpt ,
53+ aOpt ,
54+ nOpt ,
55+ tOpt ,
56+ iOpt ,
57+ } ;
58+
59+ findRefsCommand . SetHandler (
60+ ( FileInfo fi , string o , long ? a , string n , string t , bool i ) => HandleFindReferences ( fi , o , a , n , t , i ) ,
61+ pathArg , oOpt , aOpt , nOpt , tOpt , iOpt ) ;
62+
63+ rootCommand . Add ( findRefsCommand ) ;
64+ }
65+
5566 {
56- extractArchiveCommand ,
57- listArchiveCommand ,
58- } ;
59- extractArchiveCommand . Handler = CommandHandler . Create < FileInfo > ( HandleExtractArchive ) ;
60- listArchiveCommand . Handler = CommandHandler . Create < FileInfo > ( HandleListArchive ) ;
67+ var pathArg = new Argument < FileInfo > ( "filename" , "The path of the file to dump" ) . ExistingOnly ( ) ;
68+ var fOpt = new Option < DumpFormat > ( aliases : new [ ] { "--output-format" , "-f" } , description : "Output format" , getDefaultValue : ( ) => DumpFormat . Text ) ;
69+ var sOpt = new Option < bool > ( aliases : new [ ] { "--skip-large-arrays" , "-s" } , description : "Do not dump large arrays of basic data types" ) ;
70+
71+ var dumpCommand = new Command ( "dump" , "Dump the content of an AssetBundle or SerializedFile." )
72+ {
73+ pathArg ,
74+ fOpt ,
75+ sOpt ,
76+ } ;
77+ dumpCommand . SetHandler (
78+ ( FileInfo fi , DumpFormat f , bool s ) => HandleDump ( fi , f , s ) ,
79+ pathArg , fOpt , sOpt ) ;
80+
81+ rootCommand . AddCommand ( dumpCommand ) ;
82+ }
6183
62- var cmd = new RootCommand ( )
6384 {
64- analyzeCommand ,
65- findRefsCommand ,
66- dumpCommand ,
67- archiveCommand ,
68- } ;
85+ var pathArg = new Argument < FileInfo > ( "filename" , "The path of the archive file" ) . ExistingOnly ( ) ;
86+
87+ var extractArchiveCommand = new Command ( "extract" , "Extract the archive." )
88+ {
89+ pathArg ,
90+ } ;
91+
92+ extractArchiveCommand . SetHandler (
93+ ( FileInfo fi ) => HandleExtractArchive ( fi ) ,
94+ pathArg ) ;
95+
96+ var listArchiveCommand = new Command ( "list" , "List the content of an archive." )
97+ {
98+ pathArg ,
99+ } ;
100+
101+ listArchiveCommand . SetHandler (
102+ ( FileInfo fi ) => HandleListArchive ( fi ) ,
103+ pathArg ) ;
104+
105+ var archiveCommand = new Command ( "archive" , "Unity Archive (AssetBundle) functions." )
106+ {
107+ extractArchiveCommand ,
108+ listArchiveCommand ,
109+ } ;
110+
111+ rootCommand . AddCommand ( archiveCommand ) ;
112+ }
69113
70- return cmd . Invoke ( args ) ;
114+ return rootCommand . Invoke ( args ) ;
71115 }
72116
73117 enum DumpFormat
0 commit comments