Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c026f44

Browse files
committedSep 26, 2021
buildreport (#49): add file format column, load/save column widths with preferences, parse projectpath from editorlog, add contect menu and double click to open buildreport file with Explorer select file, rename BuildReport struct to BuildReportItem
1 parent 545e010 commit c026f44

File tree

7 files changed

+153
-53
lines changed

7 files changed

+153
-53
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
namespace UnityLauncherPro
22
{
3-
public class BuildReport
3+
public class BuildReportItem
44
{
55
// TODO use real values, so can sort and convert kb/mb
66
public string Size { set; get; }
77
public string Percentage { set; get; }
88
public string Path { set; get; }
9+
public string Format { set; get; }
910
}
1011
}

‎UnityLauncherPro/MainWindow.xaml

+13-5
Original file line numberDiff line numberDiff line change
@@ -797,15 +797,23 @@
797797
<Button x:Name="btnRefreshBuildReport" Style="{StaticResource CustomButton}" ToolTip="Get latest Build Report from Editor.log" Content="" Height="22" Width="22" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="16" Margin="0,4,10,0" Padding="1,-2,1,1" BorderBrush="{x:Null}" Click="BtnRefreshBuildReport_Click"/>
798798
<!--<CheckBox x:Name="chkAutoUpdateBuildReport" Content="AutoUpdate" Foreground="{DynamicResource ButtonForeground}" Margin="0,0,0,3" ToolTip="" HorizontalAlignment="Right" VerticalAlignment="Top" Height="26" VerticalContentAlignment="Center" IsEnabled="False"/>-->
799799
</StackPanel>
800-
<DataGrid x:Name="gridBuildReport" SelectionMode="Single" Margin="4,30,2,0" Background="{x:Null}" BorderBrush="{x:Null}" ColumnHeaderStyle="{StaticResource HeaderStyle}" Padding="0" HorizontalScrollBarVisibility="Disabled" HeadersVisibility="Column" Foreground="{DynamicResource ThemeGridForeground}" HorizontalGridLinesBrush="{DynamicResource ThemeGridHorizontalGridLines}" VerticalGridLinesBrush="{DynamicResource ThemeGridVerticalGridLines}" AutoGenerateColumns="False" VerticalAlignment="Top">
800+
<DataGrid x:Name="gridBuildReport" SelectionMode="Single" Margin="4,30,2,0" Background="{x:Null}" BorderBrush="{x:Null}" ColumnHeaderStyle="{StaticResource HeaderStyle}" Padding="0" HorizontalScrollBarVisibility="Disabled" HeadersVisibility="Column" Foreground="{DynamicResource ThemeGridForeground}" HorizontalGridLinesBrush="{DynamicResource ThemeGridHorizontalGridLines}" VerticalGridLinesBrush="{DynamicResource ThemeGridVerticalGridLines}" AutoGenerateColumns="False" VerticalAlignment="Top" PreviewMouseDoubleClick="GridBuildReport_PreviewMouseDoubleClick">
801801
<DataGrid.Columns>
802-
<DataGridTextColumn Binding="{Binding Size}" ClipboardContentBinding="{x:Null}" Header="Size" IsReadOnly="True" MinWidth="75"/>
803-
<DataGridTextColumn Binding="{Binding Percentage}" ClipboardContentBinding="{x:Null}" Header="%" IsReadOnly="True" MinWidth="55" />
804-
<DataGridTextColumn Binding="{Binding Path}" ClipboardContentBinding="{x:Null}" Header="Path" IsReadOnly="True"/>
802+
<DataGridTextColumn Binding="{Binding Size}" ClipboardContentBinding="{x:Null}" Header="Size" IsReadOnly="True" Width="75"/>
803+
<DataGridTextColumn Binding="{Binding Percentage}" ClipboardContentBinding="{x:Null}" Header="%" IsReadOnly="True" Width="55" />
804+
<DataGridTextColumn Binding="{Binding Path}" ClipboardContentBinding="{x:Null}" Header="Path" IsReadOnly="True" Width="333" />
805+
<DataGridTextColumn Binding="{Binding Format}" ClipboardContentBinding="{x:Null}" Header="Format" IsReadOnly="True" Width="65"/>
805806
</DataGrid.Columns>
806807

808+
<!-- right click context menu -->
809+
<DataGrid.ContextMenu>
810+
<ContextMenu>
811+
<MenuItem x:Name="menuItemExploreBuildItem" Header="Open Explorer here" Click="MenuItemExploreBuildItem_Click" />
812+
</ContextMenu>
813+
</DataGrid.ContextMenu>
814+
807815
<!-- sample data for testing -->
808-
<local:BuildReport Size="10.0 mb" Percentage="50.0%" Path="Assets/Textures/sample.png" />
816+
<local:BuildReportItem Size="10.0 mb" Percentage="50.0%" Path="Assets/Textures/sample.png" />
809817
</DataGrid>
810818

811819
</Grid>

‎UnityLauncherPro/MainWindow.xaml.cs

+97-46
Original file line numberDiff line numberDiff line change
@@ -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

‎UnityLauncherPro/Properties/Settings.Designer.cs

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎UnityLauncherPro/Properties/Settings.settings

+3
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,8 @@
8686
<Setting Name="recentColumnsOrder" Type="System.Int32[]" Scope="User">
8787
<Value Profile="(Default)" />
8888
</Setting>
89+
<Setting Name="gridColumnWidthsBuildReport" Type="System.Int32[]" Scope="User">
90+
<Value Profile="(Default)" />
91+
</Setting>
8992
</Settings>
9093
</SettingsFile>

‎UnityLauncherPro/Tools.cs

+26
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,32 @@ public static bool LaunchExplorer(string folder)
287287
return false;
288288
}
289289

290+
public static bool LaunchExplorerSelectFile(string fileName)
291+
{
292+
if (File.Exists(fileName) == true)
293+
{
294+
295+
fileName = Path.GetFullPath(fileName);
296+
Process.Start("explorer.exe", string.Format("/select,\"{0}\"", fileName));
297+
return true;
298+
}
299+
else // file is missing, try to find parent folder that we can go into
300+
{
301+
for (int i = fileName.Length - 1; i > -1; i--)
302+
{
303+
if (fileName[i] == '/')
304+
{
305+
if (Directory.Exists(fileName.Substring(0, i)))
306+
{
307+
Process.Start(fileName.Substring(0, i) + "/");
308+
break;
309+
}
310+
}
311+
}
312+
}
313+
return false;
314+
}
315+
290316
// run any exe
291317
public static bool LaunchExe(string path, string param = null)
292318
{

‎UnityLauncherPro/UnityLauncherPro.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<SubType>Designer</SubType>
7777
</ApplicationDefinition>
7878
<Compile Include="Converters\LastModifiedConverter.cs" />
79-
<Compile Include="Data\BuildReport.cs" />
79+
<Compile Include="Data\BuildReportItem.cs" />
8080
<Compile Include="Data\Platform.cs" />
8181
<Compile Include="Data\Tabs.cs" />
8282
<Compile Include="GetProjects.cs" />

0 commit comments

Comments
 (0)
Please sign in to comment.