Skip to content

Commit 95f4377

Browse files
committed
use streamreader for editor.log file (to fix "file is used by another process"), #build
1 parent 6dac9d8 commit 95f4377

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

UnityLauncherPro/MainWindow.xaml.cs

+17-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Drawing; // for notifyicon
99
using System.IO;
1010
using System.Runtime.InteropServices;
11+
using System.Text;
1112
using System.Threading;
1213
using System.Threading.Tasks;
1314
using System.Windows;
@@ -1505,16 +1506,25 @@ private void BtnRefreshBuildReport_Click(object sender, RoutedEventArgs e)
15051506
var logFile = Path.Combine(Tools.GetEditorLogsFolder(), "Editor.log");
15061507
//Console.WriteLine("read editor log: " + logFile);
15071508

1508-
// TODO use streamreader to scan.. some log files are huge
1509-
1510-
string[] rows;
1509+
List<string> rows = new List<string>();
15111510

15121511
try
15131512
{
1514-
rows = File.ReadAllLines(logFile);
1513+
using (var fs = new FileStream(logFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
1514+
using (var sr = new StreamReader(fs, Encoding.Default))
1515+
{
1516+
while (sr.EndOfStream == false)
1517+
{
1518+
// TODO only start collecting when find build report start, and need to reset list if another build report later
1519+
var r = sr.ReadLine();
1520+
rows.Add(r);
1521+
}
1522+
}
1523+
15151524
}
1516-
catch (Exception)
1525+
catch (Exception ex)
15171526
{
1527+
Console.WriteLine(ex.Message);
15181528
throw;
15191529
}
15201530

@@ -1529,7 +1539,7 @@ private void BtnRefreshBuildReport_Click(object sender, RoutedEventArgs e)
15291539
int startRow = -1;
15301540
int endRow = -1;
15311541
// loop backwards to find latest report
1532-
for (int i = rows.Length - 1; i >= 0; i--)
1542+
for (int i = rows.Count - 1; i >= 0; i--)
15331543
{
15341544
// find start of build report
15351545
//if (rows[i].IndexOf("Build Report") == 0) // TODO take overview also
@@ -1538,7 +1548,7 @@ private void BtnRefreshBuildReport_Click(object sender, RoutedEventArgs e)
15381548
startRow = i + 1;
15391549

15401550
// find end of report
1541-
for (int k = i; k < rows.Length; k++)
1551+
for (int k = i; k < rows.Count; k++)
15421552
{
15431553
if (rows[k].IndexOf("-------------------------------------------------------------------------------") == 0)
15441554
{

0 commit comments

Comments
 (0)