Skip to content

Commit 5abfee5

Browse files
committed
fix build report searchbox, add support for viewing multiple build report data, add prev/next build report buttons
1 parent f2a67ff commit 5abfee5

File tree

2 files changed

+89
-46
lines changed

2 files changed

+89
-46
lines changed

UnityLauncherPro/MainWindow.xaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@
770770
<Grid>
771771
<!-- search box -->
772772
<Grid Background="{DynamicResource ThemeTextBoxBackground}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="222" Margin="6,5,0,0" Height="20" >
773-
<TextBlock Margin="3,2" MinWidth="100" Text="Search" Foreground="{DynamicResource ThemeSearchForeground}" Visibility="{Binding Text.IsEmpty, Converter={StaticResource MyBoolToVisibilityConverter}, ElementName=txtSearchBoxUpdates}" Height="24" />
773+
<TextBlock Margin="3,2" MinWidth="100" Text="Search" Foreground="{DynamicResource ThemeSearchPlaceholder}" Visibility="{Binding Text.IsEmpty, Converter={StaticResource MyBoolToVisibilityConverter}, ElementName=txtSearchBoxUpdates}" Height="24" />
774774
<TextBox MinWidth="100" CaretBrush="{DynamicResource ThemeSearchCaret}" x:Name="txtSearchBoxUpdates" Background="Transparent" BorderBrush="{x:Null}" Foreground="{DynamicResource ThemeSearchForeground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" BorderThickness="0" Margin="2,2,0,0" UndoLimit="64" PreviewKeyDown="TxtSearchBoxUpdates_PreviewKeyDown" TextChanged="TxtSearchBoxUpdates_TextChanged" />
775775
<Button x:Name="btnClearUpdatesSearch" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" BorderThickness="0" HorizontalAlignment="Right" VerticalAlignment="Top" Height="23" Width="23" Background="Transparent" Padding="0,2" Visibility="Visible" BorderBrush="{x:Null}" Click="OnClearUpdateSearchClick">
776776
<TextBlock Text="" FontSize="8" Foreground="{DynamicResource ThemeSearchClose}" Padding="5,3,4,4" HorizontalAlignment="Center">
@@ -910,8 +910,8 @@
910910

911911
<!-- search box -->
912912
<Grid Background="{DynamicResource ThemeTextBoxBackground}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="222" Margin="6,5,0,0" Height="20" >
913-
<TextBox MinWidth="100" CaretBrush="{DynamicResource ThemeSearchCaret}" x:Name="txtSearchBoxBuildReport" Background="{DynamicResource ThemeTextBoxBackground}" BorderBrush="{x:Null}" Foreground="{DynamicResource ThemeSearchForeground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" BorderThickness="0" Margin="2,2,0,0" UndoLimit="64" PreviewKeyDown="TxtSearchBoxBuildReport_PreviewKeyDown" TextChanged="TxtSearchBoxBuildReport_TextChanged" />
914-
<TextBlock Margin="3,2" MinWidth="100" Text="Search" Foreground="{DynamicResource ThemeSearchPlaceholder}" Visibility="{Binding Text.IsEmpty, Converter={StaticResource MyBoolToVisibilityConverter}, ElementName=txtSearchBoxBuildReport}" Height="24" />
913+
<TextBlock Margin="3,2" MinWidth="100" Text="Search" Foreground="{DynamicResource ThemeSearchPlaceholder}" Visibility="{Binding Text.IsEmpty, Converter={StaticResource MyBoolToVisibilityConverter}, ElementName=txtSearchBoxBuildReport}" Height="24" IsEnabled="False" />
914+
<TextBox MinWidth="100" CaretBrush="{DynamicResource ThemeSearchCaret}" x:Name="txtSearchBoxBuildReport" Background="Transparent" BorderBrush="{x:Null}" Foreground="{DynamicResource ThemeSearchForeground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" BorderThickness="0" Margin="2,2,0,0" UndoLimit="64" PreviewKeyDown="TxtSearchBoxBuildReport_PreviewKeyDown" TextChanged="TxtSearchBoxBuildReport_TextChanged" />
915915
<Button x:Name="btnClearBuildReportSearch" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" BorderThickness="0" HorizontalAlignment="Right" VerticalAlignment="Top" Height="23" Width="23" Background="Transparent" Padding="0,2" Visibility="Visible" BorderBrush="{x:Null}" Click="BtnClearBuildReportSearch_Click">
916916
<TextBlock Text="" FontSize="8" Foreground="{DynamicResource ThemeSearchCaret}" Padding="5,3,4,4" HorizontalAlignment="Center">
917917
<TextBlock.Style>
@@ -930,9 +930,12 @@
930930
</Button>
931931
</Grid>
932932

