예제 #1
0
        public static AFS_Directory_Entry FromStream(FileStream stream)
        {
            var entry = new AFS_Directory_Entry();

            entry.filename   = BinaryHelper.ReadString(stream, 32);
            entry.year       = BinaryHelper.ReadUInt16(stream);
            entry.month      = BinaryHelper.ReadUInt16(stream);
            entry.day        = BinaryHelper.ReadUInt16(stream);
            entry.hour       = BinaryHelper.ReadUInt16(stream);
            entry.minute     = BinaryHelper.ReadUInt16(stream);
            entry.second     = BinaryHelper.ReadUInt16(stream);
            entry.fileLength = BinaryHelper.ReadUInt32(stream);

            return(entry);
        }
예제 #2
0
        public static AFS FromStream(FileStream stream)
        {
            var afs = new AFS();

            afs.header   = BinaryHelper.ReadString(stream, 4);
            afs.numFiles = BinaryHelper.ReadUInt32(stream);

            afs.tableOfContents = new AFS_TOC_Entry[afs.numFiles];

            for (var i = 0; i < afs.numFiles; ++i)
            {
                var toc_entry = AFS_TOC_Entry.FromStream(stream);
                afs.tableOfContents[i] = toc_entry;
            }

            afs.filenameDirectoryOffset = BinaryHelper.ReadUInt32(stream);
            afs.filenameDirectoryLength = BinaryHelper.ReadUInt32(stream);

            afs.files = new AFS_File[afs.numFiles];
            for (var i = 0; i < afs.numFiles; ++i)
            {
                var toc_entry = afs.tableOfContents[i];
                var file      = AFS_File.FromStream(stream, toc_entry.offset, toc_entry.length);
                afs.files[i] = file;
            }

            afs.directory = new AFS_Directory_Entry[afs.numFiles];

            // hmm
            var dataBlockStart             = afs.tableOfContents[0].offset;
            var directoryOffsetStreamStart = dataBlockStart - 8;

            stream.Position = directoryOffsetStreamStart;
            stream.Position = BinaryHelper.ReadUInt32(stream);

            // HMMM
            // stream.Position = afs.filenameDirectoryOffset;

            for (var i = 0; i < afs.numFiles; ++i)
            {
                var toc_entry       = afs.tableOfContents[i];
                var directory_entry = AFS_Directory_Entry.FromStream(stream);
                afs.directory[i] = directory_entry;
            }

            return(afs);
        }