@@ -54,7 +54,8 @@ public partial class MainWindow : Window
5454 Dictionary < string , SolidColorBrush > origResourceColors = new Dictionary < string , SolidColorBrush > ( ) ;
5555
5656 string currentBuildReportProjectPath = null ;
57- List < List < string > > buildReports = new List < List < string > > ( ) ;
57+ //List<List<string>> buildReports = new List<List<string>>();
58+ List < BuildReport > buildReports = new List < BuildReport > ( ) ; // multiple reports, each contains their own stats and items
5859 int currentBuildReport = 0 ;
5960
6061 [ DllImport ( "user32" , CharSet = CharSet . Unicode ) ]
@@ -1844,6 +1845,7 @@ private void BtnRefreshBuildReport_Click(object sender, RoutedEventArgs e)
18441845 void RefreshBuildReports ( )
18451846 {
18461847 currentBuildReport = 0 ;
1848+ // delete all reports
18471849 buildReports . Clear ( ) ;
18481850 UpdateBuildReportLabelAndButtons ( ) ;
18491851
@@ -1853,17 +1855,21 @@ void RefreshBuildReports()
18531855 var logFile = Path . Combine ( Tools . GetEditorLogsFolder ( ) , "Editor.log" ) ;
18541856 if ( File . Exists ( logFile ) == false ) return ;
18551857
1856- List < string > subList = null ;
1858+ BuildReport singleReport = new BuildReport ( ) ;
18571859
18581860 try
18591861 {
18601862 using ( FileStream fs = new FileStream ( logFile , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) )
18611863 {
18621864 using ( StreamReader sr = new StreamReader ( fs ) )
18631865 {
1864- bool collect = false ;
1866+ bool collectRows = false ; // actual log rows
1867+ bool collectStats = false ; // category stat rows
1868+ bool collectedBuildTime = false ;
1869+
18651870 bool gotProjectPath = false ;
18661871
1872+ // TODO cleanup here
18671873 while ( ! sr . EndOfStream )
18681874 {
18691875 var line = sr . ReadLine ( ) ;
@@ -1877,25 +1883,112 @@ void RefreshBuildReports()
18771883 if ( line == "-projectPath" ) gotProjectPath = true ;
18781884
18791885
1880- // build report starts, TODO collect report header also
1881- if ( collect == false && line . IndexOf ( "Used Assets and files from the Resources folder, sorted by uncompressed size:" ) == 0 )
1886+ // build report starts
1887+ if ( collectRows == false && line . IndexOf ( "Used Assets and files from the Resources folder, sorted by uncompressed size:" ) == 0 )
18821888 {
18831889 // init new list for this build report
1884- subList = new List < string > ( ) ;
1885- collect = true ;
1890+ singleReport . Items = new List < BuildReportItem > ( ) ;
1891+ collectRows = true ;
1892+
1893+ // category report ends
1894+ if ( collectRows == true )
1895+ {
1896+ collectStats = false ;
1897+ }
1898+
18861899 continue ;
18871900 }
18881901
1889- // build report ends
1890- if ( collect == true && line . IndexOf ( "------------------------------------------------------------------------------- " ) == 0 )
1902+ // build report category stats starts
1903+ if ( collectStats == false && line . IndexOf ( "Uncompressed usage by category (Percentages based on user generated assets only): " ) == 0 )
18911904 {
1892- buildReports . Add ( subList ) ;
1893- collect = false ;
1905+ // init new list for this build report
1906+ singleReport . Stats = new List < BuildReportItem > ( ) ;
1907+ collectStats = true ;
1908+ continue ;
18941909 }
18951910
1896- if ( collect == true )
1911+ // build report ends with elapsed time
1912+ if ( collectedBuildTime == false && line . IndexOf ( "Build completed with a result of 'Succeeded' in " ) == 0 )
18971913 {
1898- subList . Add ( line ) ;
1914+ var ms = line . Substring ( line . IndexOf ( "(" ) + 1 , line . IndexOf ( ")" ) - line . IndexOf ( "(" ) - 1 ) . Trim ( ) . Replace ( " ms" , "" ) ;
1915+ singleReport . ElapsedTimeMS = long . Parse ( ms ) ;
1916+ collectedBuildTime = true ;
1917+
1918+ // get streamingassets folder size and add to report, NOTE need to recalculate sizes then?
1919+ long streamingAssetFolderSize = Tools . GetFolderSizeInBytes ( Path . Combine ( currentBuildReportProjectPath , "Assets" , "StreamingAssets" ) ) ;
1920+ singleReport . Stats . Insert ( singleReport . Stats . Count - 1 , new BuildReportItem ( ) { Category = "StreamingAssets" , Size = Tools . GetBytesReadable ( streamingAssetFolderSize ) } ) ;
1921+
1922+ // add all rows and stat rows for this build report
1923+ buildReports . Add ( singleReport ) ;
1924+
1925+ // make new
1926+ singleReport = new BuildReport ( ) ;
1927+ continue ;
1928+ }
1929+
1930+ // build report ends for rows
1931+ if ( collectRows == true && line . IndexOf ( "-------------------------------------------------------------------------------" ) == 0 )
1932+ {
1933+ collectRows = false ;
1934+ collectedBuildTime = false ;
1935+ continue ;
1936+ }
1937+
1938+ // parse and add this line to current build report
1939+ if ( collectRows == true )
1940+ {
1941+ var line2 = line . Trim ( ) ;
1942+ // get tab after kb
1943+ var space1 = line2 . IndexOf ( '\t ' ) ;
1944+ // get % between % and path
1945+ var space2 = line2 . IndexOf ( '%' ) ;
1946+
1947+ if ( space1 == - 1 || space2 == - 1 )
1948+ {
1949+ Console . WriteLine ( ( "Failed to parse build report row: " + line2 ) ) ;
1950+ continue ;
1951+ }
1952+
1953+ // create single row
1954+ var r = new BuildReportItem ( ) ;
1955+ r . Size = line2 . Substring ( 0 , space1 ) ;
1956+ r . Percentage = line2 . Substring ( space1 + 2 , space2 - space1 - 1 ) ;
1957+ r . Path = line2 . Substring ( space2 + 2 , line2 . Length - space2 - 2 ) ;
1958+ r . Format = Path . GetExtension ( r . Path ) ;
1959+
1960+ singleReport . Items . Add ( r ) ;
1961+ }
1962+
1963+
1964+ if ( collectStats == true )
1965+ {
1966+ var line2 = line . Trim ( ) ;
1967+ // get 2xspace after category name
1968+ var space1 = line2 . IndexOf ( " " ) ;
1969+ // get tab after first size
1970+ var space2 = line2 . IndexOf ( '\t ' ) ;
1971+ // last row didnt contain tab "Complete build size"
1972+ bool lastRow = false ;
1973+ if ( space2 == - 1 )
1974+ {
1975+ space2 = line2 . Length - 1 ;
1976+ lastRow = true ;
1977+ }
1978+
1979+ if ( space1 == - 1 || space2 == - 1 )
1980+ {
1981+ Console . WriteLine ( ( "(2) Failed to parse build report row: " + line2 ) ) ;
1982+ continue ;
1983+ }
1984+
1985+ // create single row
1986+ var r = new BuildReportItem ( ) ;
1987+ r . Category = line2 . Substring ( 0 , space1 ) . Trim ( ) ;
1988+ r . Size = line2 . Substring ( space1 + 2 , space2 - space1 - 1 ) . Trim ( ) ;
1989+ if ( lastRow == false ) r . Percentage = line2 . Substring ( space2 + 2 , line2 . Length - space2 - 2 ) . Trim ( ) ;
1990+
1991+ singleReport . Stats . Add ( r ) ;
18991992 }
19001993 }
19011994 }
@@ -1905,18 +1998,40 @@ void RefreshBuildReports()
19051998 {
19061999 gridBuildReport . ItemsSource = null ;
19072000 gridBuildReport . Items . Clear ( ) ;
1908- Console . WriteLine ( "Failed to open editor log: " + logFile ) ;
2001+
2002+ gridBuildReportData . ItemsSource = null ;
2003+ gridBuildReportData . Items . Clear ( ) ;
2004+
2005+ txtBuildTime . Text = "" ;
2006+
2007+ Console . WriteLine ( "Failed to open editor log or other error in parsing: " + logFile ) ;
19092008 return ;
19102009 }
19112010
1912- if ( buildReports . Count < 1 || buildReports [ 0 ] . Count < 1 )
2011+ // no build reports found
2012+ if ( buildReports . Count == 0 )
19132013 {
19142014 gridBuildReport . ItemsSource = null ;
19152015 gridBuildReport . Items . Clear ( ) ;
2016+
2017+ gridBuildReportData . ItemsSource = null ;
2018+ gridBuildReportData . Items . Clear ( ) ;
2019+
2020+ txtBuildTime . Text = "" ;
2021+
19162022 Console . WriteLine ( "Failed to parse Editor.Log (probably no build reports there)" ) ;
19172023 return ;
19182024 }
19192025
2026+ // remove streaming assets info, keep only for last build (because older builds might have had different files there, we dont know)
2027+ for ( int i = 0 ; i < buildReports . Count - 1 ; i ++ )
2028+ {
2029+ buildReports [ i ] . Stats [ buildReports [ i ] . Stats . Count - 2 ] . Size = "???" ;
2030+ }
2031+
2032+ // reverse build reports, so that latest is first
2033+ buildReports . Reverse ( ) ;
2034+
19202035 DisplayBuildReport ( currentBuildReport ) ;
19212036 }
19222037
@@ -1942,38 +2057,17 @@ void DisplayBuildReport(int index)
19422057 currentBuildReport = buildReports . Count - 1 ;
19432058 }
19442059
1945- // create build report rows array
1946- var reportSource = new List < BuildReportItem > ( ) ;
1947-
1948- // parse actual report rows
1949- for ( int i = 0 , len = buildReports [ currentBuildReport ] . Count ; i < len ; i ++ )
1950- {
1951- var d = buildReports [ currentBuildReport ] [ i ] . Trim ( ) ;
1952-
1953- // get tab after kb
1954- var space1 = d . IndexOf ( '\t ' ) ;
1955- // get % between % and path
1956- var space2 = d . IndexOf ( '%' ) ;
1957-
1958- if ( space1 == - 1 || space2 == - 1 )
1959- {
1960- Console . WriteLine ( "Failed to parse build report row: " + d ) ;
1961- continue ;
1962- }
1963-
1964- // create single row
1965- var r = new BuildReportItem ( ) ;
1966- r . Size = d . Substring ( 0 , space1 ) ;
1967- r . Percentage = d . Substring ( space1 + 2 , space2 - space1 - 1 ) ;
1968- r . Path = d . Substring ( space2 + 2 , d . Length - space2 - 2 ) ;
1969- r . Format = Path . GetExtension ( r . Path ) ;
1970-
1971- reportSource . Add ( r ) ;
1972- }
1973-
19742060 gridBuildReport . ItemsSource = null ;
19752061 gridBuildReport . Items . Clear ( ) ;
1976- gridBuildReport . ItemsSource = reportSource ;
2062+ gridBuildReport . ItemsSource = buildReports [ currentBuildReport ] . Items ;
2063+
2064+ gridBuildReportData . ItemsSource = null ;
2065+ gridBuildReportData . Items . Clear ( ) ;
2066+ gridBuildReportData . ItemsSource = buildReports [ currentBuildReport ] . Stats ;
2067+
2068+ var time = TimeSpan . FromMilliseconds ( buildReports [ currentBuildReport ] . ElapsedTimeMS ) ;
2069+ var dt = new DateTime ( time . Ticks ) ;
2070+ txtBuildTime . Text = dt . ToString ( "HH 'hours' mm 'minutes' ss 'seconds'" ) ;
19772071
19782072 UpdateBuildReportLabelAndButtons ( ) ;
19792073 }
@@ -1983,11 +2077,13 @@ void UpdateBuildReportLabelAndButtons()
19832077 btnPrevBuildReport . IsEnabled = currentBuildReport > 0 ;
19842078 btnNextBuildReport . IsEnabled = currentBuildReport < buildReports . Count - 1 ;
19852079 lblBuildReportIndex . Content = ( buildReports . Count == 0 ? 0 : ( currentBuildReport + 1 ) ) + "/" + ( buildReports . Count ) ;
2080+ txtBuildTime . Text = "" ;
19862081 }
19872082
19882083 private void BtnClearBuildReport_Click ( object sender , RoutedEventArgs e )
19892084 {
19902085 gridBuildReport . ItemsSource = null ;
2086+ gridBuildReportData . ItemsSource = null ;
19912087 currentBuildReport = 0 ;
19922088 buildReports . Clear ( ) ;
19932089 UpdateBuildReportLabelAndButtons ( ) ;
0 commit comments