예제 #1
0
파일: AAPack.cs 프로젝트: obluda3/Kuriimu2
        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);
        }
예제 #2
0
        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));
        }
예제 #3
0
파일: AAPack.cs 프로젝트: obluda3/Kuriimu2
        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);
            }
        }