@@ -13,35 +13,39 @@ namespace UnityDataTools.Analyzer;
1313
1414public class AnalyzerTool
1515{
16- bool m_Verbose = false ;
16+ AnalyzeOptions m_Options ;
1717
1818 public List < ISQLiteFileParser > parsers = new List < ISQLiteFileParser > ( )
1919 {
2020 new AddressablesBuildLayoutParser ( ) ,
2121 new SerializedFileParser ( ) ,
2222 } ;
2323
24- public int Analyze (
25- string path ,
26- string databaseName ,
27- string searchPattern ,
28- bool skipReferences ,
29- bool skipCrc ,
30- bool verbose ,
31- bool noRecursion )
24+ public class AnalyzeOptions
3225 {
33- m_Verbose = verbose ;
26+ public string Path { get ; init ; }
27+ public string DatabaseName { get ; init ; }
28+ public string SearchPattern { get ; init ; } = "*" ;
29+ public bool SkipReferences { get ; init ; }
30+ public bool SkipCrc { get ; init ; }
31+ public bool Verbose { get ; init ; }
32+ public bool NoRecursion { get ; init ; }
33+ }
34+
35+ public int Analyze ( AnalyzeOptions options )
36+ {
37+ m_Options = options ;
3438
35- using SQLiteWriter writer = new ( databaseName ) ;
39+ using SQLiteWriter writer = new ( m_Options . DatabaseName ) ;
3640
3741 try
3842 {
3943 writer . Begin ( ) ;
4044 foreach ( var parser in parsers )
4145 {
42- parser . Verbose = verbose ;
43- parser . SkipReferences = skipReferences ;
44- parser . SkipCrc = skipCrc ;
46+ parser . Verbose = m_Options . Verbose ;
47+ parser . SkipReferences = m_Options . SkipReferences ;
48+ parser . SkipCrc = m_Options . SkipCrc ;
4549 parser . Init ( writer . Connection ) ;
4650
4751 }
@@ -56,9 +60,9 @@ public int Analyze(
5660 timer . Start ( ) ;
5761
5862 var files = Directory . GetFiles (
59- path ,
60- searchPattern ,
61- noRecursion ? SearchOption . TopDirectoryOnly : SearchOption . AllDirectories ) ;
63+ m_Options . Path ,
64+ m_Options . SearchPattern ,
65+ m_Options . NoRecursion ? SearchOption . TopDirectoryOnly : SearchOption . AllDirectories ) ;
6266
6367 int countFailures = 0 ;
6468 int countSuccess = 0 ;
@@ -75,15 +79,15 @@ public int Analyze(
7579 try
7680 {
7781 parser . Parse ( file ) ;
78- ReportProgress ( Path . GetRelativePath ( path , file ) , i , files . Length ) ;
82+ ReportProgress ( Path . GetRelativePath ( m_Options . Path , file ) , i , files . Length ) ;
7983 countSuccess ++ ;
8084 }
8185 catch ( SerializedFileOpenException e )
8286 {
8387 // Expected failure — the file content could not be parsed.
8488 // Don't print a stack trace; it adds no value for this known failure mode.
8589 EraseProgressLine ( ) ;
86- var relativePath = Path . GetRelativePath ( path , file ) ;
90+ var relativePath = Path . GetRelativePath ( m_Options . Path , file ) ;
8791 Console . Error . WriteLine ( $ "Failed to open: { relativePath } ") ;
8892 var hint = SerializedFileDetector . GetOpenFailureHint ( e . FilePath ) ;
8993 if ( hint != null )
@@ -94,9 +98,9 @@ public int Analyze(
9498 {
9599 // Unexpected failure (SQL error, I/O error, bug, etc.) — print full details.
96100 EraseProgressLine ( ) ;
97- var relativePath = Path . GetRelativePath ( path , file ) ;
101+ var relativePath = Path . GetRelativePath ( m_Options . Path , file ) ;
98102 Console . Error . WriteLine ( $ "Failed to process: { relativePath } ") ;
99- if ( m_Verbose )
103+ if ( m_Options . Verbose )
100104 {
101105 Console . Error . WriteLine ( $ " Exception: { e . GetType ( ) . Name } : { e . Message } ") ;
102106 if ( e . InnerException != null )
@@ -109,9 +113,9 @@ public int Analyze(
109113 }
110114 if ( ! foundParser )
111115 {
112- if ( m_Verbose )
116+ if ( m_Options . Verbose )
113117 {
114- var relativePath = Path . GetRelativePath ( path , file ) ;
118+ var relativePath = Path . GetRelativePath ( m_Options . Path , file ) ;
115119 Console . WriteLine ( ) ;
116120 Console . WriteLine ( $ "Ignoring { relativePath } ") ;
117121 }
@@ -142,7 +146,7 @@ public int Analyze(
142146 void ReportProgress ( string relativePath , int fileIndex , int cntFiles )
143147 {
144148 var message = $ "Processing { fileIndex * 100 / cntFiles } % ({ fileIndex } /{ cntFiles } ) { relativePath } ";
145- if ( ! m_Verbose )
149+ if ( ! m_Options . Verbose )
146150 {
147151 EraseProgressLine ( ) ;
148152 Console . Write ( $ "\r { message } ") ;
@@ -158,7 +162,7 @@ void ReportProgress(string relativePath, int fileIndex, int cntFiles)
158162
159163 void EraseProgressLine ( )
160164 {
161- if ( ! m_Verbose )
165+ if ( ! m_Options . Verbose )
162166 Console . Write ( $ "\r { new string ( ' ' , m_LastProgressMessageLength ) } \r ") ;
163167 else
164168 Console . WriteLine ( ) ;
0 commit comments