Skip to content

Commit 5b6acba

Browse files
authored
pythongh-95587: Fixes some upgrade detection issues in the Windows installer (pythonGH-95631)
1 parent 7b370b7 commit 5b6acba

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixes some issues where the Windows installer would incorrectly detect
2+
certain features of an existing install when upgrading.

Tools/msi/bundle/bootstrap/PythonBootstrapperApplication.cpp

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,8 @@ class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
724724
auto hr = LoadAssociateFilesStateFromKey(_engine, fPerMachine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER);
725725
if (hr == S_OK) {
726726
_engine->SetVariableNumeric(L"AssociateFiles", 1);
727+
} else if (hr == S_FALSE) {
728+
_engine->SetVariableNumeric(L"AssociateFiles", 0);
727729
} else if (FAILED(hr)) {
728730
BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Failed to load AssociateFiles state: error code 0x%08X", hr);
729731
}
@@ -817,6 +819,8 @@ class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
817819
auto hr = LoadAssociateFilesStateFromKey(_engine, hkey);
818820
if (hr == S_OK) {
819821
_engine->SetVariableNumeric(L"AssociateFiles", 1);
822+
} else if (hr == S_FALSE) {
823+
_engine->SetVariableNumeric(L"AssociateFiles", 0);
820824
} else if (FAILED(hr)) {
821825
BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Failed to load AssociateFiles state: error code 0x%08X", hr);
822826
}
@@ -834,7 +838,17 @@ class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
834838
LONGLONG includeLauncher;
835839
if (SUCCEEDED(BalGetNumericVariable(L"Include_launcher", &includeLauncher))
836840
&& includeLauncher == -1) {
837-
_engine->SetVariableNumeric(L"Include_launcher", 1);
841+
if (BOOTSTRAPPER_ACTION_LAYOUT == _command.action ||
842+
(BOOTSTRAPPER_ACTION_INSTALL == _command.action && !_upgrading)) {
843+
// When installing/downloading, we want to include the launcher
844+
// by default.
845+
_engine->SetVariableNumeric(L"Include_launcher", 1);
846+
} else {
847+
// Any other action, if we didn't detect the MSI then we want to
848+
// keep it excluded
849+
_engine->SetVariableNumeric(L"Include_launcher", 0);
850+
_engine->SetVariableNumeric(L"AssociateFiles", 0);
851+
}
838852
}
839853
}
840854

@@ -2812,6 +2826,17 @@ class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
28122826
return ::CompareStringW(LOCALE_NEUTRAL, 0, platform, -1, L"x64", -1) == CSTR_EQUAL;
28132827
}
28142828

2829+
static bool IsTargetPlatformARM64(__in IBootstrapperEngine* pEngine) {
2830+
WCHAR platform[8];
2831+
DWORD platformLen = 8;
2832+
2833+
if (FAILED(pEngine->GetVariableString(L"TargetPlatform", platform, &platformLen))) {
2834+
return S_FALSE;
2835+
}
2836+
2837+
return ::CompareStringW(LOCALE_NEUTRAL, 0, platform, -1, L"ARM64", -1) == CSTR_EQUAL;
2838+
}
2839+
28152840
static HRESULT LoadOptionalFeatureStatesFromKey(
28162841
__in IBootstrapperEngine* pEngine,
28172842
__in HKEY hkHive,
@@ -2820,7 +2845,7 @@ class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
28202845
HKEY hKey;
28212846
LRESULT res;
28222847

2823-
if (IsTargetPlatformx64(pEngine)) {
2848+
if (IsTargetPlatformx64(pEngine) || IsTargetPlatformARM64(pEngine)) {
28242849
res = RegOpenKeyExW(hkHive, subkey, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
28252850
} else {
28262851
res = RegOpenKeyExW(hkHive, subkey, 0, KEY_READ | KEY_WOW64_32KEY, &hKey);
@@ -2859,7 +2884,7 @@ class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
28592884
BYTE buffer[1024];
28602885
DWORD bufferLen = sizeof(buffer);
28612886

2862-
if (IsTargetPlatformx64(pEngine)) {
2887+
if (IsTargetPlatformx64(pEngine) || IsTargetPlatformARM64(pEngine)) {
28632888
res = RegOpenKeyExW(hkHive, subkey, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
28642889
} else {
28652890
res = RegOpenKeyExW(hkHive, subkey, 0, KEY_READ | KEY_WOW64_32KEY, &hKey);
@@ -2917,12 +2942,7 @@ class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
29172942
HRESULT hr;
29182943
HKEY hkHive;
29192944

2920-
// The launcher installation is separate from the Python install, so we
2921-
// check its state later. For now, assume we don't want the launcher or
2922-
// file associations, and if they have already been installed then
2923-
// loading the state will reactivate these settings.
2924-
pEngine->SetVariableNumeric(L"Include_launcher", 0);
2925-
pEngine->SetVariableNumeric(L"AssociateFiles", 0);
2945+
BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Loading state of optional features");
29262946

29272947
// Get the registry key from the bundle, to save having to duplicate it
29282948
// in multiple places.

0 commit comments

Comments
 (0)