Esempio n. 1
0
        /// <summary>
        /// Creates new list entry.
        /// </summary>
        /// <param name="packFilePath"></param>
        /// <param name="packHeader"></param>
        /// <param name="binaryReader"></param>
        internal PackedFileEntry(PackHeader packHeader, BinaryReader binaryReader)
        {
            _br = binaryReader;

            this.Seed   = 1;
            this.Header = packHeader;
        }
Esempio n. 2
0
        /// <summary>
        /// Reads header from reader and returns it.
        /// </summary>
        /// <param name="br"></param>
        /// <param name="packFilePath"></param>
        /// <returns></returns>
        public static PackHeader ReadFrom(BinaryReader br, string packFilePath)
        {
            int len;

            byte[] strBuffer;

            var header = new PackHeader();

            header.PackFilePath = packFilePath;

            header.Signature     = br.ReadBytes(4);
            header.FormatVersion = br.ReadInt32();
            header.PackVersion   = br.ReadInt32();
            header.FileCount     = br.ReadInt32();
            header.FileTime1     = DateTime.FromFileTimeUtc(br.ReadInt64());
            header.FileTime2     = DateTime.FromFileTimeUtc(br.ReadInt64());

            strBuffer       = br.ReadBytes(480);
            len             = Array.IndexOf(strBuffer, (byte)0);
            header.BasePath = Encoding.UTF8.GetString(strBuffer, 0, len);

            header.ListFileCount = br.ReadInt32();
            header.ListLength    = br.ReadInt32();
            header.BlankLength   = br.ReadInt32();
            header.DataLength    = br.ReadInt32();
            header.Zero          = br.ReadBytes(16);

            return(header);
        }
