Beispiel #1
0
        private static byte[] CreateDirEntryBytes(DirEntry dirEntry, FileHeader.Version version)
        {
            byte[]       result       = new byte[DirEntry.GetSize(version)];
            MemoryStream memoryStream = new MemoryStream(result);
            BinaryWriter writer       = new BinaryWriter(memoryStream);

            byte[] filenameBytes = Encoding.Unicode.GetBytes(dirEntry.filename);
            writer.Write(filenameBytes, 0, (int)Math.Min(DirEntry.GetFilenameSize(), filenameBytes.Length));
            writer.BaseStream.Position = DirEntry.GetFilenameSize();

            FileHeader.WriteUIntVersionAware(writer, dirEntry.offset, version);
            FileHeader.WriteUIntVersionAware(writer, dirEntry.compressed, version);
            FileHeader.WriteUIntVersionAware(writer, dirEntry.filesize, version);
            FileHeader.WriteUIntVersionAware(writer, dirEntry.timestamp, version);
            FileHeader.WriteUIntVersionAware(writer, dirEntry.unknown, version);

            return(result);
        }
        private void ReadDirEntries(byte[] buffer, BlockInfo block, RDAMemoryResidentHelper mrm)
        {
            MemoryStream memoryStream = new MemoryStream(buffer);
            BinaryReader reader       = new BinaryReader(memoryStream);

            for (uint fileId = 0; fileId < block.fileCount; ++fileId)
            {
                byte[] fileNameBytes  = reader.ReadBytes((int)DirEntry.GetFilenameSize());
                string fileNameString = Encoding.Unicode.GetString(fileNameBytes).Replace("\0", "");

                DirEntry dirEntry = new DirEntry
                {
                    filename   = fileNameString,
                    offset     = ReadUIntVersionAware(reader),
                    compressed = ReadUIntVersionAware(reader),
                    filesize   = ReadUIntVersionAware(reader),
                    timestamp  = ReadUIntVersionAware(reader),
                    unknown    = ReadUIntVersionAware(reader),
                };

                RDAFile rdaFile = RDAFile.FromUnmanaged(fileHeader.version, dirEntry, block, read, mrm);
                rdaFileEntries.Add(rdaFile);
            }
        }