Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SplitArchive" /> class.
        /// </summary>
        /// <param name="path">Archive name.</param>
        /// <param name="nested">Nested single archive.</param>
        /// <param name="physicalSize">Size of the archive part as reported by file system.</param>
        /// <param name="totalPhysicalSize">Total size of all parts as reported by file system.</param>
        /// <param name="lastModified">The last modified date for this archive latest modified file.</param>
        public SplitArchive(string path, SingleArchive nested, long physicalSize = 0,
            long totalPhysicalSize = 0, DateTime? lastModified = null)
            : base(path, ArchiveType.Split, physicalSize, lastModified)
        {
            Contract.Requires(nested != null);
            Contract.Requires(physicalSize >= 0);
            Contract.Requires(totalPhysicalSize >= 0);

            Nested = nested;
            _totalPhysicalSize = totalPhysicalSize;
        }
Beispiel #2
0
        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 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 virtual bool InitFromSplitAndSingle(SplitArchive left, SingleArchive right)
 {
     return InitFromSingles(left.Nested, right);
 }
 /// <summary> Initializes comparison from two single archives. </summary>
 /// <param name="left">Left archive.</param>
 /// <param name="right">Right archive.</param>
 /// <returns>true if comparison of two single archives by this trait can be performed;
 ///  false otherwise.</returns>
 protected virtual bool InitFromSingles(SingleArchive left, SingleArchive right)
 {
     return InitFromArchives(left, right);
 }
 /// <summary> Initializes comparison from single and split archives. </summary>
 /// <param name="left">Left archive.</param>
 /// <param name="right">Right archive.</param>
 /// <returns>true if comparison of single and split archives by this trait can be performed;
 ///  false otherwise.</returns>
 protected virtual bool InitFromSingleAndSplit(SingleArchive left, SplitArchive right)
 {
     return InitFromSingles(left, right.Nested);
 }
 /// <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;
 }
 /// <summary> Initializes comparison from two single archives. </summary>
 /// <param name="left">Left archive.</param>
 /// <param name="right">Right archive.</param>
 /// <returns>true if comparison of two single archives by this trait can be performed;
 ///  false otherwise.</returns>
 protected override bool InitFromSingles(SingleArchive left, SingleArchive right)
 {
     LeftSize = left.Size;
     RightSize = right.Size;
     return true;
 }
 /// <summary> Initializes comparison from two single archives. </summary>
 /// <param name="left">Left archive.</param>
 /// <param name="right">Right archive.</param>
 /// <returns>true if comparison of two single archives by this trait can be performed;
 ///  false otherwise.</returns>
 protected override bool InitFromSingles(SingleArchive left, SingleArchive right)
 {
     LeftFolderCount = left.FolderCount;
     RightFolderCount = right.FolderCount;
     return true;
 }