protected bool ParseVisitedSystem(DateTime time, TimeSpan tzoffset, string line, out JObject jo, out JournalLocOrJump je) { jo = new JObject(); jo["timestamp"] = time.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"); jo["event"] = "FSDJump"; je = null; try { Regex pattern; /* MKW: Use regular expressions to parse the log; much more readable and robust. * Example log entry: From ED 2.1 /1.6 {19:21:15} System:"Ooscs Fraae JR-L d8-112" StarPos:(-11609.469,639.594,20141.875)ly NormalFlight string rgexpstr = "{(?<Hour>\\d+):(?<Minute>\\d+):(?<Second>\\d+)} System:\"(?<SystemName>[^\"]+)\" StarPos:\\((?<Pos>.*?)\\)ly( +(?<TravelMode>\\w+))?"; new from beta3? {18:15:14} System:"Pleiades Sector HR-W d1-41" StarPos:(-83.969,-146.156,-334.219)ly Body:0 RelPos:(-1.19887e+07,-9.95573e+06,2.55124e+06)km Supercruise string rgexpstr = "{(?<Hour>\\d+):(?<Minute>\\d+):(?<Second>\\d+)} System:\"(?<SystemName>[^\"]+)\" StarPos:\\((?<Pos>.*?)\\)ly Body:(?<Body>\d+) StarPos:\\((?<Pos>.*?)\\)ly( +(?<TravelMode>\\w+))?"; Pre ED 2.1/1.6 {09:36:16} System:0(Thuechea JE-O b11-0) Body:1 Pos:(-6.67432e+009,7.3151e+009,-1.19125e+010) Supercruise * Also, please note that due to E:D bugs, these entries can be at the end of a line as well, not just on a line of their own. * The RegExp below actually just finds the pattern somewhere in the line, so it caters for rubbish at the end too. */ if (line.Contains("StarPos:")) // new ED 2.1 format { //{(?<Hour>\d+):(?<Minute>\d+):(?<Second>\d+)} System:"(?<SystemName>[^"]+)" StarPos:\((?<Pos>.*?)\)ly( +(?<TravelMode>\w+))? //{(?<Hour>\d+):(?<Minute>\d+):(?<Second>\d+)} System:"(?<SystemName>[^"]+)" StarPos:\((?<Pos>.*?)\)ly( +(?<TravelMode>\w+))? //string rgexpstr = "{(?<Hour>\\d+):(?<Minute>\\d+):(?<Second>\\d+)} System:\"(?<SystemName>[^\"]+)\" StarPos:\\((?<Pos>.*?)\\)ly( +(?<TravelMode>\\w+))?"; string rgexpstr; if (line.Contains("Body:")) rgexpstr = "System:\"(?<SystemName>[^\"]+)\" StarPos:\\((?<Pos>.*?)\\)ly Body:(?<Body>\\d+) RelPos:\\((?<RelPos>.*?)\\)km( +(?<TravelMode>\\w+))?"; else rgexpstr = "System:\"(?<SystemName>[^\"]+)\" StarPos:\\((?<Pos>.*?)\\)ly( +(?<TravelMode>\\w+))?"; pattern = new Regex(rgexpstr); Match match = pattern.Match(line); if (match != null && match.Success) { //sp.Nr = int.Parse(match.Groups["Body"].Value); jo["StarSystem"] = match.Groups["SystemName"].Value; string pos = match.Groups["Pos"].Value; try { string[] xyzpos = pos.Split(','); jo["StarPos"] = new JArray( double.Parse(xyzpos[0], CultureInfo.InvariantCulture), double.Parse(xyzpos[1], CultureInfo.InvariantCulture), double.Parse(xyzpos[2], CultureInfo.InvariantCulture) ); } catch { System.Diagnostics.Trace.WriteLine("System parse error 1:" + line); return false; } } else { System.Diagnostics.Trace.WriteLine("System parse error 1:" + line); return false; } } else { pattern = new Regex(@"System:\d+\((?<SystemName>.*?)\) Body:(?<Body>\d+) Pos:\(.*?\)( (?<TravelMode>\w+))?"); Match match = pattern.Match(line); if (match != null && match.Success) { //sp.Nr = int.Parse(match.Groups["Body"].Value); jo["StarSystem"] = match.Groups["SystemName"].Value; } else { System.Diagnostics.Trace.WriteLine("System parse error 2:" + line); return false; } } je = new JournalFSDJump(jo); return true; } catch { // MKW TODO: should we log bad lines? return false; } }
public bool ReadNetLogSystem(out JObject jo, out JournalLocOrJump je, Func<bool> cancelRequested = null, Stream stream = null, bool ownstream = false) { if (cancelRequested == null) cancelRequested = () => false; string line; try { if (stream == null) { stream = File.Open(this.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); ownstream = true; } while (!cancelRequested() && this.ReadLine(out line, stream)) { ParseLineTime(line); if (line.Contains("[PG]")) { if (line.Contains("[PG] [Notification] Left a playlist lobby")) this.CQC = false; if (line.Contains("[PG] Destroying playlist lobby.")) this.CQC = false; if (line.Contains("[PG] [Notification] Joined a playlist lobby")) this.CQC = true; if (line.Contains("[PG] Created playlist lobby")) this.CQC = true; if (line.Contains("[PG] Found matchmaking lobby object")) this.CQC = true; } int offset = line.IndexOf("} System:") - 8; if (offset >= 1 && ParseTime(line.Substring(offset, 8)) && this.CQC == false) { //Console.WriteLine(" RD:" + line ); if (line.Contains("ProvingGround")) continue; if (ParseVisitedSystem(this.LastLogTime, this.TimeZoneOffset, line.Substring(offset + 10), out jo, out je)) { // Remove some training systems if (je.StarSystem.Equals("Training", StringComparison.CurrentCultureIgnoreCase)) continue; if (je.StarSystem.Equals("Destination", StringComparison.CurrentCultureIgnoreCase)) continue; if (je.StarSystem.Equals("Altiris", StringComparison.CurrentCultureIgnoreCase)) continue; return true; } } } } finally { if (ownstream) { stream.Dispose(); } } jo = null; je = null; return false; }