/// <summary> /// Initializes a new instance of the <see cref="PackEntry"/> class. /// </summary> /// <param name="info">The information.</param> /// <param name="name">The name.</param> /// <param name="maxNameLength">Maximum length of the name.</param> /// <exception cref="System.ArgumentOutOfRangeException">maxNameLength</exception> internal PackEntry(PackageItemInfo info, string name, int maxNameLength) : this(name, info.Seed, info.IsCompressed, info.CompressedSize, info.DecompressedSize, info.Offset, DateTime.FromFileTime(info.CreationTime), DateTime.FromFileTime(info.ModifiedTime2), DateTime.FromFileTime(info.LastAccessTime)) { if (name.Length > maxNameLength) throw new ArgumentOutOfRangeException("maxNameLength"); MaxNameLength = maxNameLength; }
/// <summary> /// Outputs the pack file to the given stream. /// </summary> /// <param name="dst">The DST.</param> public void SaveTo(Stream dst) { var head = new FileHeader { Signature = PackCommon.Header, Revision = Revision, EntryCount = _entries.Count, Path = Root, Ft1 = DateTime.UtcNow.ToFileTimeUtc(), Ft2 = DateTime.UtcNow.ToFileTimeUtc() }; var pkgHead = new PackageHeader { EntryCount = _entries.Count, InfoHeaderSize = 0, DataSectionSize = (uint)_bodyStream.Position, BlankSize = 0, Zero = new byte[16] }; var infos = new List<Tuple<byte[], PackageItemInfo>>(); foreach (var e in _entries) { var info = new PackageItemInfo() { CompressedSize = e.SizeInPack, DecompressedSize = e.DecompressedSize, IsCompressed = e.IsCompressed, Offset = (uint)e.DataOffset, Seed = e.CryptoSeed, CreationTime = e.CreatedDate.ToFileTime(), CreationTime2 = e.CreatedDate.ToFileTime(), ModifiedTime = e.ModifiedDate.ToFileTime(), ModifiedTime2 = e.ModifiedDate.ToFileTime(), LastAccessTime = e.AccessDate.ToFileTime() }; var bytes = PackCommon.EncodeName(e.Name); infos.Add(Tuple.Create(bytes, info)); pkgHead.InfoHeaderSize += bytes.Length + StructUtil.SizeOf<PackageItemInfo>(); } head.WriteToStream(dst); pkgHead.WriteToStream(dst); foreach (var i in infos) { dst.Write(i.Item1, 0, i.Item1.Length); i.Item2.WriteToStream(dst); } _bodyStream.Position = 0; _bodyStream.CopyTo(dst); }