コード例 #1
0
        private FileIndexEntry[] ReadUOPEntries()
        {
            List<FileIndexEntry> entries = new List<FileIndexEntry>();

            _stream = new FileStream(_indexPath, FileMode.Open);

            using (BinaryReader reader = new BinaryReader(_stream))
            {
                UopHeader header = new UopHeader()
                {
                    MagicNumber = reader.ReadInt32(),
                    Version = reader.ReadInt32(),
                    Misc = reader.ReadInt32(),
                    StartAddress = reader.ReadInt64(),
                    BlockSize = reader.ReadInt32(),
                    FileCount = reader.ReadInt32(),
                };

                if (header.MagicNumber != UOPMagicNumber)
                {
                    Tracer.Error("{0} is not a UOP file, magic number not found!", _indexPath);
                    return new FileIndexEntry[0];
                }

                long nextBlockAddress = header.StartAddress;

                List<UopIndexEntry> uopEntries = new List<UopIndexEntry>();

                while (nextBlockAddress != 0L)
                {
                    _stream.Seek(nextBlockAddress, SeekOrigin.Begin);

                    UopBlock block = new UopBlock()
                    {
                        FileCount = reader.ReadInt32(),
                        NextBlockAddress = reader.ReadInt64()
                    };

                    for (int i = 0; i < block.FileCount; i++)
                    {
                        UopIndexEntry uopEntry = new UopIndexEntry()
                        {
                            Lookup = reader.ReadInt64(),
                            Length = reader.ReadInt32(),
                            CompressedSize = reader.ReadInt32(),
                            DecompressedSize = reader.ReadInt32(),
                            EntryHash = reader.ReadInt64(),
                            BlockHash = reader.ReadInt32(),
                            IsCompressed = reader.ReadInt16() == 1,
                        };

                        uopEntries.Add(uopEntry);
                    }

                    nextBlockAddress = block.NextBlockAddress;
                }

                foreach (var uopEntry in uopEntries)
                {
                    FileIndexEntry entry = new FileIndexEntry()
                    {
                        Lookup = (int)uopEntry.Lookup,
                        Length = uopEntry.DecompressedSize
                    };

                    entries.Add(entry);
                }
            }

            return entries.ToArray();
        }
コード例 #2
0
ファイル: FileIndex.cs プロジェクト: nogu3ira/essence-udk
        private FileIndexEntry[] ReadUOPEntries()
        {
            List <FileIndexEntry> entries = new List <FileIndexEntry>();

            _stream = new FileStream(_indexPath, FileMode.Open);

            using (BinaryReader reader = new BinaryReader(_stream))
            {
                UopHeader header = new UopHeader()
                {
                    MagicNumber  = reader.ReadInt32(),
                    Version      = reader.ReadInt32(),
                    Misc         = reader.ReadInt32(),
                    StartAddress = reader.ReadInt64(),
                    BlockSize    = reader.ReadInt32(),
                    FileCount    = reader.ReadInt32(),
                };

                if (header.MagicNumber != UOPMagicNumber)
                {
                    Tracer.Error("{0} is not a UOP file, magic number not found!", _indexPath);
                    return(new FileIndexEntry[0]);
                }

                long nextBlockAddress = header.StartAddress;

                List <UopIndexEntry> uopEntries = new List <UopIndexEntry>();

                while (nextBlockAddress != 0L)
                {
                    _stream.Seek(nextBlockAddress, SeekOrigin.Begin);

                    UopBlock block = new UopBlock()
                    {
                        FileCount        = reader.ReadInt32(),
                        NextBlockAddress = reader.ReadInt64()
                    };

                    for (int i = 0; i < block.FileCount; i++)
                    {
                        UopIndexEntry uopEntry = new UopIndexEntry()
                        {
                            Lookup           = reader.ReadInt64(),
                            Length           = reader.ReadInt32(),
                            CompressedSize   = reader.ReadInt32(),
                            DecompressedSize = reader.ReadInt32(),
                            EntryHash        = reader.ReadInt64(),
                            BlockHash        = reader.ReadInt32(),
                            IsCompressed     = reader.ReadInt16() == 1,
                        };

                        uopEntries.Add(uopEntry);
                    }

                    nextBlockAddress = block.NextBlockAddress;
                }

                foreach (var uopEntry in uopEntries)
                {
                    FileIndexEntry entry = new FileIndexEntry()
                    {
                        Lookup = (int)uopEntry.Lookup,
                        Length = uopEntry.DecompressedSize
                    };

                    entries.Add(entry);
                }
            }

            return(entries.ToArray());
        }