Esempio n. 1
0
 private IEnumerable <ArchiveBlockDescriptor> GetDescriptors(BlockTable blockTable)
 {
     foreach (var entry in blockTable)
     {
         if (entry.BlockSize == 0)
         {
             continue;
         }
         using (var mappedStream = File.CreateViewStream(entry.DirectoryOffset, entry.BlockSize, MemoryMappedFileAccess.Read))
             using (var binaryReader = new BinaryReader(mappedStream))
             {
                 var magic           = binaryReader.ReadUInt32();
                 var blockDescriptor = ArchiveBlockDescriptor.Create(magic, binaryReader);
                 if (blockDescriptor != null)
                 {
                     yield return(blockDescriptor);
                 }
             }
     }
 }
Esempio n. 2
0
        public WildstarFile(MemoryMappedFile file, string name)
        {
            File = file;
            Name = name;
            using (var mappedStream = file.CreateViewStream(0, FileHeader.Size, MemoryMappedFileAccess.Read))
                using (var binaryReader = new BinaryReader(mappedStream))
                {
                    FileHeader = FileHeader.Load(binaryReader);

                    if (FileHeader.Magic != Signatures.Pack)
                    {
                        throw new InvalidDataException(
                                  "The file signature does not match the expected signature, the file is not valid.");
                    }
                    if (FileHeader.Version != 1)
                    {
                        throw new InvalidOperationException(
                                  $"This library only supports version 0x{1:X8}, but the file appears to be version 0x{FileHeader.Version:X8}");
                    }
                }
            BlockTable = BlockTable.Load(this);
            _lazyArchiveBlockDescriptors = new Lazy <IReadOnlyList <ArchiveBlockDescriptor> >(() => GetDescriptors(BlockTable).ToList().AsReadOnly());
            _lazyAssetTable = new Lazy <ResourceContainerTable>(() => AssetArchiveResourceContainerDescriptor == null ? null : new ResourceContainerTable(AssetArchiveResourceContainerDescriptor, this));
        }