private bool TryAddChildArchive(string path, ArchiveFileEntry entry, ArchiveArchiveEntry parentArchive) { Action <ArchiveArchiveEntry, ArchiveFileEntry> valueSetter; switch (Path.GetExtension(entry.Name)) { case ".fs": valueSetter = (a, e) => a.ContentEntry = e; break; case ".fl": valueSetter = (a, e) => a.ListingEntry = e; break; case ".fi": valueSetter = (a, e) => a.MetricsEntry = e; break; default: return(false); } path = Path.ChangeExtension(path, null); ArchiveArchiveEntry archive = _childArchives.GetOrAdd(path, p => new ArchiveArchiveEntry(Path.ChangeExtension(entry.Name, null))); valueSetter(archive, entry); if (archive.IsComplete) { _childArchives.TryRemove(path, out archive); parentArchive.AddEntry(archive); } return(true); }
private ArchiveArchiveEntry[] MoveArchive(ArchiveArchiveEntry[] oldArchives, ArchiveArchiveEntry newParent) { List <ArchiveArchiveEntry> result = new List <ArchiveArchiveEntry>(oldArchives.Length); foreach (ArchiveArchiveEntry oldArchive in oldArchives) { ArchiveArchiveEntry newArchive = new ArchiveArchiveEntry(oldArchive.Name); newParent.AddEntry(newArchive); result.Add(newArchive); } return(result.ToArray()); }
private void MoveFile(ArchiveFileEntry oldFile, ArchiveArchiveEntry newParent, ArchiveDirectoryEntry newDirectory) { ArchiveFileEntry newFile = oldFile.Clone(); { newFile.Compression = Compression.None; newFile.ContentOffset = newParent.CurrentPosition; SetCapacity(newFile); newParent.CurrentPosition += newFile.ContentCapacity; } newParent.AddEntry(newFile); newDirectory.AddEntry(oldFile.GetFullPath(), newFile); }
private void ReadInformation(ArchiveArchiveEntry parentArchive, Stream metricsStream, Stream listingStream) { _childArchives.Clear(); using (BinaryReader mbr = new BinaryReader(metricsStream)) using (StreamReader lsr = new StreamReader(listingStream, Encoding.GetEncoding(1251))) { int index = 0; while (!lsr.EndOfStream) { string path = lsr.ReadLine(); if (string.IsNullOrEmpty(path)) { break; } int uncompressedContentSize = mbr.ReadInt32(); int contentOffset = mbr.ReadInt32(); int compression = mbr.ReadInt32(); ArchiveFileEntry entry = new ArchiveFileEntry(Path.GetFileName(path)) { Index = index++, UncompressedContentSize = uncompressedContentSize, ContentOffset = contentOffset, Compression = (Compression)compression }; if (TryAddChildArchive(path, entry, parentArchive)) { continue; } parentArchive.AddEntry(entry); _info.RootDirectory.AddEntry(path, entry); } } }