Пример #1
0
        private static Index ReadIndex(this BinaryReader br, IHashService _hashService)
        {
            var index = new Index
            {
                FileTableOffset         = br.ReadUInt32(),
                FileTableSize           = br.ReadUInt32(),
                Crc                     = br.ReadUInt64(),
                FileEntryCount          = br.ReadUInt32(),
                FileSegmentCount        = br.ReadUInt32(),
                ResourceDependencyCount = br.ReadUInt32()
            };

            // read tables
            for (var i = 0; i < index.FileEntryCount; i++)
            {
                var entry = ReadFileEntry(br, _hashService);

                if (!index.FileEntries.ContainsKey(entry.NameHash64))
                {
                    index.FileEntries.Add(entry.NameHash64, entry);
                }
                else
                {
                    // TODO
                }
            }

            for (var i = 0; i < index.FileSegmentCount; i++)
            {
                index.FileSegments.Add(ReadFileSegment(br));
            }

            for (var i = 0; i < index.ResourceDependencyCount; i++)
            {
                index.Dependencies.Add(ReadDependency(br, _hashService));
            }

            foreach (var(_, value) in index.FileEntries)
            {
                var startIndex = (int)value.SegmentsStart;
                var nextIndex  = (int)value.SegmentsEnd;

                value.Size  = index.FileSegments[startIndex].Size;
                value.ZSize = index.FileSegments[startIndex].ZSize;

                for (var j = startIndex + 1; j < nextIndex; j++)
                {
                    value.Size  += index.FileSegments[j].Size;
                    value.ZSize += index.FileSegments[j].ZSize;
                }
            }

            return(index);
        }
Пример #2
0
        /// <summary>
        /// Reads the tables info to the archive.
        /// </summary>
        private void ReadTables()
        {
            //using var mmf = MemoryMappedFile.CreateFromFile(Filepath, FileMode.Open, Mmfhash, 0, MemoryMappedFileAccess.Read);

            // using (var vs = mmf.CreateViewStream(0, ArHeader.SIZE, MemoryMappedFileAccess.Read))
            // {
            //     _header = new ArHeader(new BinaryReader(vs));
            // }

            // using (var vs = mmf.CreateViewStream((long)_header.Tableoffset, (long)_header.Tablesize,
            //     MemoryMappedFileAccess.Read))
            // {
            //     _table = new Index(new BinaryReader(vs), this);
            // }

            using var vs = new FileStream(ArchiveAbsolutePath, FileMode.Open, FileAccess.Read);
            Header       = new Header(new BinaryReader(vs));
            vs.Seek((long)Header.IndexPosition, SeekOrigin.Begin);
            Index = new Index(new BinaryReader(vs), this);
            vs.Close();
        }
Пример #3
0
        public static void WriteIndex(this BinaryWriter bw, Index index)
        {
            // write the table to a stream to calculate the size
            using var ms          = new MemoryStream();
            using var tablewriter = new BinaryWriter(ms);

            index.FileEntryCount          = (uint)index.FileEntries.Count;
            index.FileSegmentCount        = (uint)index.FileSegments.Count;
            index.ResourceDependencyCount = (uint)index.Dependencies.Count;
            //tablewriter.Write(Crc);
            tablewriter.Write(index.FileEntryCount);
            tablewriter.Write(index.FileSegmentCount);
            tablewriter.Write(index.ResourceDependencyCount);

            foreach (var archiveItem in index.FileEntries)
            {
                tablewriter.WriteFileEntry(archiveItem.Value);
            }

            foreach (var offsetEntry in index.FileSegments)
            {
                tablewriter.WriteFileSegment(offsetEntry);
            }

            foreach (var dependency in index.Dependencies)
            {
                tablewriter.WriteDependency(dependency);
            }

            index.FileTableOffset = 8; //TODO
            bw.Write(index.FileTableOffset);
            bw.Write((uint)ms.Length + 8);
            //crc64 calculate
            bw.Write(Crc64.Compute(tablewriter.BaseStream.ToByteArray()));
            bw.Write(tablewriter.BaseStream.ToByteArray());
        }
Пример #4
0
 public Archive()
 {
     Header = new Header();
     Index  = new CP77Tools.Model.Index();
     Files  = new Dictionary <ulong, IGameFile>();
 }
Пример #5
0
 public Archive()
 {
     Header = new Header();
     Index  = new Index();
 }
Пример #6
0
 public Archive()
 {
     Header = new Header();
     Index  = new Index();
     Files  = new Dictionary <ulong, IGameFile>();
 }