public void ReadFile(IDXFile.IDXEntry entry, Stream target, bool AdSize) { if (entry.IsCompressed) { if (entry.CompressedDataLength > int.MaxValue) { throw new NotSupportedException("File to big to decompress"); } var input = new byte[entry.CompressedDataLength]; Seek(entry.DataLBA); file.Read(input, 0, (int)entry.CompressedDataLength); try { byte[] output = KH2Compressor.decompress(input, entry.DataLength); target.Write(output, 0, output.Length); if (AdSize) { Console.WriteLine("Size (unpacked): {0}\r\n", output.Length); } } catch (Exception e) { Program.WriteError(" ERROR: Failed to decompress: " + e.Message); } } else { ReadFileBuffer(target, entry.Offset, entry.DataLength); } }
public void AppendFile(IDXFile.IDXEntry entry, Stream data) { if (data.Length > 0xFFFFFFFF) { throw new NotSupportedException("data too big to store"); } file.Seek(0, SeekOrigin.End); EnsureBoundary(); entry.DataLBA = (uint)(file.Position - offset) / 2048; data.CopyTo(file); EnsureBoundary(); }
public void RelinkEntry(uint hash, uint target) { IDXFile.IDXEntry t = entries.Find(e => e.Hash == target); if (t.Hash == 0) { throw new FileNotFoundException(); } entries.Add(new IDXFile.IDXEntry { Hash = hash, HashAlt = 0, Compression = t.Compression, DataLBA = t.DataLBA, DataLength = t.DataLength }); }
public void AddFile(IDXFile.IDXEntry file, Stream data) { img.AppendFile(file, data); idx.AddEntry(file); }
public Substream GetFileStream(IDXFile.IDXEntry entry) { return(new Substream(file, offset + entry.DataLBA * 2048, entry.IsCompressed ? entry.CompressedDataLength : entry.DataLength)); }
public void AddEntry(IDXFile.IDXEntry entry) { entries.Add(entry); }