diff --git a/.vscode/extensions.json b/.vscode/extensions.json
new file mode 100644
index 00000000..8e3e206f
--- /dev/null
+++ b/.vscode/extensions.json
@@ -0,0 +1,9 @@
+{
+ "recommendations": [
+ "ms-vscode.csharp",
+ "ms-vscode.cpptools",
+ "ms-vscode.mono-debug",
+ "wghats.vscode-nxunit-test-adapter",
+ "visualstudioexptteam.vscodeintellicode",
+ ]
+}
\ No newline at end of file
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 00000000..cafcefe3
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,22 @@
+{
+ // Use IntelliSense to learn about possible attributes.
+ // Hover to view descriptions of existing attributes.
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": "Launch",
+ "type": "mono",
+ "request": "launch",
+ "program": "~/.nuget/packages/nunit.consolerunner/3.10.0/tools/nunit3-console.exe ${workspaceRoot}LibZipSharp.UnitTest/bin/Debug/net471/LibZipSharp.UnitTest.dll",
+ "cwd": "${workspaceRoot}bin/TestDebug/"
+ },
+ {
+ "name": "Attach",
+ "type": "mono",
+ "request": "attach",
+ "address": "localhost",
+ "port": 55555
+ }
+ ]
+}
\ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 00000000..b89b4b1c
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,6 @@
+{
+ "nxunitExplorer.nunit": "/Users/dean/.nuget/packages/nunit.consolerunner/3.10.0/tools/nunit3-console.exe",
+ "nxunitExplorer.modules": [
+ "LibZipSharp.UnitTest/bin/Debug/net471/LibZipSharp.UnitTest.dll",
+ ]
+}
\ No newline at end of file
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
new file mode 100644
index 00000000..6a3fad2d
--- /dev/null
+++ b/.vscode/tasks.json
@@ -0,0 +1,67 @@
+{
+ // See https://go.microsoft.com/fwlink/?LinkId=733558
+ // for the documentation about the tasks.json format
+ "version": "2.0.0",
+ "tasks": [
+ {
+ "label": "Build LibZipSharp",
+ "type": "shell",
+ "command": "msbuild LibZipSharp.csproj /restore /t:Build",
+ "group": {
+ "kind": "build",
+ "isDefault": true
+ },
+ "problemMatcher": [
+ "$msCompile"
+ ]
+ },
+ {
+ "label": "Pack LibZipSharp Nuget",
+ "type": "shell",
+ "command": "msbuild LibZipSharp.csproj /t:Pack",
+ "group": {
+ "kind": "build",
+ "isDefault": true
+ },
+ "problemMatcher": [
+ "$msCompile"
+ ]
+ },
+ {
+ "label": "Clean LibZipSharp",
+ "type": "shell",
+ "command": "msbuild LibZipSharp.csproj /restore /t:Clean",
+ "group": {
+ "kind": "build",
+ "isDefault": true
+ },
+ "problemMatcher": [
+ "$msCompile"
+ ]
+ },
+ {
+ "label": "Build LibZipSharp Unit Tests",
+ "type": "shell",
+ "command": "msbuild LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj /restore /t:Build /p:ReferenceNuget=False",
+ "group": {
+ "kind": "build",
+ "isDefault": true
+ },
+ "problemMatcher": [
+ "$msCompile"
+ ]
+ },
+ {
+ "label": "Run LibZipSharp Unit Tests",
+ "type": "shell",
+ "command": "msbuild LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj /restore /t:RunNunitTests /p:ReferenceNuget=False",
+ "group": {
+ "kind": "test",
+ "isDefault": true
+ },
+ "problemMatcher": [
+ "$msCompile"
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj b/LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj
index eedc4de5..bc8d3ab2 100644
--- a/LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj
+++ b/LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj
@@ -1,26 +1,39 @@
- net45
+ net471
false
true
+ False
-
+
-
+
+
+
+
+ libzip.dylib
+ PreserveNewest
+
+
+ libzip.dll
+ PreserveNewest
+
+
+
mono
\ No newline at end of file
diff --git a/LibZipSharp.UnitTest/ZipTests.cs b/LibZipSharp.UnitTest/ZipTests.cs
index 0de04661..cfa63a03 100644
--- a/LibZipSharp.UnitTest/ZipTests.cs
+++ b/LibZipSharp.UnitTest/ZipTests.cs
@@ -2,6 +2,7 @@
using System;
using System.IO;
using System.Text;
+using System.Threading;
using Xamarin.Tools.Zip;
namespace Tests {
@@ -70,5 +71,49 @@ public void CanExtractZipFile ()
FileAssert.AreEqual (Path.Combine (root, "in", "archive", "foo", "foo1.txt"), "foo1.txt", $"foo1.txt should have been {TEXT}");
}
}
+
+ static DateTime WithoutMilliseconds (DateTime t) =>
+ new DateTime (t.Year, t.Month, t.Day, t.Hour, t.Minute, t.Second, t.Kind);
+
+ [Test]
+ [Repeat (100)]
+ [NonParallelizable]
+ public void CheckDates ()
+ {
+ string root = Path.Combine (Path.GetDirectoryName (typeof (ZipTests).Assembly.Location));
+ string file = Path.Combine (root, "foo.txt");
+ string zip = Path.Combine (root, "foo.zip");
+ if (File.Exists (zip))
+ File.Delete (zip);
+ if (File.Exists (file))
+ File.Delete (file);
+ File.WriteAllText (file, TEXT);
+ DateTime lastWrite = WithoutMilliseconds (File.GetLastWriteTimeUtc (file));
+ Thread.Sleep (TimeSpan.FromSeconds (2));
+ using (var archive = ZipArchive.Open (zip, FileMode.Create)) {
+ var entry = archive.AddFile (file, archivePath: "foo.txt");
+ Assert.GreaterOrEqual (WithoutMilliseconds (entry.ModificationTime), lastWrite, $"Check 1 {WithoutMilliseconds (entry.ModificationTime)} < {lastWrite}");
+ }
+ using (var archive = ZipArchive.Open (zip, FileMode.Open)) {
+ ZipEntry entry = archive.ReadEntry ("foo.txt");
+ Assert.GreaterOrEqual (WithoutMilliseconds (entry.ModificationTime), lastWrite, $"Check 2 {WithoutMilliseconds (entry.ModificationTime)} < {lastWrite}");
+ }
+ }
+
+ [Test]
+ public void DateTimeConversion ()
+ {
+ DateTime now = DateTime.UtcNow;
+ for (int m = 0; m < 59; m++)
+ for (int s = 0; s < 59; s++)
+ for (int ms = 0; ms < 999; ms++) {
+ DateTime dt = new DateTime (now.Year, now.Month, now.Day, now.Hour, m, s, ms, DateTimeKind.Utc);
+ var dateTimeOffset = new DateTimeOffset(dt);
+ var unixTime = (ulong)dateTimeOffset.ToUnixTimeSeconds();
+ DateTime c = DateTimeOffset.FromUnixTimeSeconds ((long)unixTime).UtcDateTime;
+ Assert.AreEqual (WithoutMilliseconds (dt), WithoutMilliseconds (c));
+
+ }
+ }
}
}
\ No newline at end of file
diff --git a/LibZipSharp.code-workspace b/LibZipSharp.code-workspace
new file mode 100644
index 00000000..876a1499
--- /dev/null
+++ b/LibZipSharp.code-workspace
@@ -0,0 +1,8 @@
+{
+ "folders": [
+ {
+ "path": "."
+ }
+ ],
+ "settings": {}
+}
\ No newline at end of file
diff --git a/Native.cs b/Native.cs
index 1e748cbc..ffdf2eeb 100644
--- a/Native.cs
+++ b/Native.cs
@@ -360,6 +360,9 @@ public static int zip_set_file_comment (IntPtr archive, UInt64 index, string com
[DllImport (ZIP_LIBNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int zip_set_file_compression (IntPtr archive, UInt64 index, CompressionMethod comp, UInt32 comp_flags);
+
+ [DllImport (ZIP_LIBNAME, CallingConvention = CallingConvention.Cdecl)]
+ public static extern int zip_file_set_mtime(IntPtr archive, UInt64 index, ulong mtime, UInt32 flags);
[DllImport (ZIP_LIBNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr zip_source_buffer (IntPtr archive, byte[] data, UInt64 len, int freep);
diff --git a/Xamarin.LibZipSharp.targets b/Xamarin.LibZipSharp.targets
index c3777daf..b0245ca3 100644
--- a/Xamarin.LibZipSharp.targets
+++ b/Xamarin.LibZipSharp.targets
@@ -3,7 +3,7 @@
false
-
+
libZipSharp.dll.config
PreserveNewest
diff --git a/ZipArchive.cs b/ZipArchive.cs
index 25cec59f..6305bf83 100644
--- a/ZipArchive.cs
+++ b/ZipArchive.cs
@@ -330,7 +330,6 @@ public ZipEntry AddStream (Stream stream, string archivePath, EntryPermissions p
throw GetErrorException ();
if (Native.zip_set_file_compression (archive, (ulong)index, compressionMethod, 0) < 0)
throw GetErrorException ();
-
if (permissions == EntryPermissions.Default)
permissions = DefaultFilePermissions;
PlatformServices.Instance.SetEntryPermissions (this, (ulong)index, permissions, false);
@@ -721,7 +720,8 @@ internal static unsafe Int64 stream_callback (IntPtr state, IntPtr data, UInt64
return -1;
var stat = Native.ZipSourceGetArgs (data, len);
stat.size = (UInt64)stream.Length;
- stat.valid |= (ulong)StatFlags.Size;
+ stat.mtime = new IntPtr ((long)Utilities.UnixTimeFromDateTime (DateTime.UtcNow));
+ stat.valid |= (ulong)(StatFlags.Size | StatFlags.MTime);
Marshal.StructureToPtr (stat, data, false);
return (Int64)sizeof (Native.zip_stat_t);
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index d2006d14..e5184876 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -93,7 +93,7 @@ stages:
inputs:
solution: libZipSharp.csproj
configuration: Release
- msbuildArguments: /restore
+ msbuildArguments: /restore /v:diag
- task: MSBuild@1
displayName: NuGet pack libZipSharp
inputs:
@@ -133,7 +133,7 @@ stages:
inputs:
solution: LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj
configuration: Release
- msbuildArguments: /restore /t:RunNunitTests
+ msbuildArguments: /restore /t:RunNunitTests /p:ReferenceNuget=True /v:diag
- job: testmacos
displayName: 'Test MacOS'
pool:
@@ -149,7 +149,7 @@ stages:
inputs:
solution: LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj
configuration: Release
- msbuildArguments: /restore /t:RunNunitTests
+ msbuildArguments: /restore /t:RunNunitTests /p:ReferenceNuget=True /v:diag
- job: testwindows
displayName: 'Test Windows'
pool:
@@ -165,7 +165,7 @@ stages:
inputs:
solution: LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj
configuration: Release
- msbuildArguments: /restore /t:RunNunitTests
+ msbuildArguments: /restore /t:RunNunitTests /p:ReferenceNuget=True /v:diag
- stage: Publish
dependsOn: Test
condition: eq(variables['System.TeamProject'], 'devdiv') # only sign the packages when running on Windows, and using the private server which has the certificates
diff --git a/libZipSharp.csproj b/libZipSharp.csproj
index 238e4141..626dd304 100644
--- a/libZipSharp.csproj
+++ b/libZipSharp.csproj
@@ -4,7 +4,7 @@
libZipSharp
libZipSharp
- net45;netstandard2.0
+ netstandard2.0;net45
true
false
false
@@ -35,11 +35,11 @@
-
+
libZipSharp.dll.config
PreserveNewest
-
+
libZipSharp.dll.config
PreserveNewest