/// <summary> Initializes a new instance of the <see cref="FileEntry" /> class. </summary> /// <param name="path">Full file name.</param> /// <param name="lastModified">The date when file was last modified.</param> /// <param name="size">Uncompressed size. 0 means uncompressed size is unavailable.</param> /// <param name="packedSize">Compressed size. 0 means that either compressed size is unavailable or /// no compression was done on the entry.</param> /// <param name="hash">File hash, value equal to <see cref="NoHash"/> means hash in unavailable.</param> /// <param name="parent">Parent directory. Null means entry is located at archive's root.</param> public FileEntry(string path, DateTime? lastModified = null, long size = 0, long packedSize = 0, long hash = NoHash, FolderEntry parent = null) : base(path, lastModified, size, packedSize, parent) { Contract.Requires(!string.IsNullOrWhiteSpace(path)); Contract.Requires(size >= 0); Contract.Requires(packedSize >= 0); Hash = hash; }
/// <summary> Initializes a new instance of the <see cref="FileEntry" /> class. </summary> /// <param name="path">Full directory name.</param> /// <param name="lastModified">The date when folder was last modified.</param> /// <param name="size">Uncompressed size. 0 means uncompressed size is unavailable.</param> /// <param name="packedSize">Compressed size. 0 means that either compressed size is unavailable or /// no compression was done on the entry.</param> /// <param name="parent">Parent directory. Null means entry is located at archive's root.</param> /// <param name="contents">Folder contents. Null means folder is empty.</param> public FolderEntry(string path, DateTime? lastModified = null, long size = 0, long packedSize = 0, FolderEntry parent = null, IEnumerable<Entry> contents = null) : base(path, lastModified, size, packedSize, parent) { Contract.Requires(!string.IsNullOrWhiteSpace(path)); Contract.Requires(size >= 0); Contract.Requires(packedSize >= 0); _contents = new HashSet<Entry>(contents ?? Enumerable.Empty<Entry>()); }
/// <summary> Initializes a new instance of the <see cref="Entry" /> class. </summary> /// <param name="path">Full file or folder name.</param> /// <param name="lastModified">The date when file was last modified.</param> /// <param name="size">Uncompressed size. 0 means uncompressed size is unavailable.</param> /// <param name="packedSize">Compressed size. 0 means that either compressed size is unavailable or /// no compression was done on the entry.</param> /// <param name="parent">Parent directory. Null means entry is located at archive's root.</param> protected Entry(string path, DateTime? lastModified = null, long size = 0, long packedSize = 0, FolderEntry parent = null) { Contract.Requires(!string.IsNullOrWhiteSpace(path)); Contract.Requires(size >= 0); Contract.Requires(packedSize >= 0); Path = NormalizePath(path); ParentFolder = parent; Size = size; PackedSize = packedSize; LastModified = lastModified; }
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 file and folder entries. </summary> /// <param name="left">Left file.</param> /// <param name="right">Right folder.</param> /// <returns>true if comparison of file and folder entries by this trait can be performed; /// false otherwise.</returns> protected virtual bool InitFromFileAndFolder(FileEntry left, FolderEntry right) { return InitFromEntries(left, right); }
/// <summary> Initializes comparison from two folders. </summary> /// <param name="left">Left folder.</param> /// <param name="right">Right folder.</param> /// <returns>true if comparison of two folders by this trait can be performed; false otherwise.</returns> protected virtual bool InitFromFolders(FolderEntry left, FolderEntry right) { return InitFromEntries(left, right); }
/// <summary> Initializes comparison from any two entries. </summary> /// <param name="left">Left entry.</param> /// <param name="right">Right entry.</param> /// <returns>true if comparison of two entries by this trait can be performed; false otherwise.</returns> protected override bool InitFromEntries(Entry left, Entry right) { LeftParent = left.ParentFolder; RightParent = right.ParentFolder; return true; }
/// <summary> Initializes comparison from two folders. </summary> /// <param name="left">Left folder.</param> /// <param name="right">Right folder.</param> /// <returns>true if comparison of two folders by this trait can be performed; false otherwise.</returns> protected override bool InitFromFolders(FolderEntry left, FolderEntry right) { LeftFolderCount = left.FolderCount; RightFolderCount = right.FolderCount; return true; }