@@ -7,9 +7,12 @@ namespace AppCompare;
77
88class Comparer {
99
10- public static DataTable GetTable ( string app1path , string app2path , Dictionary < string , string > mappings )
10+ const string filter_all_files = "*.*" ;
11+ const string filter_obj_files = "*.o" ;
12+
13+ public static DataTable GetAppCompareTable ( string app1path , string app2path , Dictionary < string , string > mappings )
1114 {
12- DataTable dt = new ( ) ;
15+ DataTable dt = new ( "App bundle compare" ) ;
1316 DataColumn files = new ( "Files" , typeof ( string ) ) ;
1417 dt . Columns . Add ( files ) ;
1518 dt . PrimaryKey = new [ ] { files } ;
@@ -21,7 +24,7 @@ public static DataTable GetTable (string app1path, string app2path, Dictionary<s
2124 dt . Columns . Add ( new DataColumn ( " " , typeof ( string ) ) ) ;
2225
2326 try {
24- Populate ( dt , app1path , app2path , mappings ) ;
27+ Populate ( dt , app1path , app2path , mappings , filter_all_files ) ;
2528 } catch ( Exception ex ) {
2629 dt . ExtendedProperties . Add ( "Exception" , ex ) ;
2730 }
@@ -97,19 +100,45 @@ public static DataTable GetTable (string app1path, string app2path, Dictionary<s
97100 AddSummaryRow ( dt , "Managed *.dll/exe" , managed_a , managed_b ) ;
98101 AddEmptyRow ( dt ) ;
99102 AddSummaryRow ( dt , "TOTAL" , size_a , size_b ) ;
103+
100104 return dt ;
101105 }
102106
103- static void Populate ( DataTable dt , string app1path , string app2path , Dictionary < string , string > mappings )
107+ public static DataTable GetObjCompareTable ( string app1path , string app2path , Dictionary < string , string > mappings )
108+ {
109+ DataTable dt = new ( "Object files compare" ) ;
110+ DataColumn files = new ( "Files" , typeof ( string ) ) ;
111+ dt . Columns . Add ( files ) ;
112+ dt . PrimaryKey = new [ ] { files } ;
113+
114+ dt . Columns . Add ( new DataColumn ( "Size A" , typeof ( ( FileInfo , long ) ) ) ) ;
115+ dt . Columns . Add ( new DataColumn ( "Size B" , typeof ( ( FileInfo , long ) ) ) ) ;
116+ dt . Columns . Add ( new DataColumn ( "diff" , typeof ( long ) ) ) ;
117+ dt . Columns . Add ( new DataColumn ( "%" , typeof ( double ) ) ) ;
118+ dt . Columns . Add ( new DataColumn ( " " , typeof ( string ) ) ) ;
119+
120+ try {
121+ Populate ( dt , app1path , app2path , mappings , filter_obj_files ) ;
122+ } catch ( Exception ex ) {
123+ dt . ExtendedProperties . Add ( "Exception" , ex ) ;
124+ }
125+
126+ dt . DefaultView . Sort = "Files ASC" ;
127+ dt = dt . DefaultView . ToTable ( ) ;
128+ dt . ExtendedProperties . Add ( "AppA" , app1path ) ;
129+ dt . ExtendedProperties . Add ( "AppB" , app2path ) ;
130+
131+ AddEmptyRow ( dt ) ;
132+ return dt ;
133+ }
134+
135+ static void Populate ( DataTable dt , string app1path , string app2path , Dictionary < string , string > mappings , string filter )
104136 {
105137 DirectoryInfo Directory1 = new ( app1path ) ;
106138 if ( Directory1 . Exists ) {
107- var len1 = app1path . Length ;
108- if ( app1path [ len1 - 1 ] != Path . DirectorySeparatorChar )
109- len1 ++ ;
110- foreach ( var file in Directory1 . GetFiles ( "*.*" , SearchOption . AllDirectories ) ) {
139+ foreach ( var file in Directory1 . GetFiles ( filter , SearchOption . AllDirectories ) ) {
111140 dt . Rows . Add ( new object ? [ ] {
112- file . FullName [ len1 .. ] ,
141+ file . Name ,
113142 ( file , file . Length ) ,
114143 empty ,
115144 - file . Length ,
@@ -123,11 +152,8 @@ static void Populate (DataTable dt, string app1path, string app2path, Dictionary
123152 if ( ! Directory2 . Exists )
124153 return ;
125154
126- var len2 = app2path . Length ;
127- if ( app2path [ len2 - 1 ] != Path . DirectorySeparatorChar )
128- len2 ++ ;
129- foreach ( var file in Directory2 . GetFiles ( "*.*" , SearchOption . AllDirectories ) ) {
130- var name = file . FullName [ len2 ..] ;
155+ foreach ( var file in Directory2 . GetFiles ( filter , SearchOption . AllDirectories ) ) {
156+ var name = file . Name ;
131157 var row = dt . Rows . Find ( name ) ;
132158 var remapped = false ;
133159 if ( row is null ) {
@@ -180,54 +206,58 @@ static void AddSummaryRow (DataTable dt, string name, long a, long b)
180206 } ) ;
181207 }
182208
183- static public string ExportMarkdown ( DataTable table )
209+ static public string ExportMarkdown ( List < DataTable > tables )
184210 {
185211 StringBuilder builder = new ( ) ;
186212 builder . AppendLine ( "# Application Comparer" ) ;
187213 builder . AppendLine ( ) ;
188214
189- builder . Append ( "* App A: `" ) . Append ( table . ExtendedProperties [ "AppA" ] ) . AppendLine ( "`" ) ;
190- builder . Append ( "* App B: `" ) . Append ( table . ExtendedProperties [ "AppB" ] ) . AppendLine ( "`" ) ;
191- builder . AppendLine ( ) ;
215+ foreach ( var table in tables ) {
216+ builder . AppendLine ( $ "## { table . TableName } ") ;
217+ builder . AppendLine ( ) ;
218+ builder . Append ( "* Path A: `" ) . Append ( table . ExtendedProperties [ "AppA" ] ) . AppendLine ( "`" ) ;
219+ builder . Append ( "* Path B: `" ) . Append ( table . ExtendedProperties [ "AppB" ] ) . AppendLine ( "`" ) ;
220+ builder . AppendLine ( ) ;
192221
193- var columns = table . Columns ;
194- // skip last "comment" column - it's for the tool itself, not for reporting
195- for ( int i = 0 ; i < columns . Count - 1 ; i ++ ) {
196- builder . Append ( "| " ) . Append ( columns [ i ] . ColumnName ) . Append ( ' ' ) ;
197- }
198- builder . AppendLine ( "|" ) ;
222+ var columns = table . Columns ;
223+ // skip last "comment" column - it's for the tool itself, not for reporting
224+ for ( int i = 0 ; i < columns . Count - 1 ; i ++ ) {
225+ builder . Append ( "| " ) . Append ( columns [ i ] . ColumnName ) . Append ( ' ' ) ;
226+ }
227+ builder . AppendLine ( "|" ) ;
199228
200- builder . AppendLine ( "|:----|----:|----:|----:|----:|" ) ;
229+ builder . AppendLine ( "|:----|----:|----:|----:|----:|" ) ;
201230
202- foreach ( DataRow row in table . Rows ) {
203- var file = row [ 0 ] as string ;
204- if ( file ! . Length == 0 ) {
205- builder . AppendLine ( "| | | | | |" ) ;
206- } else {
207- builder . Append ( "| " ) . Append ( row [ 0 ] ) ;
208- ( _ , long f1length ) = ( ( FileInfo ? , long ) ) row [ 1 ] ;
209- builder . Append ( " | " ) . AppendFormat ( "{0:N0}" , f1length ) ;
210- ( _ , long f2length ) = ( ( FileInfo ? , long ) ) row [ 2 ] ;
211- builder . Append ( " | " ) . AppendFormat ( "{0:N0}" , f2length ) ;
212- builder . Append ( " | " ) . AppendFormat ( "{0:N0}" , row [ 3 ] ) ;
213- var percentage = ( double ) row [ 4 ] ;
214- var display = Double . IsNaN ( percentage ) ? "-" : percentage . ToString ( "P1" ) ;
215- builder . Append ( " | " ) . Append ( display ) ;
216- builder . AppendLine ( " |)" ) ;
231+ foreach ( DataRow row in table . Rows ) {
232+ var file = row [ 0 ] as string ;
233+ if ( file ! . Length == 0 ) {
234+ builder . AppendLine ( "| | | | | |" ) ;
235+ } else {
236+ builder . Append ( "| " ) . Append ( row [ 0 ] ) ;
237+ ( _ , long f1length ) = ( ( FileInfo ? , long ) ) row [ 1 ] ;
238+ builder . Append ( " | " ) . AppendFormat ( "{0:N0}" , f1length ) ;
239+ ( _ , long f2length ) = ( ( FileInfo ? , long ) ) row [ 2 ] ;
240+ builder . Append ( " | " ) . AppendFormat ( "{0:N0}" , f2length ) ;
241+ builder . Append ( " | " ) . AppendFormat ( "{0:N0}" , row [ 3 ] ) ;
242+ var percentage = ( double ) row [ 4 ] ;
243+ var display = Double . IsNaN ( percentage ) ? "-" : percentage . ToString ( "P1" ) ;
244+ builder . Append ( " | " ) . Append ( display ) ;
245+ builder . AppendLine ( " |)" ) ;
246+ }
217247 }
218248 }
219249 builder . AppendLine ( ) ;
220250 builder . AppendLine ( "Generated by [appcompare](https://github.com/spouliot/appcompare)" ) ;
221251 return builder . ToString ( ) ;
222252 }
223253
224- static public string Gist ( DataTable table , bool openUrl = true )
254+ static public string Gist ( List < DataTable > tables , bool openUrl = true )
225255 {
226256 GistRequest request = new ( ) {
227257 Description = "Application Comparison Report" ,
228258 Public = false ,
229259 } ;
230- request . AddFile ( "report.md" , ExportMarkdown ( table ) ) ;
260+ request . AddFile ( "report.md" , ExportMarkdown ( tables ) ) ;
231261
232262 Task < GistResponse > ? task = Task . Run ( async ( ) => await GistClient . CreateAsync ( request ) ) ;
233263 var url = "https://github.com/spouliot/SimpleGist/wiki#errors" ;
0 commit comments