933-
933+
<Label x:Name="lblBuildReportIndex" Height="26" Foreground="{DynamicResource ThemeSearchForeground}" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="10,0,0,0" Content="-/-"/>
934+
<Button x:Name="btnPrevBuildReport" Style="{StaticResource CustomButton}" ToolTip="Previous Build Report" Content="" Height="22" Width="22" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="16" Margin="0,4,0,0" Padding="1,-2,1,1" BorderBrush="{x:Null}" Click="BtnPrevBuildReport_Click" IsEnabled="False"/>
935+
<Button x:Name="btnNextBuildReport" Style="{StaticResource CustomButton}" ToolTip="Next Build Report" Content="" Height="22" Width="22" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="16" Margin="8,4,10,0" Padding="1,-2,1,1" BorderBrush="{x:Null}" Click="BtnNextBuildReport_Click" IsEnabled="False"/>
934936
</StackPanel>
935-
<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 ThemeDatagridLines}" VerticalGridLinesBrush="{DynamicResource ThemeGridVerticalGridLines}" AutoGenerateColumns="False" VerticalAlignment="Top" PreviewMouseDoubleClick="GridBuildReport_PreviewMouseDoubleClick">
937+
938+
<DataGrid x:Name="gridBuildReport" SelectionMode="Single" CanUserAddRows="False" 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 ThemeDatagridLines}" VerticalGridLinesBrush="{DynamicResource ThemeGridVerticalGridLines}" AutoGenerateColumns="False" VerticalAlignment="Top" PreviewMouseDoubleClick="GridBuildReport_PreviewMouseDoubleClick">
936939
<DataGrid.Columns>
937940
<DataGridTextColumn Binding="{Binding Size}" ClipboardContentBinding="{x:Null}" Header="Size" IsReadOnly="True" Width="75"/>
938941
<DataGridTextColumn Binding="{Binding Percentage}" ClipboardContentBinding="{x:Null}" Header="%" IsReadOnly="True" Width="55" />

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 81 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public partial class MainWindow : Window
5454
Dictionary<string, SolidColorBrush> origResourceColors = new Dictionary<string, SolidColorBrush>();
5555

5656
string latestBuildReportProjectPath = null;
57+
List<List<string>> buildReports = new List<List<string>>();
58+
int currentBuildReport = 0;
5759

