/// <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); } } }
/// <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); } }
/// <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); }