@@ -56,6 +56,9 @@ public partial class MainWindow : Window
5656 Dictionary < string , SolidColorBrush > origResourceColors = new Dictionary < string , SolidColorBrush > ( ) ;
5757 string themefile = "theme.ini" ;
5858
59+ string latestBuildReportProjectPath = null ;
60+
61+
5962 public MainWindow ( )
6063 {
6164 InitializeComponent ( ) ;
@@ -285,7 +288,7 @@ void LoadSettings()
285288 lstRootFolders . Items . Clear ( ) ;
286289 lstRootFolders . ItemsSource = Properties . Settings . Default . rootFolders ;
287290
288- // restore datagrid column widths
291+ // restore recent project datagrid column widths
289292 int [ ] gridColumnWidths = Properties . Settings . Default . gridColumnWidths ;
290293 if ( gridColumnWidths != null )
291294 {
@@ -296,6 +299,17 @@ void LoadSettings()
296299 }
297300 }
298301
302+ // restore buildreport datagrid column widths
303+ gridColumnWidths = Properties . Settings . Default . gridColumnWidthsBuildReport ;
304+ if ( gridColumnWidths != null )
305+ {
306+ for ( int i = 0 ; i < gridColumnWidths . Length ; ++ i )
307+ {
308+ if ( i >= gridBuildReport . Columns . Count ) break ; // too many columns were saved, probably some test columns
309+ gridBuildReport . Columns [ i ] . Width = gridColumnWidths [ i ] ;
310+ }
311+ }
312+
299313 // other setting vars
300314 preferredVersion = Properties . Settings . Default . preferredVersion ;
301315
@@ -322,6 +336,7 @@ void LoadSettings()
322336
323337 useHumanFriendlyDateFormat = Properties . Settings . Default . useHumandFriendlyLastModified ;
324338
339+
325340 // recent grid column display index order
326341 var order = Properties . Settings . Default . recentColumnsOrder ;
327342
@@ -349,10 +364,13 @@ void LoadSettings()
349364
350365 } // LoadSettings()
351366
367+
352368 private void SaveSettingsOnExit ( )
353369 {
354- // save list column widths
370+ // save recent project column widths
355371 List < int > gridWidths ;
372+
373+ // if we dont have any settings yet
356374 if ( Properties . Settings . Default . gridColumnWidths != null )
357375 {
358376 gridWidths = new List < int > ( Properties . Settings . Default . gridColumnWidths ) ;
@@ -362,8 +380,8 @@ private void SaveSettingsOnExit()
362380 gridWidths = new List < int > ( ) ;
363381 }
364382
365- // restore data grid view widths
366- var colum = gridRecent . Columns [ 0 ] ;
383+ // get data grid view widths
384+ var column = gridRecent . Columns [ 0 ] ;
367385 for ( int i = 0 ; i < gridRecent . Columns . Count ; ++ i )
368386 {
369387 if ( Properties . Settings . Default . gridColumnWidths != null && Properties . Settings . Default . gridColumnWidths . Length > i )
@@ -378,6 +396,36 @@ private void SaveSettingsOnExit()
378396 Properties . Settings . Default . gridColumnWidths = gridWidths . ToArray ( ) ;
379397 Properties . Settings . Default . Save ( ) ;
380398
399+
400+ // save buildrepot column widths
401+ gridWidths . Clear ( ) ;
402+
403+ // if we dont have any settings yet
404+ if ( Properties . Settings . Default . gridColumnWidthsBuildReport != null )
405+ {
406+ gridWidths = new List < int > ( Properties . Settings . Default . gridColumnWidthsBuildReport ) ;
407+ }
408+ else
409+ {
410+ gridWidths = new List < int > ( ) ;
411+ }
412+
413+ // get data grid view widths
414+ column = gridBuildReport . Columns [ 0 ] ;
415+ for ( int i = 0 ; i < gridBuildReport . Columns . Count ; ++ i )
416+ {
417+ if ( Properties . Settings . Default . gridColumnWidthsBuildReport != null && Properties . Settings . Default . gridColumnWidthsBuildReport . Length > i )
418+ {
419+ gridWidths [ i ] = ( int ) gridBuildReport . Columns [ i ] . Width . Value ;
420+ }
421+ else
422+ {
423+ gridWidths . Add ( ( int ) gridBuildReport . Columns [ i ] . Width . Value ) ;
424+ }
425+ }
426+ Properties . Settings . Default . gridColumnWidthsBuildReport = gridWidths . ToArray ( ) ;
427+ Properties . Settings . Default . Save ( ) ;
428+
381429 }
382430
383431 void UpdateUnityInstallationsList ( )
@@ -423,6 +471,11 @@ Updates GetSelectedUpdate()
423471 return ( Updates ) dataGridUpdates . SelectedItem ;
424472 }
425473
474+ BuildReportItem GetSelectedBuildItem ( )
475+ {
476+ return ( BuildReportItem ) gridBuildReport . SelectedItem ;
477+ }
478+
426479 void AddUnityInstallationRootFolder ( )
427480 {
428481 var dialog = new System . Windows . Forms . FolderBrowserDialog ( ) ;
@@ -1635,54 +1688,42 @@ private void GridRecent_ContextMenuOpening(object sender, ContextMenuEventArgs e
16351688
16361689 private void BtnRefreshBuildReport_Click ( object sender , RoutedEventArgs e )
16371690 {
1638- // TODO keep previous build report (total size?) so can compare to current one
1639-
16401691 var logFile = Path . Combine ( Tools . GetEditorLogsFolder ( ) , "Editor.log" ) ;
1641- //Console.WriteLine("read editor log: " + logFile);
16421692
1643- List < string > rows = new List < string > ( ) ;
1693+ if ( File . Exists ( logFile ) == false ) return ;
16441694
1645- try
1646- {
1647- using ( var fs = new FileStream ( logFile , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) )
1648- using ( var sr = new StreamReader ( fs , Encoding . Default ) )
1649- {
1650- while ( sr . EndOfStream == false )
1651- {
1652- // TODO only start collecting when find build report start, and need to reset list if another build report later
1653- var r = sr . ReadLine ( ) ;
1654- rows . Add ( r ) ;
1655- }
1656- }
1657-
1658- }
1659- catch ( Exception ex )
1660- {
1661- Console . WriteLine ( ex . Message ) ;
1662- throw ;
1663- }
1695+ // NOTE this can fail on a HUGE log file
1696+ string [ ] rows = File . ReadAllLines ( logFile ) ;
16641697
16651698 if ( rows == null )
16661699 {
16671700 Console . WriteLine ( "Failed to open editor log: " + logFile ) ;
16681701 return ;
16691702 }
16701703
1671- // TODO parse project folder info also, so can browse to selected file
1672-
16731704 int startRow = - 1 ;
16741705 int endRow = - 1 ;
1706+
1707+ for ( int i = 0 , len = rows . Length ; i < len ; i ++ )
1708+ {
1709+ // get current project path from log file
1710+ if ( rows [ i ] == "-projectPath" )
1711+ {
1712+ latestBuildReportProjectPath = rows [ i + 1 ] ;
1713+ break ;
1714+ }
1715+ }
1716+ if ( string . IsNullOrEmpty ( latestBuildReportProjectPath ) ) Console . WriteLine ( "Failed to parse project path from logfile.." ) ;
1717+
16751718 // loop backwards to find latest report
1676- for ( int i = rows . Count - 1 ; i >= 0 ; i -- )
1719+ for ( int i = rows . Length - 1 ; i >= 0 ; i -- )
16771720 {
16781721 // find start of build report
1679- //if (rows[i].IndexOf("Build Report") == 0) // TODO take overview also
16801722 if ( rows [ i ] . IndexOf ( "Used Assets and files from the Resources folder, sorted by uncompressed size:" ) == 0 )
16811723 {
16821724 startRow = i + 1 ;
1683-
16841725 // find end of report
1685- for ( int k = i ; k < rows . Count ; k ++ )
1726+ for ( int k = i ; k < rows . Length ; k ++ )
16861727 {
16871728 if ( rows [ k ] . IndexOf ( "-------------------------------------------------------------------------------" ) == 0 )
16881729 {
@@ -1700,13 +1741,12 @@ private void BtnRefreshBuildReport_Click(object sender, RoutedEventArgs e)
17001741 return ;
17011742 }
17021743
1703- var reportSource = new BuildReport [ endRow - startRow ] ;
1744+ var reportSource = new BuildReportItem [ endRow - startRow ] ;
17041745
1705- // get report rows
1746+ // parse actual report rows
17061747 int index = 0 ;
17071748 for ( int i = startRow ; i < endRow ; i ++ )
17081749 {
1709- //Console.WriteLine(rows[i]);
17101750 var d = rows [ i ] . Trim ( ) ;
17111751
17121752 // get tab after kb
@@ -1720,10 +1760,11 @@ private void BtnRefreshBuildReport_Click(object sender, RoutedEventArgs e)
17201760 continue ;
17211761 }
17221762
1723- var r = new BuildReport ( ) ;
1763+ var r = new BuildReportItem ( ) ;
17241764 r . Size = d . Substring ( 0 , space1 ) ;
17251765 r . Percentage = d . Substring ( space1 + 2 , space2 - space1 - 1 ) ;
17261766 r . Path = d . Substring ( space2 + 2 , d . Length - space2 - 2 ) ;
1767+ r . Format = Path . GetExtension ( r . Path ) ;
17271768 reportSource [ index ++ ] = r ;
17281769 }
17291770 gridBuildReport . ItemsSource = reportSource ;
@@ -2029,16 +2070,26 @@ private void GridRecent_ColumnReordered(object sender, DataGridColumnEventArgs e
20292070 Properties . Settings . Default . Save ( ) ;
20302071 }
20312072
2073+ private void MenuItemExploreBuildItem_Click ( object sender , RoutedEventArgs e )
2074+ {
2075+ OpenSelectedBuildReportFile ( ) ;
2076+ }
20322077
2078+ private void GridBuildReport_PreviewMouseDoubleClick ( object sender , MouseButtonEventArgs e )
2079+ {
2080+ OpenSelectedBuildReportFile ( ) ;
2081+ }
2082+
2083+ void OpenSelectedBuildReportFile ( )
2084+ {
2085+ var item = GetSelectedBuildItem ( ) ;
2086+
2087+ if ( item != null )
2088+ {
2089+ string filePath = Path . Combine ( latestBuildReportProjectPath , item . Path ) ;
2090+ Tools . LaunchExplorerSelectFile ( filePath ) ;
2091+ }
2092+ }
20332093
2034- //private void CmbPlatformSelection_ManipulationInertiaStarting(object sender, ManipulationInertiaStartingEventArgs e)
2035- //{
2036- // var comb = (ComboBox)sender;
2037- // Console.WriteLine(comb.Name);
2038- // comb.HorizontalContentAlignment = HorizontalAlignment.Stretch;
2039- // comb.VerticalContentAlignment = VerticalAlignment.Center;
2040- // comb.HorizontalAlignment = HorizontalAlignment.Stretch;
2041- // comb.VerticalAlignment = VerticalAlignment.Center;
2042- //}
20432094 } // class
20442095} //namespace
0 commit comments