Skip to content

Commit 6dac9d8

Browse files
committedSep 24, 2020
add initial build report tool #15, arrange Tools tab contents
1 parent 1d2a616 commit 6dac9d8

File tree

5 files changed

+164
-26
lines changed

5 files changed

+164
-26
lines changed
 

‎UnityLauncherPro/Data/BuildReport.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace UnityLauncherPro
2+
{
3+
public class BuildReport
4+
{
5+
// TODO use real values, so can sort and convert kb/mb
6+
public string Size { set; get; }
7+
public string Percentage { set; get; }
8+
public string Path { set; get; }
9+
}
10+
}

‎UnityLauncherPro/MainWindow.xaml

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -584,36 +584,63 @@
584584
<TabItem Header="Tools" Style="{DynamicResource TabItemStyle1}" Padding="0,0,0,0" Margin="-1,1,1,-1" BorderBrush="{x:Null}" Background="Black">
585585
<Grid>
586586
<Grid.RowDefinitions>
587-
<RowDefinition Height="50*" />
587+
<RowDefinition Height="15*" />
588588
<RowDefinition Height="50*" />
589589
</Grid.RowDefinitions>
590590
<!-- 1st part -->
591-
591+
<Grid Grid.Row="0" VerticalAlignment="Top" HorizontalAlignment="Left">
592+
<StackPanel Orientation="Vertical" Margin="10">
593+
<Border HorizontalAlignment="Left" VerticalAlignment="Top">
594+
<StackPanel Orientation="Horizontal" Margin="10">
595+
<Label Content="Folders" Foreground="{DynamicResource ButtonForeground}" />
596+
<Button Style="{StaticResource CustomButton}" x:Name="btnOpenEditorLogsFolder" Margin="0" BorderBrush="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Top" Click="BtnOpenEditorLogsFolder_Click" ToolTip="Browse Editor logs folder">
597+
<Label Content="_Editor Logs" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
598+
</Button>
599+
<Button Style="{StaticResource CustomButton}" x:Name="btnOpenPlayerLogs" Margin="10,0,0,0" BorderBrush="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Top" Click="BtnOpenPlayerLogs_Click" ToolTip="Browse Player logs folder">
600+
<Label Content="_Player Logs" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
601+
</Button>
602+
<Button Style="{StaticResource CustomButton}" x:Name="btnOpenCrashLogs" Margin="10,0,0,0" BorderBrush="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Top" Click="BtnOpenCrashLogs_Click" ToolTip="Browse Crash logs folder">
603+
<Label Content="_Crash Logs" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
604+
</Button>
605+
<Button Style="{StaticResource CustomButton}" x:Name="btnAssetPackages" Margin="10,0,0,0" BorderBrush="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Top" ToolTip="Browse AssetStore downloads folder" Click="BtnAssetPackages_Click">
606+
<Label Content="A_sset packages" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
607+
</Button>
608+
</StackPanel>
609+
</Border>
610+
<Border HorizontalAlignment="Left" VerticalAlignment="Top">
611+
<StackPanel Orientation="Horizontal" Margin="10">
612+
<Label Content="Tools" Foreground="{DynamicResource ButtonForeground}" />
613+
<Button Style="{StaticResource CustomButton}" x:Name="btnOpenADBLogCat" Margin="10,0,0,0" BorderBrush="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Top" Click="BtnOpenADBLogCat_Click" ToolTip="Start ADB logcat commandline">
614+
<Label Content="_ADB logcat" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
615+
</Button>
616+
<Button Style="{StaticResource CustomButton}" x:Name="btnAdbBindWifi" Margin="10,0,0,0" BorderBrush="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Top" Click="BtnAdbBindWifi_Click" IsEnabled="False" ToolTip="Bind Android device to wireless ADB">
617+
<Label Content="_Bind Wifi" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
618+
</Button>
619+
</StackPanel>
620+
</Border>
621+
</StackPanel>
622+
</Grid>
592623
<!-- 2nd part -->
593-
<Grid Grid.Row="1" VerticalAlignment="Top" HorizontalAlignment="Left">
594-
<Border>
595-
<StackPanel Orientation="Horizontal" Margin="10">
596-
<Button Style="{StaticResource CustomButton}" x:Name="btnOpenEditorLogsFolder" Margin="0" BorderBrush="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Top" Click="BtnOpenEditorLogsFolder_Click" ToolTip="Open Editor logs folder in Explorer">
597-
<Label Content="_Editor Logs" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
598-
</Button>
599-
<Button Style="{StaticResource CustomButton}" x:Name="btnOpenPlayerLogs" Margin="10,0,0,0" BorderBrush="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Top" Click="BtnOpenPlayerLogs_Click" ToolTip="Open Player logs folder in Explorer">
600-
<Label Content="_Player Logs" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
601-
</Button>
602-
<Button Style="{StaticResource CustomButton}" x:Name="btnOpenCrashLogs" Margin="10,0,0,0" BorderBrush="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Top" Click="BtnOpenCrashLogs_Click" ToolTip="Open Crash logs folder in Explorer">
603-
<Label Content="_Crash Logs" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
604-
</Button>
605-
<Button Style="{StaticResource CustomButton}" x:Name="btnAssetPackages" Margin="10,0,0,0" BorderBrush="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Top" ToolTip="Open assetstore downloads folder in Explorer" Click="BtnAssetPackages_Click">
606-
<Label Content="A_sset packages" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
607-
</Button>
608-
<Button Style="{StaticResource CustomButton}" x:Name="btnOpenADBLogCat" Margin="10,0,0,0" BorderBrush="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Top" Click="BtnOpenADBLogCat_Click" ToolTip="Start ADB logcat commandline">
609-
<Label Content="_ADB logcat" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
610-
</Button>
611-
<Button Style="{StaticResource CustomButton}" x:Name="btnAdbBindWifi" Margin="10,0,0,0" BorderBrush="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Top" Click="BtnAdbBindWifi_Click" IsEnabled="False" ToolTip="Bind Android device to wireless ADB">
612-
<Label Content="_Bind Wifi" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
613-
</Button>
614-
</StackPanel>
615-
</Border>
624+
<Grid Grid.Row="1" VerticalAlignment="Top">
625+
<StackPanel Orientation="Horizontal" Margin="0">
626+
<Label Content="Build Report" Foreground="{DynamicResource ButtonForeground}" HorizontalAlignment="Left" VerticalAlignment="Top" VerticalContentAlignment="Center" />
627+
<Button x:Name="btnClearBuildReport" Style="{StaticResource CustomButton}" ToolTip="Clear report" Content="🗑" Height="22" Width="22" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="16" Background="#FF3F3F46" Foreground="#FFC1C1C1" Margin="0,4,10,0" Padding="1,-2,1,1" BorderBrush="{x:Null}" Click="BtnClearBuildReport_Click" />
628+
<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" Background="#FF3F3F46" Foreground="#FFC1C1C1" Margin="0,4,10,0" Padding="1,-2,1,1" BorderBrush="{x:Null}" Click="BtnRefreshBuildReport_Click"/>
629+
<!--<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"/>-->
630+
</StackPanel>
631+
<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="#FFD8D8D8" HorizontalGridLinesBrush="#4C000000" VerticalGridLinesBrush="#19000000" AutoGenerateColumns="False" VerticalAlignment="Top">
632+
<DataGrid.Columns>
633+
<DataGridTextColumn Binding="{Binding Size}" ClipboardContentBinding="{x:Null}" Header="Size" IsReadOnly="True" MinWidth="75"/>
634+
<DataGridTextColumn Binding="{Binding Percentage}" ClipboardContentBinding="{x:Null}" Header="%" IsReadOnly="True" MinWidth="55" />
635+
<DataGridTextColumn Binding="{Binding Path}" ClipboardContentBinding="{x:Null}" Header="Path" IsReadOnly="True"/>
636+
</DataGrid.Columns>
637+
638+
<!-- sample data for testing -->
639+
<local:BuildReport Size="10.0 mb" Percentage="50.0%" Path="Assets/Textures/sample.png" />
640+
</DataGrid>
641+
616642
</Grid>
643+
617644
</Grid>
618645
</TabItem>
619646

