Skip to content

Commit

Permalink
adjustments to the file modified time
Browse files Browse the repository at this point in the history
  • Loading branch information
cengelha committed Mar 3, 2024
1 parent 4983606 commit 19ceb68
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 52 deletions.
69 changes: 21 additions & 48 deletions libNOM.test/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,64 +201,37 @@ public void ExtractArchive()

if (!Directory.Exists(template))
{
//using SharpCompress.Archives;
//using SharpCompress.Common;
Directory.CreateDirectory(template);
using var zipArchive = ArchiveFactory.Open($"{nameof(Properties.Resources.TESTSUITE_ARCHIVE)}.zip", new()
{
Password = Properties.Resources.TESTSUITE_PASSWORD,
});
foreach (var entry in zipArchive.Entries)
{
if (entry.IsDirectory)
continue;

entry.WriteToDirectory(template, new ExtractionOptions
if (!entry.IsDirectory)
{
ExtractFullPath = true,
Overwrite = true,
});
}

//using ICSharpCode.SharpZipLib.Zip;
//using var zipArchive = new ZipFile($"{nameof(Properties.Resources.TESTSUITE_ARCHIVE)}.zip")
//{
// Password = Properties.Resources.TESTSUITE_PASSWORD,
//};
//foreach (ZipEntry entry in zipArchive)
// if (entry.IsFile)
// {
// string outputFile = Path.Combine(template, entry.Name);

// Directory.CreateDirectory(Path.GetDirectoryName(outputFile)!);

// using var input = zipArchive.GetInputStream(entry);
// using var output = File.Create(outputFile);
// var buffer = new byte[4096];
// int bytesRead;
// while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
// output.Write(buffer, 0, bytesRead);
// }

//using Aspose.Zip;
//using var zipArchive = new Archive($"{nameof(Properties.Resources.TESTSUITE_ARCHIVE)}.zip", new ArchiveLoadOptions()
//{
// DecryptionPassword = Properties.Resources.TESTSUITE_PASSWORD,
//});
//zipArchive.ExtractToDirectory(template);

//using Ionic.Zip;
//using var zipArchive = new ZipFile($"{nameof(Properties.Resources.TESTSUITE_ARCHIVE)}.zip")
//{
// Encryption = EncryptionAlgorithm.WinZipAes256,
// Password = Properties.Resources.TESTSUITE_PASSWORD,
//};
//zipArchive.ExtractAll(template, ExtractExistingFileAction.DoNotOverwrite);
entry.WriteToDirectory(template, new ExtractionOptions
{
ExtractFullPath = true,
Overwrite = true,
PreserveFileTime = false, // do not use for the reason below
});
// The entry has not always the correct LastModifiedTime (can be 1 hour off due to daylight saving time).
if (entry.LastModifiedTime.HasValue)
{
var hours = 0;

if (entry.LastModifiedTime!.Value.IsDaylightSavingTime() && !DateTime.Now.IsDaylightSavingTime())
hours = +1;

if (!entry.LastModifiedTime!.Value.IsDaylightSavingTime() && DateTime.Now.IsDaylightSavingTime())
hours = -1;

File.SetLastWriteTimeUtc(Path.Combine(template, entry.Key), entry.LastModifiedTime.Value.Add(new TimeSpan(hours, 0, 0)).ToUniversalTime());
}
}
}
if (!Directory.Exists(working))
{
Copy(template, working);
}
}

[TestCleanup]
Expand Down
2 changes: 1 addition & 1 deletion libNOM.test/Steam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ public void T14_Write_Default_0x7D2_Waypoint_Account()
Assert.IsTrue(writeCallback);

Assert.AreEqual(80, valuesOrigin.MusicVolume);
Assert.AreEqual(638263807910000000, valuesOrigin.UtcTicks); // 2023-07-22 15:12:32 +00:00
Assert.AreEqual(638263807920000000, valuesOrigin.UtcTicks); // 2023-07-22 08:13:12 +00:00
Assert.AreEqual(MUSICVOLUME_NEW_AMOUNT, valuesSet.MusicVolume);
Assert.AreEqual(now.UtcTicks, valuesSet.UtcTicks);

Expand Down
4 changes: 2 additions & 2 deletions libNOM.test/Switch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public void T11_Write_Default_0x7D2_Frontiers_Account()
Assert.IsTrue(writeCallback);

Assert.AreEqual(80, valuesOrigin.MusicVolume);
Assert.AreEqual(1665085531, valuesOrigin.UnixSeconds); // 2022-10-06 19:45:31 +00:00
Assert.AreEqual(1665085532, valuesOrigin.UnixSeconds); // 2022-10-06 19:45:32 +00:00
Assert.AreEqual(MUSICVOLUME_NEW_AMOUNT, valuesSet.MusicVolume);
Assert.AreEqual(nowUnix, valuesSet.UnixSeconds);

Expand Down Expand Up @@ -489,7 +489,7 @@ public void T13_Write_Default_0x7D2_Waypoint_Account()
Assert.IsTrue(writeCallback);

Assert.AreEqual(80, valuesOrigin.MusicVolume);
Assert.AreEqual(1694247283, valuesOrigin.UnixSeconds); // 2023-09-09 08:14:43 +00:00
Assert.AreEqual(1694247284, valuesOrigin.UnixSeconds); // 2023-09-09 08:14:44 +00:00
Assert.AreEqual(MUSICVOLUME_NEW_AMOUNT, valuesSet.MusicVolume);
Assert.AreEqual(nowUnix, valuesSet.UnixSeconds);

Expand Down
1 change: 0 additions & 1 deletion libNOM.test/libNOM.test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

<!-- Dependencies -->
<ItemGroup>
<PackageReference Include="Aspose.Zip" Version="24.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.2.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.2.2" />
Expand Down

0 comments on commit 19ceb68

Please sign in to comment.