Esempio n. 3
0
        /// <summary>
        /// Loads entries from the given pack file.
        /// </summary>
        /// <param name="filePath"></param>
        private void Load(string filePath)
        {
            var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            var br = new BinaryReader(fs, Encoding.ASCII);

            lock (_syncLock)
            {
                _fileStreams.Add(fs);
                _binaryReaders.Add(br);
            }

            var header = PackHeader.ReadFrom(br, filePath);

            for (var i = 0; i < header.ListFileCount; ++i)
            {
                var entry    = PackedFileEntry.ReadFrom(header, br);
                var fullPath = entry.FullName.ToLower();

                lock (_syncLock)
                {
                    _entries[fullPath] = entry;

                    var key = entry.FileName.ToLower();

                    if (!_entriesNamed.ContainsKey(key))
                    {
                        _entriesNamed[key] = new List <PackedFileEntry>();
                    }
                    _entriesNamed[key].Add(entry);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Creates new list entry.
        /// </summary>
        /// <param name="packFilePath"></param>
        /// <param name="packHeader"></param>
        /// <param name="binaryReader"></param>
        internal PackListEntry(string packFilePath, PackHeader packHeader, BinaryReader binaryReader)
        {
            this.Seed = 166;

            header            = packHeader;
            br                = binaryReader;
            this.PackFilePath = packFilePath;
        }
Esempio n. 5
0
        /// <summary>
        /// Loads entries from the given pack file.
        /// </summary>
        /// <param name="filePath"></param>
        private void Load(string filePath)
        {
            _fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            _br = new BinaryReader(_fs, Encoding.ASCII);

            this.Header = PackHeader.ReadFrom(_br, filePath);

            for (var i = 0; i < this.Header.FileCount2; ++i)
            {
                var entry = PackedFileEntry.ReadFrom(this.Header, _br);
                this.AddEntry(entry);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Reads pack list entry from reader and returns it.
        /// </summary>
        /// <param name="packFilePath"></param>
        /// <param name="packHeader"></param>
        /// <param name="br"></param>
        /// <returns></returns>
        public static PackedFileEntry ReadFrom(PackHeader packHeader, BinaryReader br)
        {
            int len;

            byte[] strBuffer;

            var entry = new PackedFileEntry(packHeader, br);

            entry.NameType = (PackListNameType)br.ReadByte();

            if (entry.NameType <= PackListNameType.L64)
            {
                var size = (0x10 * ((byte)entry.NameType + 1));
                strBuffer = br.ReadBytes(size - 1);
            }
            else if (entry.NameType == PackListNameType.L96)
            {
                var size = 0x60;
                strBuffer = br.ReadBytes(size - 1);
            }
            else if (entry.NameType == PackListNameType.LDyn)
            {
                var size = (int)br.ReadUInt32();
                strBuffer = br.ReadBytes(size);
            }
            else
            {
                throw new Exception("Unknown entry name type '" + entry.NameType + "'.");
            }

            len = Array.IndexOf(strBuffer, (byte)0);
            entry.RelativePath = Encoding.UTF8.GetString(strBuffer, 0, len);

            entry.Seed           = br.ReadUInt32();
            entry.Zero           = br.ReadUInt32();
            entry.DataOffset     = br.ReadUInt32();
            entry.CompressedSize = br.ReadUInt32();
            entry.FileSize       = br.ReadUInt32();
            entry.IsCompressed   = (br.ReadUInt32() != 0);           // compression strength?
            entry.FileTime1      = DateTime.FromFileTimeUtc(br.ReadInt64());
            entry.FileTime2      = DateTime.FromFileTimeUtc(br.ReadInt64());
            entry.FileTime3      = DateTime.FromFileTimeUtc(br.ReadInt64());
            entry.FileTime4      = DateTime.FromFileTimeUtc(br.ReadInt64());
            entry.FileTime5      = DateTime.FromFileTimeUtc(br.ReadInt64());

            entry.FileName = Path.GetFileName(entry.RelativePath);

            return(entry);
        }
Esempio n. 7
0
        /// <summary>
        /// Loads entries from the given pack file.
        /// </summary>
        /// <param name="filePath"></param>
        private void Load(string filePath)
        {
            int len;

            byte[] strBuffer;

            var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            var br = new BinaryReader(fs, Encoding.ASCII);

            fileStreams.Add(fs);
            binaryReaders.Add(br);

            var header = new PackHeader();

            header.Signature = br.ReadBytes(8);
            header.D1        = br.ReadUInt32();
            header.Sum       = br.ReadUInt32();
            header.FileTime1 = DateTime.FromFileTimeUtc(br.ReadInt64());
            header.FileTime2 = DateTime.FromFileTimeUtc(br.ReadInt64());

            strBuffer       = br.ReadBytes(480);
            len             = Array.IndexOf(strBuffer, (byte)0);
            header.DataPath = Encoding.UTF8.GetString(strBuffer, 0, len);

            header.FileCount    = br.ReadUInt32();
            header.HeaderLength = br.ReadUInt32();
            header.BlankLength  = br.ReadUInt32();
            header.DataLength   = br.ReadUInt32();
            header.Zero         = br.ReadBytes(16);

            for (int i = 0; i < header.FileCount; ++i)
            {
                var entry = new PackListEntry(filePath, header, br);

                entry.NameType = (PackListNameType)br.ReadByte();

                if (entry.NameType <= PackListNameType.L64)
                {
                    var size = (0x10 * ((byte)entry.NameType + 1));
                    strBuffer = br.ReadBytes(size - 1);
                }
                else if (entry.NameType == PackListNameType.L96)
                {
                    var size = 0x60;
                    strBuffer = br.ReadBytes(size - 1);
                }
                else if (entry.NameType == PackListNameType.LDyn)
                {
                    var size = (int)br.ReadUInt32() + 5;
                    strBuffer = br.ReadBytes(size - 1 - 4);
                }
                else
                {
                    throw new Exception("Unknown entry name type '" + entry.NameType + "'.");
                }

                len            = Array.IndexOf(strBuffer, (byte)0);
                entry.FullName = Encoding.UTF8.GetString(strBuffer, 0, len);
                entry.FileName = Path.GetFileName(entry.FullName);

                entry.Seed             = br.ReadUInt32();
                entry.Zero             = br.ReadUInt32();
                entry.DataOffset       = br.ReadUInt32();
                entry.CompressedSize   = br.ReadUInt32();
                entry.DecompressedSize = br.ReadUInt32();
                entry.IsCompressed     = br.ReadUInt32() == 1;
                entry.FileTime1        = DateTime.FromFileTimeUtc(br.ReadInt64());
                entry.FileTime2        = DateTime.FromFileTimeUtc(br.ReadInt64());
                entry.FileTime3        = DateTime.FromFileTimeUtc(br.ReadInt64());
                entry.FileTime4        = DateTime.FromFileTimeUtc(br.ReadInt64());
                entry.FileTime5        = DateTime.FromFileTimeUtc(br.ReadInt64());

                lock (entries)
                    entries[entry.FullName.ToLower()] = entry;

                lock (entriesNamed)
                {
                    var key = entry.FileName.ToLower();

                    if (!entriesNamed.ContainsKey(key))
                    {
                        entriesNamed[key] = new List <PackListEntry>();
                    }
                    entriesNamed[key].Add(entry);
                }
            }
        }