Register the InstallDate in Burn
Closes 7068
Rob Mensching committed
Dec 21, 2022 at 23:06 UTC
8aafcc72550d89cc43dfcb81012abe8576709660
4 files changed
+24
-2
src/burn/engine/registration.cpp
+11
-2
@@ -10,6 +10,7 @@ const LPCWSTR REGISTRY_RUN_ONCE_KEY = L"SOFTWARE\\Microsoft\\Windows\\CurrentVer
10
const LPCWSTR REGISTRY_BUNDLE_DISPLAY_ICON = L"DisplayIcon";
11
const LPCWSTR REGISTRY_BUNDLE_DISPLAY_VERSION = L"DisplayVersion";
12
const LPCWSTR REGISTRY_BUNDLE_ESTIMATED_SIZE = L"EstimatedSize";
13
+const LPCWSTR REGISTRY_BUNDLE_INSTALL_DATE = L"InstallDate";
14
const LPCWSTR REGISTRY_BUNDLE_PUBLISHER = L"Publisher";
15
const LPCWSTR REGISTRY_BUNDLE_HELP_LINK = L"HelpLink";
16
const LPCWSTR REGISTRY_BUNDLE_HELP_TELEPHONE = L"HelpTelephone";
@@ -610,6 +611,7 @@ extern "C" HRESULT RegistrationSessionBegin(
611
HKEY hkRegistration = NULL;
612
BOOL fCreated = FALSE;
613
LPWSTR sczPublisher = NULL;
614
+ SYSTEMTIME systime = { };
615
DWORD er = ERROR_SUCCESS;
616
617
AssertSz(BOOTSTRAPPER_REGISTRATION_TYPE_NONE != registrationType, "Registration type can't be NONE");
@@ -814,10 +816,17 @@ extern "C" HRESULT RegistrationSessionBegin(
816
ExitOnFailure(hr, "Failed to write update registration.");
817
}
818
817
- // Only set estimated size here for the first time.
818
- // It will always get updated at the end of the session.
819
+ // Only set install date and initial estimated size here for the first time.
820
+ // Estimated size will always get updated at the end of the session.
821
if (fCreated)
822
{
823
+ // Write the install date.
824
+ ::GetLocalTime(&systime);
825
+
826
+ hr = RegWriteStringFormatted(hkRegistration, REGISTRY_BUNDLE_INSTALL_DATE, L"%04u%02u%02u", systime.wYear, systime.wMonth, systime.wDay);
827
+ ExitOnFailure(hr, "Failed to write %ls value.", REGISTRY_BUNDLE_INSTALL_DATE);
828
+
829
+ // Write the initial estimated size.
830
hr = UpdateEstimatedSize(hkRegistration, qwEstimatedSize);
831
ExitOnFailure(hr, "Failed to update estimated size.");
832
}
src/burn/test/BurnUnitTest/RegistrationTest.cpp
+2
@@ -111,6 +111,7 @@ namespace Bootstrapper
111
Assert::True(Directory::Exists(cacheDirectory), "Cache directory didn't exist.");
112
Assert::True(File::Exists(Path::Combine(cacheDirectory, gcnew String(L"setup.exe"))), "Bundle exe wasn't cached.");
113
114
+ this->ValidateUninstallKeyString(L"InstallDate", DateTime::Now.ToString("yyyyMMdd"));
115
this->ValidateUninstallKeyResume(Int32(BURN_RESUME_MODE_ACTIVE));
116
this->ValidateRunOnceKeyEntry(cacheExePath);
117
@@ -121,6 +122,7 @@ namespace Bootstrapper
122
// verify that registration was removed
123
Assert::False(Directory::Exists(cacheDirectory), "Cache directory wasn't removed.");
124
125
+ this->ValidateUninstallKeyNull(L"InstallDate");
126
this->ValidateUninstallKeyNull(L"Resume");
127
this->ValidateRunOnceKeyString(TEST_BUNDLE_ID, nullptr);
128
}
src/test/burn/WixTestTools/GenericArpRegistration.cs
+4
@@ -15,6 +15,7 @@ namespace WixTestTools
15
public const string REGISTRY_ARP_DISPLAY_NAME = "DisplayName";
16
public const string REGISTRY_ARP_DISPLAY_VERSION = "DisplayVersion";
17
public const string REGISTRY_ARP_ESTIMATED_SIZE = "EstimatedSize";
18
+ public const string REGISTRY_ARP_INSTALL_DATE = "InstallDate";
19
public const string REGISTRY_ARP_PUBLISHER = "Publisher";
20
public const string REGISTRY_ARP_HELP_LINK = "HelpLink";
21
public const string REGISTRY_ARP_HELP_TELEPHONE = "HelpTelephone";
@@ -42,6 +43,8 @@ namespace WixTestTools
43
44
public int? EstimatedSize { get; set; }
45
46
+ public string InstallDate { get; set; }
47
+
48
public int? Installed { get; set; }
49
50
public string ModifyPath { get; set; }
@@ -103,6 +106,7 @@ namespace WixTestTools
106
registration.DisplayName = idKey.GetValue(REGISTRY_ARP_DISPLAY_NAME) as string;
107
registration.DisplayVersion = idKey.GetValue(REGISTRY_ARP_DISPLAY_VERSION) as string;
108
registration.EstimatedSize = idKey.GetValue(REGISTRY_ARP_ESTIMATED_SIZE) as int?;
109
+ registration.InstallDate = idKey.GetValue(REGISTRY_ARP_INSTALL_DATE) as string;
110
registration.Installed = idKey.GetValue(REGISTRY_ARP_INSTALLED) as int?;
111
registration.ModifyPath = idKey.GetValue(REGISTRY_ARP_MODIFY_PATH) as string;
112
registration.Publisher = idKey.GetValue(REGISTRY_ARP_PUBLISHER) as string;
src/test/burn/WixToolsetTest.BurnE2E/RegistrationTests.cs
+7
@@ -25,7 +25,12 @@ namespace WixToolsetTest.BurnE2E
25
bundleA.Install();
26
var initialRegistration = bundleA.VerifyRegisteredAndInPackageCache();
27
28
+ var now = DateTime.Now;
29
+ var today = now.ToString("yyyyMMdd");
30
+ var yesterday = now.AddDays(-1).ToString("yyyyMMdd"); // check yesterday in case the bundle install crossed the midnight hour.
31
+
32
Assert.NotNull(initialRegistration.EstimatedSize);
33
+ Assert.True(initialRegistration.InstallDate == today || initialRegistration.InstallDate == yesterday, $"Installed date should have been {today} or {yesterday}");
34
35
testBAController.SetForceKeepRegistration(null);
36
testBAController.ResetPackageStates("PackageA");
@@ -36,6 +41,8 @@ namespace WixToolsetTest.BurnE2E
41
// Verifies https://github.com/wixtoolset/issues/issues/4039
42
Assert.NotNull(finalRegistration.EstimatedSize);
43
Assert.InRange(finalRegistration.EstimatedSize.Value, initialRegistration.EstimatedSize.Value + 1, Int32.MaxValue);
44
+
45
+ Assert.Equal(initialRegistration.InstallDate, finalRegistration.InstallDate);
46
}
47
48
[RuntimeFact]