Skip to content

Commit c0c6ce6

Browse files
committed
build report reader: add trycatch and cleanup streams
1 parent 9a29eab commit c0c6ce6

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,16 +1735,22 @@ private void BtnRefreshBuildReport_Click(object sender, RoutedEventArgs e)
17351735
if (File.Exists(logFile) == false) return;
17361736

17371737
// NOTE this can fail on a HUGE log file
1738-
FileStream fs = new FileStream(logFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
1739-
StreamReader sr = new StreamReader(fs);
17401738
List<string> rows = new List<string>();
1741-
while (!sr.EndOfStream)
1739+
try
17421740
{
1743-
rows.Add(sr.ReadLine());
1741+
using (FileStream fs = new FileStream(logFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
1742+
{
1743+
using (StreamReader sr = new StreamReader(fs))
1744+
{
1745+
// now we collect all lines, but could collect only those needed below
1746+
while (!sr.EndOfStream)
1747+
{
1748+
rows.Add(sr.ReadLine());
1749+
}
1750+
}
1751+
}
17441752
}
1745-
1746-
1747-
if (rows == null)
1753+
catch (Exception)
17481754
{
17491755
Console.WriteLine("Failed to open editor log: " + logFile);
17501756
return;
@@ -1786,7 +1792,7 @@ private void BtnRefreshBuildReport_Click(object sender, RoutedEventArgs e)
17861792

17871793
if (startRow == -1 || endRow == -1)
17881794
{
1789-
Console.WriteLine("Failed to parse Build Report, start= " + startRow + " end= " + endRow);
1795+
Console.WriteLine("Failed to parse Editor.Log (probably no build report there), start= " + startRow + " end= " + endRow);
17901796
return;
17911797
}
17921798

0 commit comments

Comments
 (0)