Skip to content

Commit 3dd661e

Browse files
fix: handle new line characters in entity names
1 parent fa369ea commit 3dd661e

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

HearthWatcher/LogReader/LogFileWatcher.cs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ public class LogFileWatcher
2424
private DateTime _startingPoint;
2525
private bool _stop;
2626
private Thread _thread;
27-
/**
28-
* When the Millhouse hero power is logged in the korean localization there is a line break in the entity name.
29-
* This causes the parser to get stuck on this broken line and stop reading new power information.
30-
*/
31-
const int KoreanMillhouseBugHack = 54253;
3227

3328
/**
3429
* Limit the amount of LogLines we keep in the ConcurrentQueue, so that we don't run out of memory.
@@ -218,12 +213,31 @@ private void ReadLogFile()
218213
using(var sr = new StreamReader(fs))
219214
{
220215
string line;
221-
while(!sr.EndOfStream && _lines.Count < MAX_LOG_LINE_BUFFER && (line = sr.ReadLine()) != null)
216+
var sb = new StringBuilder();
217+
while(!sr.EndOfStream && _lines.Count < MAX_LOG_LINE_BUFFER)
222218
{
219+
sb.Clear();
220+
var foundEndOfLine = false;
221+
var prevChar = '\0';
222+
while(!sr.EndOfStream)
223+
{
224+
var c = (char)sr.Read();
225+
if(c == '\n' && prevChar == '\r')
226+
{
227+
foundEndOfLine = true;
228+
break;
229+
}
230+
sb.Append(c);
231+
prevChar = c;
232+
}
233+
if(!foundEndOfLine) break;
234+
235+
line = sb.ToString(0, sb.Length - 1);
236+
223237
if(line.StartsWith("D "))
224238
{
225239
var next = sr.Peek();
226-
if(!sr.EndOfStream && !(next == 'D' || next == 'W' || next == 'E' || next == KoreanMillhouseBugHack))
240+
if(!sr.EndOfStream && !(next == 'D' || next == 'W' || next == 'E'))
227241
break;
228242
var logLine = new LogLine(Info.Name, line);
229243
if((!Info.HasFilters || (Info.StartsWithFilters?.Any(x => logLine.LineContent.StartsWith(x)) ?? false)
@@ -275,7 +289,7 @@ private void FindInitialOffset()
275289
for(var i = 0; i < 4096; i++)
276290
{
277291
skip++;
278-
if(buffer[i] == '\n')
292+
if(i > 0 && buffer[i - 1] == '\r' && buffer[i] == '\n')
279293
break;
280294
}
281295
offset -= skip;
@@ -323,7 +337,7 @@ public DateTime FindEntryPoint(string logDirectory, string[] str)
323337
for(var i = 0; i < 4096; i++)
324338
{
325339
skip++;
326-
if(buffer[i] == '\n')
340+
if(i > 0 && buffer[i - 1] == '\r' && buffer[i] == '\n')
327341
break;
328342
}
329343
if(skip >= 4096)

HearthWatcher/LogReader/LogLine.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class LogLine
1616

1717
public LogLine(string ns, string line)
1818
{
19+
line = line.Replace("\n", "").Trim();
1920
Namespace = ns;
2021
Line = line;
2122
var match = _regex.Match(line);

0 commit comments

Comments
 (0)