diff --git a/SharpCompress/Archive/IArchiveEntry.Extensions.cs b/SharpCompress/Archive/IArchiveEntry.Extensions.cs index 91f82f68..239a372c 100644 --- a/SharpCompress/Archive/IArchiveEntry.Extensions.cs +++ b/SharpCompress/Archive/IArchiveEntry.Extensions.cs @@ -27,7 +27,7 @@ namespace SharpCompress.Archive { return; } - using(entryStream) + using (entryStream) using (Stream s = new ListeningStream(streamListener, entryStream)) { s.TransferTo(streamToWriteTo); @@ -60,7 +60,10 @@ namespace SharpCompress.Archive { destinationFileName = Path.Combine(destinationDirectory, file); } - entry.WriteToFile(destinationFileName, options); + if (!entry.IsDirectory) + { + entry.WriteToFile(destinationFileName, options); + } } /// @@ -69,10 +72,6 @@ namespace SharpCompress.Archive public static void WriteToFile(this IArchiveEntry entry, string destinationFileName, ExtractOptions options = ExtractOptions.Overwrite) { - if (entry.IsDirectory) - { - return; - } FileMode fm = FileMode.Create; if (!options.HasFlag(ExtractOptions.Overwrite)) @@ -84,39 +83,7 @@ namespace SharpCompress.Archive entry.WriteTo(fs); } - if (options.HasFlag(ExtractOptions.PreserveFileTime) || options.HasFlag(ExtractOptions.PreserveAttributes)) - { - // update file time to original packed time - FileInfo nf = new FileInfo(destinationFileName); - if (nf.Exists) - { - if (options.HasFlag(ExtractOptions.PreserveFileTime)) - { - if (entry.CreatedTime.HasValue) - { - nf.CreationTime = entry.CreatedTime.Value; - } - - if (entry.LastModifiedTime.HasValue) - { - nf.LastWriteTime = entry.LastModifiedTime.Value; - } - - if (entry.LastAccessedTime.HasValue) - { - nf.LastAccessTime = entry.CreatedTime.Value; - } - } - - if (options.HasFlag(ExtractOptions.PreserveAttributes)) - { - if (entry.Attrib.HasValue) - { - nf.Attributes = (FileAttributes)System.Enum.ToObject(typeof(FileAttributes), entry.Attrib.Value); - } - } - } - } + entry.PreserveExtractionOptions(destinationFileName, options); } #endif } diff --git a/SharpCompress/Common/IEntry.Extensions.cs b/SharpCompress/Common/IEntry.Extensions.cs new file mode 100644 index 00000000..8385c7db --- /dev/null +++ b/SharpCompress/Common/IEntry.Extensions.cs @@ -0,0 +1,48 @@ +using System; +using System.IO; + +namespace SharpCompress.Common +{ + internal static class IEntryExtensions + { + internal static void PreserveExtractionOptions(this IEntry entry, string destinationFileName, + ExtractOptions options) + { + if (options.HasFlag(ExtractOptions.PreserveFileTime) || options.HasFlag(ExtractOptions.PreserveAttributes)) + { + FileInfo nf = new FileInfo(destinationFileName); + if (!nf.Exists) + { + return; + } + + // update file time to original packed time + if (options.HasFlag(ExtractOptions.PreserveFileTime)) + { + if (entry.CreatedTime.HasValue) + { + nf.CreationTime = entry.CreatedTime.Value; + } + + if (entry.LastModifiedTime.HasValue) + { + nf.LastWriteTime = entry.LastModifiedTime.Value; + } + + if (entry.LastAccessedTime.HasValue) + { + nf.LastAccessTime = entry.LastAccessedTime.Value; + } + } + + if (options.HasFlag(ExtractOptions.PreserveAttributes)) + { + if (entry.Attrib.HasValue) + { + nf.Attributes = (FileAttributes)System.Enum.ToObject(typeof(FileAttributes), entry.Attrib.Value); + } + } + } + } + } +} diff --git a/SharpCompress/Reader/IReader.Extensions.cs b/SharpCompress/Reader/IReader.Extensions.cs index 7eabd7fc..00b5374b 100644 --- a/SharpCompress/Reader/IReader.Extensions.cs +++ b/SharpCompress/Reader/IReader.Extensions.cs @@ -89,6 +89,7 @@ namespace SharpCompress.Reader // s.TransferTo(fs); //} } + reader.Entry.PreserveExtractionOptions(destinationFileName, options); } #endif } diff --git a/SharpCompress/SharpCompress.PortableTest.csproj b/SharpCompress/SharpCompress.PortableTest.csproj index d978c5de..76f4792b 100644 --- a/SharpCompress/SharpCompress.PortableTest.csproj +++ b/SharpCompress/SharpCompress.PortableTest.csproj @@ -129,6 +129,7 @@ + diff --git a/SharpCompress/SharpCompress.Unsigned.csproj b/SharpCompress/SharpCompress.Unsigned.csproj index 0bfa9838..2114d855 100644 --- a/SharpCompress/SharpCompress.Unsigned.csproj +++ b/SharpCompress/SharpCompress.Unsigned.csproj @@ -131,6 +131,7 @@ + diff --git a/SharpCompress/SharpCompress.csproj b/SharpCompress/SharpCompress.csproj index b2c2ab6b..fd033f1a 100644 --- a/SharpCompress/SharpCompress.csproj +++ b/SharpCompress/SharpCompress.csproj @@ -131,6 +131,7 @@ +