private void LoadPluginData(BinaryReader br, bool headerOnly, string[] recFilter) { bool oldHoldUpdates = HoldUpdates; try { string s; uint recsize; bool IsOblivion = false; Filtered = (recFilter != null && recFilter.Length > 0); HoldUpdates = true; Decompressor.Init(); 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.) br.BaseStream.Position = 20; s = ReadRecName(br); if (s == "HEDR") { // Record Header is 20 bytes IsOblivion = true; } else { 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 } br.BaseStream.Position = 4; recsize = br.ReadUInt32(); try { AddRecord(new Record("TES4", recsize, br, IsOblivion)); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } if (!headerOnly) { while (br.PeekChar() != -1) { s = ReadRecName(br); recsize = br.ReadUInt32(); if (s == "GRUP") { try { AddRecord(new GroupRecord(recsize, br, IsOblivion, recFilter, false)); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } } else { bool skip = recFilter != null && Array.IndexOf(recFilter, s) >= 0; if (skip) { long size = (recsize + (IsOblivion ? 8 : 12)); if ((br.ReadUInt32() & 0x00040000) > 0) { size += 4; // Add 4 bytes for compressed record since the decompressed size is not included in the record size. } br.BaseStream.Position += size; // just position past the data } else { try { AddRecord(new Record(s, recsize, br, IsOblivion)); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } } } } } } finally { HoldUpdates = oldHoldUpdates; FireRecordListUpdate(this, this); Decompressor.Close(); } }
private void LoadPluginData(BinaryReader br, bool headerOnly, string[] recFilter) { bool oldHoldUpdates = HoldUpdates; try { string s; uint recsize; bool IsOblivion = false; Filtered = (recFilter != null && recFilter.Length > 0); HoldUpdates = true; Decompressor.Init(); s = ReadRecName(br); if (s != "TES4") throw new Exception("File is not a valid TES4 plugin (Missing TES4 record)"); br.BaseStream.Position = 20; s = ReadRecName(br); if (s == "HEDR") { IsOblivion = true; } else { s = ReadRecName(br); if (s != "HEDR") throw new Exception( "File is not a valid TES4 plugin (Missing HEDR subrecord in the TES4 record)"); } br.BaseStream.Position = 4; recsize = br.ReadUInt32(); AddRecord(new Record("TES4", recsize, br, IsOblivion)); if (!headerOnly) { while (br.PeekChar() != -1) { s = ReadRecName(br); recsize = br.ReadUInt32(); if (s == "GRUP") { AddRecord(new GroupRecord(recsize, br, IsOblivion, recFilter, false)); } else { bool skip = recFilter != null && Array.IndexOf(recFilter, s) >= 0; if (skip) { long size = (recsize + (IsOblivion ? 8 : 12)); if ((br.ReadUInt32() & 0x00040000) > 0) size += 4; br.BaseStream.Position += size; // just read past the data } else AddRecord(new Record(s, recsize, br, IsOblivion)); } } } } finally { HoldUpdates = oldHoldUpdates; FireRecordListUpdate(this, this); Decompressor.Close(); } }