Ejemplo n.º 1
0
        public static PAKArchive ReadNew(Stream baseStream)
        {
            if (!baseStream.CanRead || !baseStream.CanSeek)
            {
                throw new InvalidDataException("PAKArchive stream has to be readable and seekable");
            }
            PAKArchive archive = new PAKArchive(baseStream);

            using BinaryReader reader = new BinaryReader(baseStream, Encoding.UTF8, leaveOpen: true);
            if (reader.ReadUInt32() != 0)
            {
                throw new InvalidDataException("Invalid PAKArchive magic (has to be 0x00000000)");
            }

            uint count = reader.ReadUInt32();

            for (uint i = 0; i < count; i++)
            {
                PAKArchiveEntry entry = PAKArchiveEntry.ReadNew(reader);
                string          key   = getPathKey(entry.path);
                archive.entries[key] = entry;

                var parent = entry.path.Parent?.WithoutDirectoryMarker();
                while (parent?.StaysInbound ?? false)
                {
                    archive.directories[getPathKey(parent)] = parent;
                    parent = parent.Parent?.WithoutDirectoryMarker();
                }
            }
            archive.baseOffset = (UInt32)baseStream.Position;
            return(archive);
        }
Ejemplo n.º 2
0
        public Stream ReadFile(string pathString)
        {
            string          pathKey = getPathKey(new FilePath(pathString));
            PAKArchiveEntry entry   = entries[pathKey];

            stream.Position = baseOffset + entry.offset;
            return(new RangeStream(stream, entry.length, false, false));
        }