Fix various MSI issues (#2985)

* wix: add Notice.md #2442

* wix: close PowerToys which might be running during installation process #2887

* wix: update dotnet core to 3.1.4
This commit is contained in:
Andrey Nekrasov 2020-05-14 19:20:06 +03:00 committed by GitHub
parent 7a1f3a0cb1
commit 6f38cdec5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 103 additions and 5 deletions

View File

@ -91,9 +91,19 @@
<Custom Action="InstallDotNet" After="InstallFinalize">
NOT Installed
</Custom>
<Custom Action="TerminateProcesses" Before="InstallValidate" />
</InstallExecuteSequence>
<CustomAction
Id="TerminateProcesses"
Return="ignore"
Impersonate="no"
Execute="immediate"
BinaryKey="PTCustomActions"
DllEntry="TerminateProcessesCA" />
<CustomAction
Id="InstallDotNet"
FileKey="action_runner.exe"
@ -344,6 +354,9 @@
<Component Id="License_rtf" Guid="3E5AE43B-CFB4-449B-A346-94CAAFF3312E" Win64="yes">
<File Source="$(var.RepoDir)\installer\License.rtf" Id="License.rtf" KeyPath="yes" />
</Component>
<Component Id="Notice_md" Guid="E2FE99F5-5DF7-44EA-8B1C-2BDF8CEC5E6D" Win64="yes">
<File Source="$(var.RepoDir)\Notice.md" Id="Notice.md" KeyPath="yes" />
</Component>
<Component Id="powertoysinterop_dll" Guid="B7DD2DF4-C8F2-46FA-9571-D6EF1588ADF3" Win64="yes">
<File Id="PowerToysInterop.dll" KeyPath="yes" Checksum="yes" />
</Component>
@ -695,6 +708,7 @@
<ComponentRef Id="action_runner_exe" />
<ComponentRef Id="powertoys_toast_clsid" />
<ComponentRef Id="License_rtf" />
<ComponentRef Id="Notice_md" />
<ComponentRef Id="powertoysinterop_dll" />
<ComponentRef Id="osDetection_dll" />
<ComponentRef Id="PowerToysSvgs" />

View File

@ -630,6 +630,84 @@ UINT __stdcall DetectPrevInstallPathCA(MSIHANDLE hInstall)
return WcaFinalize(er);
}
UINT __stdcall TerminateProcessesCA(MSIHANDLE hInstall)
{
HRESULT hr = S_OK;
UINT er = ERROR_SUCCESS;
hr = WcaInitialize(hInstall, "TerminateProcessesCA");
std::vector<DWORD> processes;
const size_t maxProcesses = 4096;
DWORD bytes = maxProcesses * sizeof(processes[0]);
processes.resize(maxProcesses);
if (!EnumProcesses(processes.data(), bytes, &bytes))
{
return 1;
}
processes.resize(bytes / sizeof(processes[0]));
std::array<std::wstring_view, 4> processesToTerminate = {
L"PowerLauncher.exe",
L"Microsoft.PowerToys.Settings.UI.Runner.exe",
L"Microsoft.PowerToys.Settings.UI.exe",
L"PowerToys.exe"
};
for (const auto procID : processes)
{
if (!procID)
{
continue;
}
wchar_t processName[MAX_PATH] = L"<unknown>";
HANDLE hProcess{OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ | PROCESS_TERMINATE, FALSE, procID)};
if (!hProcess)
{
continue;
}
HMODULE hMod;
DWORD cbNeeded;
if (!EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded))
{
CloseHandle(hProcess);
continue;
}
GetModuleBaseNameW(hProcess, hMod, processName, sizeof(processName) / sizeof(wchar_t));
for (const auto processToTerminate : processesToTerminate)
{
if (processName == processToTerminate)
{
const DWORD timeout = 500;
auto windowEnumerator = [](HWND hwnd, LPARAM procIDPtr) -> BOOL {
auto targetProcID = *reinterpret_cast<const DWORD*>(procIDPtr);
DWORD windowProcID = 0;
GetWindowThreadProcessId(hwnd, &windowProcID);
if (windowProcID == targetProcID)
{
DWORD_PTR _ {};
SendMessageTimeoutA(hwnd, WM_CLOSE, 0, 0, SMTO_BLOCK, timeout, &_);
}
return TRUE;
};
EnumWindows(windowEnumerator, reinterpret_cast<LPARAM>(&procID));
Sleep(timeout);
TerminateProcess(hProcess, 0);
break;
}
}
CloseHandle(hProcess);
}
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
return WcaFinalize(er);
}
// DllMain - Initialize and cleanup WiX custom action utils.
extern "C" BOOL WINAPI DllMain(__in HINSTANCE hInst, __in ULONG ulReason, __in LPVOID)
{

View File

@ -11,4 +11,5 @@ EXPORTS
TelemetryLogUninstallCancelCA
TelemetryLogUninstallFailCA
TelemetryLogRepairCancelCA
TelemetryLogRepairFailCA
TelemetryLogRepairFailCA
TerminateProcessesCA

View File

@ -61,7 +61,7 @@
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<AdditionalDependencies>Pathcch.lib;comsupp.lib;taskschd.lib;Secur32.lib;msi.lib;dutil.lib;wcautil.lib;Version.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>Psapi.lib;Pathcch.lib;comsupp.lib;taskschd.lib;Secur32.lib;msi.lib;dutil.lib;wcautil.lib;Version.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(WIX)sdk\$(WixPlatformToolset)\lib\x64;$(SolutionDir)\packages\WiX.3.11.2\tools\sdk\vs2017\lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ModuleDefinitionFile>CustomAction.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
@ -84,7 +84,7 @@
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<AdditionalDependencies>Pathcch.lib;comsupp.lib;taskschd.lib;Secur32.lib;msi.lib;dutil.lib;wcautil.lib;Version.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>Psapi.lib;Pathcch.lib;comsupp.lib;taskschd.lib;Secur32.lib;msi.lib;dutil.lib;wcautil.lib;Version.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(WIX)sdk\$(WixPlatformToolset)\lib\x64;$(SolutionDir)\packages\WiX.3.11.2\tools\sdk\vs2017\lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ModuleDefinitionFile>CustomAction.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>

View File

@ -1,6 +1,7 @@
#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define DPSAPI_VERSION 1
// Windows Header Files:
#include <windows.h>
#include <strsafe.h>
@ -21,3 +22,7 @@
#include <string>
#include <optional>
#include <pathcch.h>
#include <psapi.h>
#include <vector>
#include <array>

View File

@ -139,8 +139,8 @@ bool dotnet_is_installed()
bool install_dotnet()
{
const wchar_t DOTNET_DESKTOP_DOWNLOAD_LINK[] = L"https://download.visualstudio.microsoft.com/download/pr/a1510e74-b31a-4434-b8a0-8074ff31fb3f/b7de8ecba4a14d8312551cfdc745dea1/windowsdesktop-runtime-3.1.0-win-x64.exe";
const wchar_t DOTNET_DESKTOP_FILENAME[] = L"windowsdesktop-runtime-3.1.0-win-x64.exe";
const wchar_t DOTNET_DESKTOP_DOWNLOAD_LINK[] = L"https://download.visualstudio.microsoft.com/download/pr/d8cf1fe3-21c2-4baf-988f-f0152996135e/0c00b94713ee93e7ad5b4f82e2b86607/windowsdesktop-runtime-3.1.4-win-x64.exe";
const wchar_t DOTNET_DESKTOP_FILENAME[] = L"windowsdesktop-runtime-3.1.4-win-x64.exe";
auto dotnet_download_path = fs::temp_directory_path() / DOTNET_DESKTOP_FILENAME;
winrt::Windows::Foundation::Uri download_link{ DOTNET_DESKTOP_DOWNLOAD_LINK };