public ReplayKey DecodeNext(BinaryReader reader) { try { var time = reader.ReadUInt32(); var size = reader.ReadUInt32(); Debug.WriteLine("time: " + time); Debug.WriteLine("size: " + size); var position = reader.BaseStream.Position; var key = (Data.ReplayKeys)reader.ReadInt32(); if (!Enum.IsDefined(key)) { Debug.WriteLine($"Key doesn't exist {(int) key} @ length {reader.BaseStream.Position}"); var result = new ReplayKey(TimeSpan.FromMilliseconds(time) * 100, key, HandleUnhandled(reader, (int)size)); //new Tuple<Data.ReplayKeys, object>(key,null); reader.BaseStream.Position = position + size; return(result); } else { Debug.WriteLine($"Key found {(int) key} @ length {reader.BaseStream.Position}"); var result = new ReplayKey(TimeSpan.FromMilliseconds(time) * 100, key, Decode(key, reader)); var possibleLength = reader.BaseStream.Position - (position - size); if (reader.BaseStream.Position > position + size) { Debug.WriteLine("Exceeded length by " + possibleLength + "bytes"); } else if (reader.BaseStream.Position < position + size) { Debug.WriteLine("lost length by " + possibleLength + "bytes"); //result.SubKey.Add( DecodeSubNext(reader, (int)possibleLength,result)); //Debug.WriteLine(BitConverter.ToString(reader.ReadBytes((int) possibleLength))); result.SubKey.Add(HandleUnhandled(reader, (int)possibleLength)); } reader.BaseStream.Position = position + size; return(result); } } catch (EndOfStreamException ex) { Debug.WriteLine(ex); } return(new ReplayKey(TimeSpan.Zero, (Data.ReplayKeys)(-1), null)); }
private ReplayKey DecodeSubNext(BinaryReader reader, int remainingLength, ReplayKey originalKey) { try { var key = (Data.ReplayKeys)reader.ReadInt32(); var position = reader.BaseStream.Position; var totalSize = position + remainingLength; if (!Enum.IsDefined(key)) { Debug.WriteLine($"Key doesn't exist {(int) key} @ length {reader.BaseStream.Position}"); var result = new ReplayKey(originalKey.TimeStamp, key, HandleUnhandled(reader, (int)(remainingLength - (reader.BaseStream.Position - position)))); //new Tuple<Data.ReplayKeys, object>(key,null); return(result); } else { Debug.WriteLine($"Key found {(int) key} @ length {reader.BaseStream.Position}"); var result = new ReplayKey(originalKey.TimeStamp, key, Decode(key, reader)); var possibleLength = reader.BaseStream.Position - position; if (reader.BaseStream.Position > totalSize) { Debug.WriteLine("Exceeded length by " + possibleLength + "bytes"); } else if (reader.BaseStream.Position < totalSize) { remainingLength = (int)(remainingLength - (reader.BaseStream.Position - position)); Debug.WriteLine("lost length by " + possibleLength + "bytes"); result.SubKey.Add(DecodeSubNext(reader, (int)possibleLength, originalKey)); //Debug.WriteLine(BitConverter.ToString(reader.ReadBytes((int) possibleLength))); } return(result); } } catch (EndOfStreamException ex) { Debug.WriteLine(ex); } return(new ReplayKey(TimeSpan.Zero, (Data.ReplayKeys)(-1), null)); }
static void ParseReplayLog(string replayName, Stream file) { var key = new ReplayKey( replayName.Substring(0, 2), DateTime.ParseExact(replayName.Substring(3, 19), "yyyy-MM-dd-HH-mm-ss", CultureInfo.InvariantCulture) ); if (ExistingRecords.Contains(key)) { return; } var stream = PboFile.FromStream(file).OpenFile("log.txt"); if (stream != null) { using (var input = new StreamReader(stream)) { var p = new ReplayProcessor(input); Replay replay; try { replay = p.ProcessReplay(); if (replay != null) { Interlocked.Increment(ref counterParsed); } } catch (ParseException e) { exceptions.Writer.TryWrite(Tuple.Create(replayName, (Exception)e)); replay = p.GetResult(); } Interlocked.Increment(ref counterProcessed); if (replay != null) { replay.Server = replayName.Substring(0, 2); queue.Writer.TryWrite(replay); } } } }