internal void ReadHeader(PBO pbo) { try { _client.PushOnEvent($"Starting Header Read for {pbo.LongName}", EventType.Debug); //Get the signature PBOFile sig = ReadDatablock(); //_client.PushOnEvent($"Signature read Packing Method: {sig.PackingMethod}", EventType.Debug); //Look for a prefix if (sig.PackingMethod == PackingMethod.Product) { string possiblePrefix; do { possiblePrefix = ReadString(); if (possiblePrefix != string.Empty) { pbo.Prefix = new PBOPrefix(possiblePrefix, ReadString()); } } while (possiblePrefix != string.Empty); } //Read all file header structs PBOFile file; do { file = ReadDatablock(); if (file.FileName != string.Empty) { pbo.Files.Add(file); _client.PushOnEvent($"File found: {file.FileName}", EventType.Info); } } while (file.FileName != string.Empty); //Update the file offsets for each file foreach (PBOFile pbofile in pbo.Files) { pbofile.Offset = BaseStream.Position; BaseStream.Position += pbofile.DataSize; } _client.PushOnEvent($"Header read successfully from {pbo.LongName}", EventType.Debug); } catch (Exception ex) { _client.PushOnEvent($"Failed to read header for {pbo.LongName}\n {ex.Message}", EventType.Error); } }
/// <summary> /// Extract specific file data and returns it as a byte[] /// </summary> /// <param name="file"></param> /// <returns></returns> public byte[] ExtractFileData(PBOFile file) { file.Reader.BaseStream.Seek(file.Offset, SeekOrigin.Begin); return(file.Reader.ReadBytes(file.DataSize)); }