diff --git a/src/ICSharpCode.SharpZipLib/Zip/FastZip.cs b/src/ICSharpCode.SharpZipLib/Zip/FastZip.cs
index 99443a06a..5ba5a6237 100644
--- a/src/ICSharpCode.SharpZipLib/Zip/FastZip.cs
+++ b/src/ICSharpCode.SharpZipLib/Zip/FastZip.cs
@@ -3,6 +3,7 @@
using System;
using System.IO;
using static ICSharpCode.SharpZipLib.Zip.Compression.Deflater;
+using static ICSharpCode.SharpZipLib.Zip.ZipEntryFactory;
namespace ICSharpCode.SharpZipLib.Zip
{
@@ -188,6 +189,29 @@ public enum Overwrite
#region Constructors
+ ///
+ /// Initialise a new instance of using the specified
+ ///
+ /// The time setting to use when creating or extracting Zip entries.
+ /// Using TimeSetting.LastAccessTime[Utc] when
+ /// creating an archive will set the file time to the moment of reading.
+ ///
+ public FastZip(TimeSetting timeSetting)
+ {
+ entryFactory_ = new ZipEntryFactory(timeSetting);
+ restoreDateTimeOnExtract_ = true;
+ }
+
+ ///
+ /// Initialise a new instance of using the specified
+ ///
+ /// The time to set all values for created or extracted Zip Entries.
+ public FastZip(DateTime time)
+ {
+ entryFactory_ = new ZipEntryFactory(time);
+ restoreDateTimeOnExtract_ = true;
+ }
+
///
/// Initialise a default instance of .
///
@@ -733,7 +757,39 @@ private void ExtractFileEntry(ZipEntry entry, string targetName)
if (restoreDateTimeOnExtract_)
{
- File.SetLastWriteTime(targetName, entry.DateTime);
+ switch (entryFactory_.Setting)
+ {
+ case TimeSetting.CreateTime:
+ File.SetCreationTime(targetName, entry.DateTime);
+ break;
+
+ case TimeSetting.CreateTimeUtc:
+ File.SetCreationTimeUtc(targetName, entry.DateTime);
+ break;
+
+ case TimeSetting.LastAccessTime:
+ File.SetLastAccessTime(targetName, entry.DateTime);
+ break;
+
+ case TimeSetting.LastAccessTimeUtc:
+ File.SetLastAccessTimeUtc(targetName, entry.DateTime);
+ break;
+
+ case TimeSetting.LastWriteTime:
+ File.SetLastWriteTime(targetName, entry.DateTime);
+ break;
+
+ case TimeSetting.LastWriteTimeUtc:
+ File.SetLastWriteTimeUtc(targetName, entry.DateTime);
+ break;
+
+ case TimeSetting.Fixed:
+ File.SetLastWriteTime(targetName, entryFactory_.FixedDateTime);
+ break;
+
+ default:
+ throw new ZipException("Unhandled time setting in ExtractFileEntry");
+ }
}
if (RestoreAttributesOnExtract && entry.IsDOSEntry && (entry.ExternalFileAttributes != -1))
@@ -807,7 +863,39 @@ private void ExtractEntry(ZipEntry entry)
Directory.CreateDirectory(dirName);
if (entry.IsDirectory && restoreDateTimeOnExtract_)
{
- Directory.SetLastWriteTime(dirName, entry.DateTime);
+ switch (entryFactory_.Setting)
+ {
+ case TimeSetting.CreateTime:
+ Directory.SetCreationTime(dirName, entry.DateTime);
+ break;
+
+ case TimeSetting.CreateTimeUtc:
+ Directory.SetCreationTimeUtc(dirName, entry.DateTime);
+ break;
+
+ case TimeSetting.LastAccessTime:
+ Directory.SetLastAccessTime(dirName, entry.DateTime);
+ break;
+
+ case TimeSetting.LastAccessTimeUtc:
+ Directory.SetLastAccessTimeUtc(dirName, entry.DateTime);
+ break;
+
+ case TimeSetting.LastWriteTime:
+ Directory.SetLastWriteTime(dirName, entry.DateTime);
+ break;
+
+ case TimeSetting.LastWriteTimeUtc:
+ Directory.SetLastWriteTimeUtc(dirName, entry.DateTime);
+ break;
+
+ case TimeSetting.Fixed:
+ Directory.SetLastWriteTime(dirName, entryFactory_.FixedDateTime);
+ break;
+
+ default:
+ throw new ZipException("Unhandled time setting in ExtractEntry");
+ }
}
}
else
diff --git a/src/ICSharpCode.SharpZipLib/Zip/IEntryFactory.cs b/src/ICSharpCode.SharpZipLib/Zip/IEntryFactory.cs
index bbe40c4d7..35642a7cf 100644
--- a/src/ICSharpCode.SharpZipLib/Zip/IEntryFactory.cs
+++ b/src/ICSharpCode.SharpZipLib/Zip/IEntryFactory.cs
@@ -1,5 +1,9 @@
+using System;
+
using ICSharpCode.SharpZipLib.Core;
+using static ICSharpCode.SharpZipLib.Zip.ZipEntryFactory;
+
namespace ICSharpCode.SharpZipLib.Zip
{
///
@@ -50,5 +54,16 @@ public interface IEntryFactory
/// Get/set the applicable.
///
INameTransform NameTransform { get; set; }
+
+ ///
+ /// Get the in use.
+ ///
+ TimeSetting Setting { get; }
+
+ ///
+ /// Get the value to use when is set to ,
+ /// or if not specified, the value of when the class was the initialized
+ ///
+ DateTime FixedDateTime { get; }
}
}
diff --git a/src/ICSharpCode.SharpZipLib/Zip/ZipEntryFactory.cs b/src/ICSharpCode.SharpZipLib/Zip/ZipEntryFactory.cs
index caabc7a80..9ebfcf924 100644
--- a/src/ICSharpCode.SharpZipLib/Zip/ZipEntryFactory.cs
+++ b/src/ICSharpCode.SharpZipLib/Zip/ZipEntryFactory.cs
@@ -322,7 +322,7 @@ public ZipEntry MakeDirectoryEntry(string directoryName, bool useFileSystem)
private INameTransform nameTransform_;
private DateTime fixedDateTime_ = DateTime.Now;
- private TimeSetting timeSetting_;
+ private TimeSetting timeSetting_ = TimeSetting.LastWriteTime;
private bool isUnicodeText_;
private int getAttributes_ = -1;