public IList <IArchiveFileInfo> Load(Stream incStream, Stream datStream, string version) { using var incBr = new BinaryReaderX(incStream); var entryCount = (int)(incStream.Length / FileEntrySize); var entries = incBr.ReadMultiple <AAPackFileEntry>(entryCount); var nameMapping = AAPackSupport.GetMapping(version); var result = new IArchiveFileInfo[entryCount]; for (var i = 0; i < entryCount; i++) { var subStream = new SubStream(datStream, entries[i].offset, entries[i].compSize); var compressionMethod = NintendoCompressor.PeekCompressionMethod(subStream); var fileName = $"{i:00000000}.bin"; if (nameMapping.ContainsKey(entries[i].hash)) { fileName = nameMapping[entries[i].hash]; } result[i] = new AAPackArchiveFileInfo(subStream, fileName, NintendoCompressor.GetConfiguration(compressionMethod), entries[i].uncompSize, entries[i]); } return(result); }
public async Task Load(IFileSystem fileSystem, UPath filePath, LoadContext loadContext) { Stream incStream; Stream datStream; if (filePath.GetExtensionWithDot() == ".inc") { if (!fileSystem.FileExists(filePath.GetDirectory() / "pack.dat")) { throw new FileNotFoundException("pack.dat not found."); } incStream = await fileSystem.OpenFileAsync(filePath); datStream = await fileSystem.OpenFileAsync(filePath.GetDirectory() / "pack.dat"); } else { if (!fileSystem.FileExists(filePath.GetDirectory() / "pack.inc")) { throw new FileNotFoundException("pack.inc not found."); } incStream = await fileSystem.OpenFileAsync(filePath.GetDirectory() / "pack.inc"); datStream = await fileSystem.OpenFileAsync(filePath); } Files = _aatri.Load(incStream, datStream, AAPackSupport.GetVersion(loadContext.DialogManager)); }
public void Save(Stream incStream, Stream datStream, IList <IArchiveFileInfo> files) { using var bw = new BinaryWriterX(incStream); foreach (var file in files.Cast <AAPackArchiveFileInfo>()) { file.Entry.offset = (uint)datStream.Position; var writtenSize = file.SaveFileData(datStream); file.Entry.hash = IsUnmappedFile(file.FilePath.ToRelative().FullName) ? file.Entry.hash : AAPackSupport.CreateHash(file.FilePath.ToRelative().FullName); file.Entry.compSize = (uint)writtenSize; file.Entry.uncompSize = (uint)file.FileSize; bw.WriteType(file.Entry); } }