5860
[DllImport("user32", CharSet = CharSet.Unicode)]
5961
static extern IntPtr FindWindow(string cls, string win);
@@ -624,7 +626,7 @@ private void OnRectangleMouseDown(object sender, MouseButtonEventArgs e)
624626
private void OnSearchTextChanged(object sender, TextChangedEventArgs e)
625627
{
626628
FilterRecentProjects();
627-
629+
628630
// if nothing selected, select first item
629631
if (gridRecent.SelectedIndex < 0) gridRecent.SelectedIndex = 0;
630632
}
@@ -1801,22 +1803,49 @@ private void GridRecent_ContextMenuOpening(object sender, ContextMenuEventArgs e
18011803

18021804
private void BtnRefreshBuildReport_Click(object sender, RoutedEventArgs e)
18031805
{
1804-
var logFile = Path.Combine(Tools.GetEditorLogsFolder(), "Editor.log");
1806+
currentBuildReport = 0;
1807+
buildReports.Clear();
1808+
UpdateBuildReportLabelAndButtons();
1809+
1810+
btnPrevBuildReport.IsEnabled = false;
1811+
btnNextBuildReport.IsEnabled = false;
18051812

1813+
var logFile = Path.Combine(Tools.GetEditorLogsFolder(), "Editor.log");
18061814
if (File.Exists(logFile) == false) return;
18071815

1808-
// NOTE this can fail on a HUGE log file
1809-
List<string> rows = new List<string>();
1816+
List<string> subList = null;
1817+
18101818
try
18111819
{
18121820
using (FileStream fs = new FileStream(logFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
18131821
{
18141822
using (StreamReader sr = new StreamReader(fs))
18151823
{
1824+
bool collect = false;
18161825
// now we collect all lines, but could collect only those needed below
18171826
while (!sr.EndOfStream)
18181827
{
1819-
rows.Add(sr.ReadLine());
1828+
var line = sr.ReadLine();
1829+
// build report starts, TODO collect report header also
1830+
if (collect == false && line.IndexOf("Used Assets and files from the Resources folder, sorted by uncompressed size:") == 0)
1831+
{
1832+
// init new list for this build report
1833+
subList = new List<string>();
1834+
collect = true;
1835+
continue;
1836+
}
1837+
1838+
// build report ends
1839+
if (collect == true && line.IndexOf("-------------------------------------------------------------------------------") == 0)
1840+
{
1841+
buildReports.Add(subList);
1842+
collect = false;
1843+
}
1844+
1845+
if (collect == true)
1846+
{
1847+
subList.Add(line);
1848+
}
18201849
}
18211850
}
18221851
}
@@ -1827,53 +1856,44 @@ private void BtnRefreshBuildReport_Click(object sender, RoutedEventArgs e)
18271856
return;
18281857
}
18291858

1830-
int startRow = -1;
1831-
int endRow = -1;
1832-
1833-
for (int i = 0, len = rows.Count; i < len; i++)
1859+
if (buildReports.Count < 1 || buildReports[0].Count < 1)
18341860
{
1835-
// get current project path from log file
1836-
if (rows[i] == "-projectPath")
1837-
{
1838-
latestBuildReportProjectPath = rows[i + 1];
1839-
break;
1840-
}
1861+
Console.WriteLine("Failed to parse Editor.Log (probably no build reports there)");
1862+
return;
18411863
}
1842-
if (string.IsNullOrEmpty(latestBuildReportProjectPath)) Console.WriteLine("Failed to parse project path from logfile..");
18431864

1844-
// loop backwards to find latest report
1845-
for (int i = rows.Count - 1; i >= 0; i--)
1865+
DisplayBuildReport(currentBuildReport);
1866+
}
1867+
1868+
private void BtnPrevBuildReport_Click(object sender, RoutedEventArgs e)
1869+
{
1870+
DisplayBuildReport(--currentBuildReport);
1871+
}
1872+
1873+
private void BtnNextBuildReport_Click(object sender, RoutedEventArgs e)
1874+
{
1875+
DisplayBuildReport(++currentBuildReport);
1876+
}
1877+
1878+
void DisplayBuildReport(int index)
1879+
{
1880+
if (currentBuildReport < 0)
18461881
{
1847-
// find start of build report
1848-
if (rows[i].IndexOf("Used Assets and files from the Resources folder, sorted by uncompressed size:") == 0)
1849-
{
1850-
startRow = i + 1;
1851-
// find end of report
1852-
for (int k = i, len = rows.Count; k < len; k++)
1853-
{
1854-
if (rows[k].IndexOf("-------------------------------------------------------------------------------") == 0)
1855-
{
1856-
endRow = k - 1;
1857-
break;
1858-
}
1859-
}
1860-
break;
1861-
}
1882+
currentBuildReport = 0;
18621883
}
18631884

1864-
if (startRow == -1 || endRow == -1)
1885+
if (currentBuildReport > buildReports.Count)
18651886
{
1866-
Console.WriteLine("Failed to parse Editor.Log (probably no build report there), start= " + startRow + " end= " + endRow);
1867-
return;
1887+
currentBuildReport = buildReports.Count - 1;
18681888
}
18691889

1870-
var reportSource = new BuildReportItem[endRow - startRow];
1890+
// create build report rows array
1891+
var reportSource = new List<BuildReportItem>();
18711892

18721893
// parse actual report rows
1873-
int index = 0;
1874-
for (int i = startRow; i < endRow; i++)
1894+
for (int i = 0, len = buildReports[currentBuildReport].Count; i < len; i++)
18751895
{
1876-
var d = rows[i].Trim();
1896+
var d = buildReports[currentBuildReport][i].Trim();
18771897

18781898
// get tab after kb
18791899
var space1 = d.IndexOf('\t');
@@ -1886,20 +1906,36 @@ private void BtnRefreshBuildReport_Click(object sender, RoutedEventArgs e)
18861906
continue;
18871907
}
18881908

1909+
// create single row
18891910
var r = new BuildReportItem();
18901911
r.Size = d.Substring(0, space1);
18911912
r.Percentage = d.Substring(space1 + 2, space2 - space1 - 1);
18921913
r.Path = d.Substring(space2 + 2, d.Length - space2 - 2);
18931914
r.Format = Path.GetExtension(r.Path);
1894-
reportSource[index++] = r;
1915+
1916+
reportSource.Add(r);
18951917
}
1918+
1919+
gridBuildReport.ItemsSource = null;
1920+
gridBuildReport.Items.Clear();
18961921
gridBuildReport.ItemsSource = reportSource;
18971922

1923+
UpdateBuildReportLabelAndButtons();
1924+
}
1925+
1926+
void UpdateBuildReportLabelAndButtons()
1927+
{
1928+
btnPrevBuildReport.IsEnabled = currentBuildReport > 0;
1929+
btnNextBuildReport.IsEnabled = currentBuildReport < buildReports.Count - 1;
1930+
lblBuildReportIndex.Content = (buildReports.Count == 0 ? 0 : (currentBuildReport + 1)) + "/" + (buildReports.Count);
18981931
}
18991932

19001933
private void BtnClearBuildReport_Click(object sender, RoutedEventArgs e)
19011934
{
19021935
gridBuildReport.ItemsSource = null;
1936+
currentBuildReport = 0;
1937+
buildReports.Clear();
1938+
UpdateBuildReportLabelAndButtons();
19031939
}
19041940

19051941
private void MenuStartWebGLServer_Click(object sender, RoutedEventArgs e)
@@ -2216,6 +2252,8 @@ void OpenSelectedBuildReportFile()
22162252
{
22172253
var item = GetSelectedBuildItem();
22182254

2255+
Console.WriteLine(item.Path);
2256+
22192257
if (item != null)
22202258
{
22212259
string filePath = Path.Combine(latestBuildReportProjectPath, item.Path);
@@ -2416,6 +2454,8 @@ private void BtnUnityCache_Click(object sender, RoutedEventArgs e)
24162454
Tools.OpenAppdataSpecialFolder("Unity/cache");
24172455
}
24182456

2457+
2458+
24192459
//private void BtnBrowseTemplateUnityPackagesFolder_Click(object sender, RoutedEventArgs e)
24202460
//{
24212461
// var folder = Tools.BrowseForOutputFolder("Select unitypackage Templates folder");

0 commit comments

Comments
 (0)