void SerializeAllocationTable(IO.EndianStream s) { long entries_count = FileEntries.Count; s.Stream(ref entries_count); if (entries_count > 0) { if (s.IsReading) { FileEntries.Capacity = (int)entries_count; for (int x = 0; x < entries_count; x++) { var e = new CaPackageEntry(); s.Stream(ref e); FileEntries.Add(e); } } else if (s.IsWriting) { foreach (var e in FileEntries) { var e_copy = e; s.Stream(ref e_copy); } } } }
public byte[] ReadEntryBytes(IO.EndianStream s, CaPackageEntry entry) { Contract.Requires <ArgumentNullException>(s != null); if (entry.Offset < 0 || entry.Offset > s.BaseStream.Length) { throw new InvalidOperationException(string.Format( "File entry '{0}' offset @{1} is not within length #{2} of file {3}", entry.Name, entry.Offset, s.BaseStream.Length, s.StreamName)); } long endOffset = entry.Offset + entry.Size; if (endOffset < 0 || endOffset > s.BaseStream.Length) { throw new InvalidOperationException(string.Format( "File entry '{0}' @{1} with size #{2} is not within length #{3} of file {4}", entry.Name, entry.Offset, entry.Size, s.BaseStream.Length, s.StreamName)); } s.Seek(entry.Offset); byte[] bytes = new byte[entry.Size]; s.Stream(bytes); return(bytes); }
public void WriteEntryBytes(IO.EndianStream s, ref CaPackageEntry entry, Stream entryStream) { Contract.Requires <ArgumentNullException>(s != null); Contract.Requires <ArgumentNullException>(entryStream != null); Contract.Assume(entry.Name.IsNotNullOrEmpty()); Contract.Assume(entry.Offset == 0); Contract.Assume(entry.Size == 0); entry.Offset = s.BaseStream.Position; entry.Size = entryStream.Length; entryStream.CopyTo(s.BaseStream); }
void ExpandEntryToFile(string workPath, CaPackageEntry entry) { string file_path = Path.Combine(workPath, entry.Name); if (!ExpanderOptions.Test(CaPackageFileExpanderOptions.DontOverwriteExistingFiles)) { if (File.Exists(file_path)) { if (VerboseOutput != null) { VerboseOutput.WriteLine("\tSkipping chunk, output file already exists: {0}", file_path); } return; } } using (var fs = File.OpenWrite(file_path)) { var entry_bytes = mPkgFile.ReadEntryBytes(mPkgStream, entry); fs.Write(entry_bytes, 0, entry_bytes.Length); } }