Exemplo n.º 1
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)
        {
            Seed = 166;

            header       = packHeader;
            br           = binaryReader;
            PackFilePath = packFilePath;
        }
Exemplo n.º 2
0
 public PackWriter(string outFile, int version)
 {
     _outFile    = outFile;
     _packHeader = new PackHeader();
     _packList   = new List <PackListEntry>();
     _tempOutput = new TempFileScope();
     _version    = version;
     _bodyStream = File.Open(_tempOutput.Filename, FileMode.Create);
 }
Exemplo n.º 3
0
        /// <summary>
        ///     Loads entries from the given pack file.
        /// </summary>
        /// <param name="filePath"></param>
        public 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 = br.ReadInt64();
            header.FileTime2 = br.ReadInt64();
            header.Zero      = new byte[16];

            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 (var 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        = br.ReadInt64();
                entry.FileTime2        = br.ReadInt64();
                entry.FileTime3        = br.ReadInt64();
                entry.FileTime4        = br.ReadInt64();
                entry.FileTime5        = 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);
                }
            }
        }