public static bool scanLogFile(String logFile, ref WurmDateTime cur, ref WurmDateTimeStamp stamp, DateTime maxDate) { bool foundMatch = false; System.Diagnostics.Debug.WriteLine(logFile); FileStream stream = new FileStream(logFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); StreamReader reader = new StreamReader(stream); Regex LoggingStarted = new Regex(@"^Logging started (\d{4}-\d{2}-\d{2})$"); Regex LogEntry = new Regex(@"^\[(\d\d):(\d\d):(\d\d)] (.*)$"); DateTime lastLogDate = new DateTime(); while (!reader.EndOfStream) { String line = reader.ReadLine(); Match match = LoggingStarted.Match(line); if (match.Success) { lastLogDate = DateTime.Parse(match.Groups[1].Value); continue; } match = LogEntry.Match(line); if (match.Success) { DateTime currentLogDate = new DateTime( lastLogDate.Year, lastLogDate.Month, lastLogDate.Day, Int16.Parse(match.Groups[1].Value), Int16.Parse(match.Groups[2].Value), Int16.Parse(match.Groups[3].Value), DateTimeKind.Local); while (currentLogDate < lastLogDate) { currentLogDate = currentLogDate.AddDays(1); // Handle day wrap around } lastLogDate = currentLogDate; if (currentLogDate > maxDate) { System.Diagnostics.Debug.WriteLine(currentLogDate + " > " + maxDate + ". Exiting"); break; } if (parseDateTime(match.Groups[4].Value, ref cur)) { System.Diagnostics.Debug.WriteLine(lastLogDate + ": new Date " + match.Groups[4].Value); stamp.wurm = cur; stamp.real = lastLogDate; foundMatch = true; } } } reader.Close(); stream.Close(); return(foundMatch); }
public static bool scanLogFile(String logFile, ref WurmDateTime cur, ref WurmDateTimeStamp stamp, DateTime maxDate) { bool foundMatch = false; System.Diagnostics.Debug.WriteLine(logFile); FileStream stream = new FileStream(logFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); StreamReader reader = new StreamReader(stream); Regex LoggingStarted = new Regex(@"^Logging started (\d{4}-\d{2}-\d{2})$"); Regex LogEntry = new Regex(@"^\[(\d\d):(\d\d):(\d\d)] (.*)$"); DateTime lastLogDate = new DateTime(); while (!reader.EndOfStream) { String line = reader.ReadLine(); Match match = LoggingStarted.Match(line); if (match.Success) { lastLogDate = DateTime.Parse(match.Groups[1].Value); continue; } match = LogEntry.Match(line); if (match.Success) { DateTime currentLogDate = new DateTime( lastLogDate.Year, lastLogDate.Month, lastLogDate.Day, Int16.Parse(match.Groups[1].Value), Int16.Parse(match.Groups[2].Value), Int16.Parse(match.Groups[3].Value), DateTimeKind.Local); while (currentLogDate < lastLogDate) currentLogDate = currentLogDate.AddDays(1); // Handle day wrap around lastLogDate = currentLogDate; if (currentLogDate > maxDate) { System.Diagnostics.Debug.WriteLine(currentLogDate + " > " + maxDate + ". Exiting"); break; } if (parseDateTime(match.Groups[4].Value, ref cur)) { System.Diagnostics.Debug.WriteLine(lastLogDate + ": new Date " + match.Groups[4].Value); stamp.wurm = cur; stamp.real = lastLogDate; foundMatch = true; } } } reader.Close(); stream.Close(); return foundMatch; }