‎UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ void Start()
9191
// clear updates grid
9292
dataGridUpdates.Items.Clear();
9393

94+
// clear buildreport grid
95+
gridBuildReport.Items.Clear();
96+
9497
// build notifyicon (using windows.forms)
9598
notifyIcon = new System.Windows.Forms.NotifyIcon();
9699
notifyIcon.Icon = new Icon(Application.GetResourceStream(new Uri("pack://application:,,,/Images/icon.ico")).Stream);
@@ -884,7 +887,7 @@ private void TxtSearchBoxUpdates_PreviewKeyDown(object sender, KeyEventArgs e)
884887

885888
private void BtnOpenEditorLogsFolder_Click(object sender, RoutedEventArgs e)
886889
{
887-
var logfolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Unity", "Editor");
890+
var logfolder = Tools.GetEditorLogsFolder();
888891
if (Directory.Exists(logfolder) == true)
889892
{
890893
if (Tools.LaunchExplorer(logfolder) == false)
@@ -1495,7 +1498,100 @@ private void GridRecent_ContextMenuOpening(object sender, ContextMenuEventArgs e
14951498
new KeyGesture(Key.Q, ModifierKeys.Alt)
14961499
}));
14971500

1501+
private void BtnRefreshBuildReport_Click(object sender, RoutedEventArgs e)
1502+
{
1503+
// TODO keep previous build report (total size?) so can compare to current one
1504+
1505+
var logFile = Path.Combine(Tools.GetEditorLogsFolder(), "Editor.log");
1506+
//Console.WriteLine("read editor log: " + logFile);
1507+
1508+
// TODO use streamreader to scan.. some log files are huge
1509+
1510+
string[] rows;
1511+
1512+
try
1513+
{
1514+
rows = File.ReadAllLines(logFile);
1515+
}
1516+
catch (Exception)
1517+
{
1518+
throw;
1519+
}
1520+
1521+
if (rows == null)
1522+
{
1523+
Console.WriteLine("Failed to open editor log: " + logFile);
1524+
return;
1525+
}
1526+
1527+
// TODO parse project folder info also, so can browse to selected file
1528+
1529+
int startRow = -1;
1530+
int endRow = -1;
1531+
// loop backwards to find latest report
1532+
for (int i = rows.Length - 1; i >= 0; i--)
1533+
{
1534+
// find start of build report
1535+
//if (rows[i].IndexOf("Build Report") == 0) // TODO take overview also
1536+
if (rows[i].IndexOf("Used Assets and files from the Resources folder, sorted by uncompressed size:") == 0)
1537+
{
1538+
startRow = i + 1;
1539+
1540+
// find end of report
1541+
for (int k = i; k < rows.Length; k++)
1542+
{
1543+
if (rows[k].IndexOf("-------------------------------------------------------------------------------") == 0)
1544+
{
1545+
endRow = k - 1;
1546+
break;
1547+
}
1548+
}
1549+
break;
1550+
}
1551+
}
1552+
1553+
if (startRow == -1 || endRow == -1)
1554+
{
1555+
Console.WriteLine("Failed to parse Build Report, start= " + startRow + " end= " + endRow);
1556+
return;
1557+
}
1558+
1559+
//Console.WriteLine("buildreport at " + startRow + " - " + endRow);
1560+
1561+
var reportSource = new BuildReport[endRow - startRow];
1562+
1563+
// get report rows
1564+
int index = 0;
1565+
for (int i = startRow; i < endRow; i++)
1566+
{
1567+
//Console.WriteLine(rows[i]);
1568+
var d = rows[i].Trim();
14981569

1570+
// get tab after kb
1571+
var space1 = d.IndexOf('\t');
1572+
// get % between % and path
1573+
var space2 = d.IndexOf('%');
1574+
1575+
if (space1 == -1 || space2 == -1)
1576+
{
1577+
Console.WriteLine("Failed to parse build report row: " + d);
1578+
continue;
1579+
}
1580+
1581+
var r = new BuildReport();
1582+
r.Size = d.Substring(0, space1);
1583+
r.Percentage = d.Substring(space1 + 2, space2 - space1 - 1);
1584+
r.Path = d.Substring(space2 + 2, d.Length - space2 - 2);
1585+
reportSource[index++] = r;
1586+
}
1587+
gridBuildReport.ItemsSource = reportSource;
1588+
1589+
}
1590+
1591+
private void BtnClearBuildReport_Click(object sender, RoutedEventArgs e)
1592+
{
1593+
gridBuildReport.ItemsSource = null;
1594+
}
14991595
} // class
15001596
} //namespace
15011597

‎UnityLauncherPro/Tools.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,10 @@ static void CreateEmptyProjectFolder(string path, string version)
873873
File.WriteAllText(settingsFile, "m_EditorVersion: " + version);
874874
}
875875

876+
public static string GetEditorLogsFolder()
877+
{
878+
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Unity", "Editor");
879+
}
876880

877881
} // class
878882
} // namespace

‎UnityLauncherPro/UnityLauncherPro.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<Generator>MSBuild:Compile</Generator>
7676
<SubType>Designer</SubType>
7777
</ApplicationDefinition>
78+
<Compile Include="Data\BuildReport.cs" />
7879
<Compile Include="Data\Tabs.cs" />
7980
<Compile Include="GetProjects.cs" />
8081
<Compile Include="GetUnityInstallations.cs" />

0 commit comments

Comments
 (0)
Please sign in to comment.