public static Archive ParseArchive([CanBeNull] string singleArchiveListing) { if (string.IsNullOrWhiteSpace(singleArchiveListing)) { return null; } var sorted = ReadSingleArchiveListing(singleArchiveListing); if (sorted == null) { return null; } // Sorting failed, means listing does't contain an archive. // Create archive entries first. var entries = sorted.IsSimpleFormat ? sorted.SimpleEntries.Select(ParseEntry).Where(entry => entry != null).ToArray() : sorted.ComplexEntries.Select(ParseEntry).Where(entry => entry != null).ToArray(); // 'D' attribute does not exist sometimes, like in PE archives, so try to detect folder entries. // For every entry a simple lookup is made to see if some other entry uses it as a directory. var detectedDirectories = SevenZipTools.InferDirectoriesFromPaths(entries.Select(entry => entry.Path)); // Now check created entries agains detected folders, // and fix those created file entries that should be folder entries. for (int index = 0; index < entries.Length; index++) { var entry = entries[index]; if (detectedDirectories.Contains(entry.Path) && !(entry is FolderEntry)) { entries[index] = new FolderEntry(entry.Path, entry.LastModified, entry.Size, entry.PackedSize, entry.ParentFolder); } } // Now create archive containing these entries: Archive result; Debug.Assert(sorted.Properties != null); if (sorted.IsSplitArchive) { Debug.Assert(sorted.NestedProperties != null); var nestedArchive = new SingleArchive(sorted.NestedProperties.Name, sorted.NestedProperties.Type, entries, sorted.NestedProperties.PhysicalSize, sorted.NestedProperties.Size); result = new SplitArchive(sorted.Properties.Name, nestedArchive, sorted.Properties.PhysicalSize, sorted.Properties.TotalPhysicalSize); } else { result = new SingleArchive(sorted.Properties.Name, sorted.Properties.Type, entries, sorted.Properties.PhysicalSize, sorted.Properties.Size); } return result; }
/// <summary> Initializes comparison from two split archives. </summary> /// <param name="left">Left archive.</param> /// <param name="right">Right archive.</param> /// <returns>true if comparison of two split archives by this trait can be performed; /// false otherwise.</returns> protected virtual bool InitFromSplits(SplitArchive left, SplitArchive right) { return InitFromSingles(left.Nested, right.Nested); }
/// <summary> Initializes comparison from two split archives. </summary> /// <param name="left">Left archive.</param> /// <param name="right">Right archive.</param> /// <returns>true if comparison of two split archives by this trait can be performed; /// false otherwise.</returns> protected override bool InitFromSplits(SplitArchive left, SplitArchive right) { LeftTotalPhysicalSize = left.TotalPhysicalSize; RightTotalPhysicalSize = right.TotalPhysicalSize; return true; }
/// <summary> Initializes comparison from split and single archives. </summary> /// <param name="left">Left archive.</param> /// <param name="right">Right archive.</param> /// <returns>true if comparison of split and single archives by this trait can be performed; /// false otherwise.</returns> protected override bool InitFromSplitAndSingle(SplitArchive left, SingleArchive right) { LeftTotalPhysicalSize = left.TotalPhysicalSize; RightTotalPhysicalSize = 0; return true; }