private void LoadPluginData(FileStream fs, bool headerOnly, string[] recFilter) //LoadPluginData(BinaryReader br, bool headerOnly, string[] recFilter) { bool oldHoldUpdates = HoldUpdates; SnipStreamWrapper snipStreamWrapper = null; try { ZLibWrapper.AllocateBuffers(); RecordsTace.InitListOfRecords(); snipStreamWrapper = new SnipStreamWrapper(fs); //BinaryReader br = new BinaryReader(fs); string s; uint recsize; bool IsOblivion = false; this.Filtered = recFilter != null && recFilter.Length > 0; HoldUpdates = true; s = ReadRecName(snipStreamWrapper.ReadBytes(4)); //s = ReadRecName(br); if (s != "TES4") { throw new Exception("File is not a valid TES4 plugin (Missing TES4 record)"); } // Check for file version by checking the position of the HEDR field in the file. (ie. how big are the record header.) snipStreamWrapper.JumpTo(20, SeekOrigin.Begin); //br.BaseStream.Position = 20; s = ReadRecName(snipStreamWrapper.ReadBytes(4)); //s = ReadRecName(br); if (s == "HEDR") { // Record Header is 20 bytes IsOblivion = true; } else { s = ReadRecName(snipStreamWrapper.ReadBytes(4)); //s = ReadRecName(br); if (s != "HEDR") { throw new Exception("File is not a valid TES4 plugin (Missing HEDR subrecord in the TES4 record)"); } // Record Header is 24 bytes. Or the file is illegal } snipStreamWrapper.JumpTo(4, SeekOrigin.Begin); //br.BaseStream.Position = 4; recsize = snipStreamWrapper.ReadUInt32(); //recsize = br.ReadUInt32(); try { this.AddRecord(new Record("TES4", recsize, snipStreamWrapper, IsOblivion)); } catch (Exception e) { MessageBox.Show(e.Message); } if (!headerOnly) { while (!snipStreamWrapper.Eof()) //while (br.PeekChar() != -1) { s = ReadRecName(snipStreamWrapper.ReadBytes(4)); //s = ReadRecName(br); recsize = snipStreamWrapper.ReadUInt32(); //recsize = br.ReadUInt32(); if (s == "GRUP") { try { this.AddRecord(new GroupRecord(recsize, snipStreamWrapper, IsOblivion, recFilter, false)); //this.AddRecord(new GroupRecord(recsize, br, IsOblivion, recFilter, false)); } catch (Exception e) { MessageBox.Show(e.Message); } } else { bool skip = recFilter != null && Array.IndexOf(recFilter, s) >= 0; if (skip) { long size = recsize + (IsOblivion ? 8 : 12); if ((snipStreamWrapper.ReadUInt32() & 0x00040000) > 0) //if ((br.ReadUInt32() & 0x00040000) > 0) { size += 4; // Add 4 bytes for compressed record since the decompressed size is not included in the record size. } snipStreamWrapper.JumpTo((int)size, SeekOrigin.Current); //br.BaseStream.Position += size; // just position past the data } else { try { this.AddRecord(new Record(s, recsize, snipStreamWrapper, IsOblivion)); //this.AddRecord(new Record(s, recsize, br, IsOblivion)); } catch (Exception e) { MessageBox.Show(e.Message); } } } } } } finally { snipStreamWrapper.CloseAndDisposeFileStream(); snipStreamWrapper = null; Clipboard.SetText("CompressedRecords:" + Environment.NewLine + string.Join <string>(string.Empty, RecordsTace.CompressedRecords) + "AllRecords:" + Environment.NewLine + string.Join <string>(string.Empty, RecordsTace.AllRecords) + "Max Size:" + ZLibWrapper.MaxOutputBufferPosition.ToString(CultureInfo.InvariantCulture)); ZLibWrapper.ReleaseBuffers(); ZLib.ReleaseInflater(); HoldUpdates = oldHoldUpdates; FireRecordListUpdate(this, this); } }