public void Add(string name) { TES4File file = new TES4File(this, this.path, name); this.files.Add(file); this.indexedFiles.Add(name, file); }
/* * TES4LoadedRecord constructor. */ public TES4LoadedRecord(TES4File placedFile, TES4RecordType type, int formid, int size, int flags) { this.placedFile = placedFile; this.RecordType = type; this.formid = formid; this.size = size; this.flags = flags; }
/* * TES4Record constructor. */ public TES4Record(TES4File placedFile, TES4RecordType type, int formid, int size, int flags) { this.placedFile = placedFile; this.RecordType = type; this.formIDPrivate = formid; this.size = size; this.flags = flags; formIDLazy = new Lazy <int>(() => this.placedFile.Expand(this.formIDPrivate)); }
/* * @throws InvalidESFileException */ public IEnumerable <ITES4Record> Load(FileStream fileContents, TES4File file, TES4GrupLoadScheme scheme, bool isTopLevelGrup) { long startPosition = fileContents.Position; byte[] headerBytes = fileContents.Read(GRUP_HEADER_SIZE); string headerString = TES4File.ISO_8859_1.Value.GetString(headerBytes); if (headerString.Substring(0, 4) != "GRUP") { throw new InvalidESFileException("Invalid GRUP magic, found " + headerString.Substring(0, 4)); } this.Size = PHPFunction.UnpackV(headerBytes.Skip(4).Take(4).ToArray()); if (isTopLevelGrup) { this.Type = TES4RecordType.First(headerString.Substring(8, 4)); } long end = startPosition + this.Size; while (fileContents.Position < end) { //Ineffective lookahead, but oh well byte[] nextEntryTypeBytes = new byte[4]; int bytesRead = fileContents.Read(nextEntryTypeBytes); if (bytesRead == 0) { break; } fileContents.Seek(-4, SeekOrigin.Current); string nextEntryType = TES4File.ISO_8859_1.Value.GetString(nextEntryTypeBytes); switch (nextEntryType) { case "GRUP": { TES4Grup nestedGrup = new TES4Grup(); foreach (var subrecord in nestedGrup.Load(fileContents, file, scheme, false)) { yield return(subrecord); } break; } default: { byte[] recordHeaderBytes = fileContents.Read(TES4LoadedRecord.RECORD_HEADER_SIZE); string recordTypeString = TES4File.ISO_8859_1.Value.GetString(recordHeaderBytes.Take(4).ToArray()); TES4RecordType recordType = TES4RecordType.First(recordTypeString); int recordSize = PHPFunction.UnpackV(recordHeaderBytes.Skip(4).Take(4).ToArray()); int recordFlags = PHPFunction.UnpackV(recordHeaderBytes.Skip(8).Take(4).ToArray()); int recordFormid = PHPFunction.UnpackV(recordHeaderBytes.Skip(12).Take(4).ToArray()); if (scheme.ShouldLoad(recordType)) { TES4LoadedRecord record = new TES4LoadedRecord(file, recordType, recordFormid, recordSize, recordFlags); record.Load(fileContents, scheme.GetRulesFor(recordType)); this.records.Add(record); yield return(record); } else { fileContents.Seek(recordSize, SeekOrigin.Current); } break; } } } }