From 8aafcc72550d89cc43dfcb81012abe8576709660 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 21 Dec 2022 23:06:05 -0800 Subject: Register the InstallDate in Burn Closes 7068 --- src/burn/engine/registration.cpp | 13 +++++++++++-- src/burn/test/BurnUnitTest/RegistrationTest.cpp | 2 ++ src/test/burn/WixTestTools/GenericArpRegistration.cs | 4 ++++ src/test/burn/WixToolsetTest.BurnE2E/RegistrationTests.cs | 7 +++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/burn/engine/registration.cpp b/src/burn/engine/registration.cpp index 0117a993..01ed30d7 100644 --- a/src/burn/engine/registration.cpp +++ b/src/burn/engine/registration.cpp @@ -10,6 +10,7 @@ const LPCWSTR REGISTRY_RUN_ONCE_KEY = L"SOFTWARE\\Microsoft\\Windows\\CurrentVer const LPCWSTR REGISTRY_BUNDLE_DISPLAY_ICON = L"DisplayIcon"; const LPCWSTR REGISTRY_BUNDLE_DISPLAY_VERSION = L"DisplayVersion"; const LPCWSTR REGISTRY_BUNDLE_ESTIMATED_SIZE = L"EstimatedSize"; +const LPCWSTR REGISTRY_BUNDLE_INSTALL_DATE = L"InstallDate"; const LPCWSTR REGISTRY_BUNDLE_PUBLISHER = L"Publisher"; const LPCWSTR REGISTRY_BUNDLE_HELP_LINK = L"HelpLink"; const LPCWSTR REGISTRY_BUNDLE_HELP_TELEPHONE = L"HelpTelephone"; @@ -610,6 +611,7 @@ extern "C" HRESULT RegistrationSessionBegin( HKEY hkRegistration = NULL; BOOL fCreated = FALSE; LPWSTR sczPublisher = NULL; + SYSTEMTIME systime = { }; DWORD er = ERROR_SUCCESS; AssertSz(BOOTSTRAPPER_REGISTRATION_TYPE_NONE != registrationType, "Registration type can't be NONE"); @@ -814,10 +816,17 @@ extern "C" HRESULT RegistrationSessionBegin( ExitOnFailure(hr, "Failed to write update registration."); } - // Only set estimated size here for the first time. - // It will always get updated at the end of the session. + // Only set install date and initial estimated size here for the first time. + // Estimated size will always get updated at the end of the session. if (fCreated) { + // Write the install date. + ::GetLocalTime(&systime); + + hr = RegWriteStringFormatted(hkRegistration, REGISTRY_BUNDLE_INSTALL_DATE, L"%04u%02u%02u", systime.wYear, systime.wMonth, systime.wDay); + ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_INSTALL_DATE); + + // Write the initial estimated size. hr = UpdateEstimatedSize(hkRegistration, qwEstimatedSize); ExitOnFailure(hr, "Failed to update estimated size."); } diff --git a/src/burn/test/BurnUnitTest/RegistrationTest.cpp b/src/burn/test/BurnUnitTest/RegistrationTest.cpp index f95c011f..fc84511d 100644 --- a/src/burn/test/BurnUnitTest/RegistrationTest.cpp +++ b/src/burn/test/BurnUnitTest/RegistrationTest.cpp @@ -111,6 +111,7 @@ namespace Bootstrapper Assert::True(Directory::Exists(cacheDirectory), "Cache directory didn't exist."); Assert::True(File::Exists(Path::Combine(cacheDirectory, gcnew String(L"setup.exe"))), "Bundle exe wasn't cached."); + this->ValidateUninstallKeyString(L"InstallDate", DateTime::Now.ToString("yyyyMMdd")); this->ValidateUninstallKeyResume(Int32(BURN_RESUME_MODE_ACTIVE)); this->ValidateRunOnceKeyEntry(cacheExePath); @@ -121,6 +122,7 @@ namespace Bootstrapper // verify that registration was removed Assert::False(Directory::Exists(cacheDirectory), "Cache directory wasn't removed."); + this->ValidateUninstallKeyNull(L"InstallDate"); this->ValidateUninstallKeyNull(L"Resume"); this->ValidateRunOnceKeyString(TEST_BUNDLE_ID, nullptr); } diff --git a/src/test/burn/WixTestTools/GenericArpRegistration.cs b/src/test/burn/WixTestTools/GenericArpRegistration.cs index d87c4feb..dfddd9a3 100644 --- a/src/test/burn/WixTestTools/GenericArpRegistration.cs +++ b/src/test/burn/WixTestTools/GenericArpRegistration.cs @@ -15,6 +15,7 @@ namespace WixTestTools public const string REGISTRY_ARP_DISPLAY_NAME = "DisplayName"; public const string REGISTRY_ARP_DISPLAY_VERSION = "DisplayVersion"; public const string REGISTRY_ARP_ESTIMATED_SIZE = "EstimatedSize"; + public const string REGISTRY_ARP_INSTALL_DATE = "InstallDate"; public const string REGISTRY_ARP_PUBLISHER = "Publisher"; public const string REGISTRY_ARP_HELP_LINK = "HelpLink"; public const string REGISTRY_ARP_HELP_TELEPHONE = "HelpTelephone"; @@ -42,6 +43,8 @@ namespace WixTestTools public int? EstimatedSize { get; set; } + public string InstallDate { get; set; } + public int? Installed { get; set; } public string ModifyPath { get; set; } @@ -103,6 +106,7 @@ namespace WixTestTools registration.DisplayName = idKey.GetValue(REGISTRY_ARP_DISPLAY_NAME) as string; registration.DisplayVersion = idKey.GetValue(REGISTRY_ARP_DISPLAY_VERSION) as string; registration.EstimatedSize = idKey.GetValue(REGISTRY_ARP_ESTIMATED_SIZE) as int?; + registration.InstallDate = idKey.GetValue(REGISTRY_ARP_INSTALL_DATE) as string; registration.Installed = idKey.GetValue(REGISTRY_ARP_INSTALLED) as int?; registration.ModifyPath = idKey.GetValue(REGISTRY_ARP_MODIFY_PATH) as string; registration.Publisher = idKey.GetValue(REGISTRY_ARP_PUBLISHER) as string; diff --git a/src/test/burn/WixToolsetTest.BurnE2E/RegistrationTests.cs b/src/test/burn/WixToolsetTest.BurnE2E/RegistrationTests.cs index b45ec83a..d9eb36ba 100644 --- a/src/test/burn/WixToolsetTest.BurnE2E/RegistrationTests.cs +++ b/src/test/burn/WixToolsetTest.BurnE2E/RegistrationTests.cs @@ -25,7 +25,12 @@ namespace WixToolsetTest.BurnE2E bundleA.Install(); var initialRegistration = bundleA.VerifyRegisteredAndInPackageCache(); + var now = DateTime.Now; + var today = now.ToString("yyyyMMdd"); + var yesterday = now.AddDays(-1).ToString("yyyyMMdd"); // check yesterday in case the bundle install crossed the midnight hour. + Assert.NotNull(initialRegistration.EstimatedSize); + Assert.True(initialRegistration.InstallDate == today || initialRegistration.InstallDate == yesterday, $"Installed date should have been {today} or {yesterday}"); testBAController.SetForceKeepRegistration(null); testBAController.ResetPackageStates("PackageA"); @@ -36,6 +41,8 @@ namespace WixToolsetTest.BurnE2E // Verifies https://github.com/wixtoolset/issues/issues/4039 Assert.NotNull(finalRegistration.EstimatedSize); Assert.InRange(finalRegistration.EstimatedSize.Value, initialRegistration.EstimatedSize.Value + 1, Int32.MaxValue); + + Assert.Equal(initialRegistration.InstallDate, finalRegistration.InstallDate); } [RuntimeFact] -- cgit v1.2.3-55-g6feb