Exemple #1
0
            public VolFile(Stream stream, string filename)
            {
                Name        = filename;
                this.stream = stream;

                try
                {
                    stream.ReadBytes(4);
                    var directoryOffset = BitConverter.ToInt32(stream.ReadBytes(4), 0);
                    var fileCount       = BitConverter.ToInt32(stream.ReadBytes(4), 0);

                    stream.Seek(directoryOffset, SeekOrigin.Begin);
                    for (int i = 0; i < fileCount; i++)
                    {
                        var entryFilename = stream.ReadASCII(28);
                        entryFilename = entryFilename.Replace("\0", string.Empty);

                        var offset = BitConverter.ToInt32(stream.ReadBytes(4), 0);
                        var size   = BitConverter.ToInt32(stream.ReadBytes(4), 0);

                        // Ignore duplicate files
                        if (index.ContainsKey(entryFilename))
                        {
                            continue;
                        }

                        var info = new VolEntry()
                        {
                            Filename = entryFilename, Offset = offset, Size = size
                        };
                        index.Add(entryFilename, info);
                    }
                }
                catch
                {
                    Dispose();
                    throw;
                }
            }
Exemple #2
0
            public VolFile(Stream stream, string filename)
            {
                Name        = filename;
                this.stream = stream;

                var magicByte = stream.ReadASCII(4);

                if (magicByte != "VOL ")
                {
                    return;
                }

                var unknown1 = stream.ReadUInt32();

                var header = stream.ReadASCII(4);
                var zero   = stream.ReadUInt32();

                if (header != "volh" && zero != 0)
                {
                    return;
                }

                var volumeSection = stream.ReadASCII(4);

                if (volumeSection != "vols")
                {
                    return;
                }

                var unknown2        = stream.ReadUInt32();
                var directoryOffset = stream.ReadUInt32();

                var entryFilenames = new List <string>();

                while (true)
                {
                    var entryFilename = stream.ReadASCIIZ();
                    if (string.IsNullOrEmpty(entryFilename))
                    {
                        break;
                    }

                    entryFilenames.Add(entryFilename);
                }

                while (true)
                {
                    if (stream.ReadByte() != 0)
                    {
                        break;
                    }
                }

                stream.Seek(-1, SeekOrigin.Current);

                var volumeIndex = stream.ReadASCII(4);

                if (volumeIndex != "voli")
                {
                    return;
                }

                var totalSize = stream.ReadUInt32();

                foreach (var entryFilename in entryFilenames)
                {
                    var filenameIndex = stream.ReadUInt32();
                    var offset        = stream.ReadUInt32();
                    var size          = stream.ReadUInt32();
                    var compression   = stream.ReadByte();
                    var valid         = stream.ReadByte();
                    if (valid != 0 && valid != 1)
                    {
                        throw new InvalidDataException("Check byte contains invalid values");
                    }

                    // Ignore duplicate files
                    if (index.ContainsKey(entryFilename))
                    {
                        continue;
                    }

                    var info = new VolEntry()
                    {
                        Filename    = entryFilename,
                        Offset      = offset + 8,
                        Size        = size,
                        Compression = compression,
                    };

                    if (compression != 0)
                    {
                        throw new NotImplementedException("'RLE', 'LZ', 'LZH' are not yet supported.");
                    }

                    index.Add(entryFilename, info);
                }
            }