mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 09:28:03 +08:00
[installer] Log installer to separate file (#24045)
* [installer] Log installer to separate file * Spellcheck and minor fix * Delete interop hardlinks before creating them
This commit is contained in:
parent
aceffe3212
commit
47999199e9
6
.github/actions/spell-check/expect.txt
vendored
6
.github/actions/spell-check/expect.txt
vendored
@ -40,7 +40,6 @@ ALPHATYPE
|
|||||||
Altdown
|
Altdown
|
||||||
alwaysontop
|
alwaysontop
|
||||||
amd
|
amd
|
||||||
AMF
|
|
||||||
AModifier
|
AModifier
|
||||||
AMPROPERTY
|
AMPROPERTY
|
||||||
AMPROPSETID
|
AMPROPSETID
|
||||||
@ -206,7 +205,6 @@ CHILDACTIVATE
|
|||||||
CHILDWINDOW
|
CHILDWINDOW
|
||||||
Choibalsan
|
Choibalsan
|
||||||
chrdavis
|
chrdavis
|
||||||
chromaticities
|
|
||||||
Chrzan
|
Chrzan
|
||||||
cht
|
cht
|
||||||
Chukotka
|
Chukotka
|
||||||
@ -393,7 +391,6 @@ Deondre
|
|||||||
depersist
|
depersist
|
||||||
deprioritized
|
deprioritized
|
||||||
depsfileslistspath
|
depsfileslistspath
|
||||||
depsjsonpath
|
|
||||||
deref
|
deref
|
||||||
DESKTOPABSOLUTEEDITING
|
DESKTOPABSOLUTEEDITING
|
||||||
DESKTOPABSOLUTEPARSING
|
DESKTOPABSOLUTEPARSING
|
||||||
@ -931,7 +928,6 @@ logconsole
|
|||||||
logfile
|
logfile
|
||||||
LOGFONT
|
LOGFONT
|
||||||
LOGFONTW
|
LOGFONTW
|
||||||
LOGMSG
|
|
||||||
logon
|
logon
|
||||||
LOGPIXELSX
|
LOGPIXELSX
|
||||||
LOn
|
LOn
|
||||||
@ -2004,7 +2000,7 @@ WANTPALM
|
|||||||
wbem
|
wbem
|
||||||
wbemuuid
|
wbemuuid
|
||||||
WBounds
|
WBounds
|
||||||
wca
|
Wca
|
||||||
wcautil
|
wcautil
|
||||||
WCE
|
WCE
|
||||||
wcex
|
wcex
|
||||||
|
@ -177,9 +177,7 @@
|
|||||||
<Custom Action="DeleteWinAppSDKHardlinks" Before="RemoveFiles">
|
<Custom Action="DeleteWinAppSDKHardlinks" Before="RemoveFiles">
|
||||||
Installed AND (REMOVE="ALL")
|
Installed AND (REMOVE="ALL")
|
||||||
</Custom>
|
</Custom>
|
||||||
<Custom Action="DeletePTInteropHardlinks" Before="RemoveFiles">
|
<Custom Action="DeletePTInteropHardlinks" Before="CreatePTInteropHardlinks" />
|
||||||
Installed AND (REMOVE="ALL")
|
|
||||||
</Custom>
|
|
||||||
|
|
||||||
<Custom Action="DeleteDotnetRuntimeHardlinks" Before="RemoveFiles">
|
<Custom Action="DeleteDotnetRuntimeHardlinks" Before="RemoveFiles">
|
||||||
Installed AND (REMOVE="ALL")
|
Installed AND (REMOVE="ALL")
|
||||||
|
@ -34,24 +34,6 @@ const DWORD USERNAME_LEN = UNLEN + 1; // User Name + '\0'
|
|||||||
static const wchar_t* POWERTOYS_EXE_COMPONENT = L"{A2C66D91-3485-4D00-B04D-91844E6B345B}";
|
static const wchar_t* POWERTOYS_EXE_COMPONENT = L"{A2C66D91-3485-4D00-B04D-91844E6B345B}";
|
||||||
static const wchar_t* POWERTOYS_UPGRADE_CODE = L"{42B84BF7-5FBF-473B-9C8B-049DC16F7708}";
|
static const wchar_t* POWERTOYS_UPGRADE_CODE = L"{42B84BF7-5FBF-473B-9C8B-049DC16F7708}";
|
||||||
|
|
||||||
struct WcaSink : spdlog::sinks::base_sink<std::mutex>
|
|
||||||
{
|
|
||||||
virtual void sink_it_(const spdlog::details::log_msg& msg) override
|
|
||||||
{
|
|
||||||
WcaLog(LOGMSG_STANDARD, msg.payload.data());
|
|
||||||
}
|
|
||||||
virtual void flush_() override
|
|
||||||
{
|
|
||||||
// we don't need to flush wca log manually
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void initSystemLogger()
|
|
||||||
{
|
|
||||||
static std::once_flag initLoggerFlag;
|
|
||||||
std::call_once(initLoggerFlag, []() { Logger::init(std::vector<spdlog::sink_ptr>{ std::make_shared<WcaSink>() }); });
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT getInstallFolder(MSIHANDLE hInstall, std::wstring& installationDir)
|
HRESULT getInstallFolder(MSIHANDLE hInstall, std::wstring& installationDir)
|
||||||
{
|
{
|
||||||
DWORD len = 0;
|
DWORD len = 0;
|
||||||
@ -70,7 +52,6 @@ LExit:
|
|||||||
}
|
}
|
||||||
UINT __stdcall ApplyModulesRegistryChangeSetsCA(MSIHANDLE hInstall)
|
UINT __stdcall ApplyModulesRegistryChangeSetsCA(MSIHANDLE hInstall)
|
||||||
{
|
{
|
||||||
initSystemLogger();
|
|
||||||
HRESULT hr = S_OK;
|
HRESULT hr = S_OK;
|
||||||
UINT er = ERROR_SUCCESS;
|
UINT er = ERROR_SUCCESS;
|
||||||
std::wstring installationFolder;
|
std::wstring installationFolder;
|
||||||
@ -85,14 +66,14 @@ UINT __stdcall ApplyModulesRegistryChangeSetsCA(MSIHANDLE hInstall)
|
|||||||
{
|
{
|
||||||
if (!changeSet.apply())
|
if (!changeSet.apply())
|
||||||
{
|
{
|
||||||
WcaLog(LOGMSG_STANDARD, "Couldn't apply registry changeSet");
|
Logger::error(L"Couldn't apply registry changeSet");
|
||||||
failedToApply = true;
|
failedToApply = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!failedToApply)
|
if (!failedToApply)
|
||||||
{
|
{
|
||||||
WcaLog(LOGMSG_STANDARD, "All registry changeSets applied successfully");
|
Logger::info(L"All registry changeSets applied successfully");
|
||||||
}
|
}
|
||||||
LExit:
|
LExit:
|
||||||
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
||||||
@ -101,7 +82,6 @@ LExit:
|
|||||||
|
|
||||||
UINT __stdcall UnApplyModulesRegistryChangeSetsCA(MSIHANDLE hInstall)
|
UINT __stdcall UnApplyModulesRegistryChangeSetsCA(MSIHANDLE hInstall)
|
||||||
{
|
{
|
||||||
initSystemLogger();
|
|
||||||
HRESULT hr = S_OK;
|
HRESULT hr = S_OK;
|
||||||
UINT er = ERROR_SUCCESS;
|
UINT er = ERROR_SUCCESS;
|
||||||
std::wstring installationFolder;
|
std::wstring installationFolder;
|
||||||
@ -131,14 +111,14 @@ UINT __stdcall InstallEmbeddedMSIXCA(MSIHANDLE hInstall)
|
|||||||
|
|
||||||
if (auto msix = RcResource::create(IDR_BIN_MSIX_HELLO_PACKAGE, L"BIN", DLL_HANDLE))
|
if (auto msix = RcResource::create(IDR_BIN_MSIX_HELLO_PACKAGE, L"BIN", DLL_HANDLE))
|
||||||
{
|
{
|
||||||
WcaLog(LOGMSG_STANDARD, "Extracted MSIX");
|
Logger::info(L"Extracted MSIX");
|
||||||
// TODO: Use to activate embedded MSIX
|
// TODO: Use to activate embedded MSIX
|
||||||
const auto msix_path = std::filesystem::temp_directory_path() / "hello_package.msix";
|
const auto msix_path = std::filesystem::temp_directory_path() / "hello_package.msix";
|
||||||
if (!msix->saveAsFile(msix_path))
|
if (!msix->saveAsFile(msix_path))
|
||||||
{
|
{
|
||||||
ExitOnFailure(hr, "Failed to save msix");
|
ExitOnFailure(hr, "Failed to save msix");
|
||||||
}
|
}
|
||||||
WcaLog(LOGMSG_STANDARD, "Saved MSIX");
|
Logger::info(L"Saved MSIX");
|
||||||
using namespace winrt::Windows::Management::Deployment;
|
using namespace winrt::Windows::Management::Deployment;
|
||||||
using namespace winrt::Windows::Foundation;
|
using namespace winrt::Windows::Foundation;
|
||||||
|
|
||||||
@ -150,7 +130,7 @@ UINT __stdcall InstallEmbeddedMSIXCA(MSIHANDLE hInstall)
|
|||||||
ExitOnFailure(hr, "Failed to AddPackage");
|
ExitOnFailure(hr, "Failed to AddPackage");
|
||||||
}
|
}
|
||||||
|
|
||||||
WcaLog(LOGMSG_STANDARD, "MSIX[s] were installed!");
|
Logger::info(L"MSIX[s] were installed!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -181,11 +161,11 @@ UINT __stdcall UninstallEmbeddedMSIXCA(MSIHANDLE hInstall)
|
|||||||
auto result = pm.RemovePackageAsync(p.Id().FullName()).get();
|
auto result = pm.RemovePackageAsync(p.Id().FullName()).get();
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
WcaLog(LOGMSG_STANDARD, "MSIX was uninstalled!");
|
Logger::info(L"MSIX was uninstalled!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
WcaLog(LOGMSG_STANDARD, "Couldn't uninstall MSIX!");
|
Logger::error(L"Couldn't uninstall MSIX!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +207,7 @@ UINT __stdcall CreateScheduledTaskCA(MSIHANDLE hInstall)
|
|||||||
hr = WcaInitialize(hInstall, "CreateScheduledTaskCA");
|
hr = WcaInitialize(hInstall, "CreateScheduledTaskCA");
|
||||||
ExitOnFailure(hr, "Failed to initialize");
|
ExitOnFailure(hr, "Failed to initialize");
|
||||||
|
|
||||||
WcaLog(LOGMSG_STANDARD, "Initialized.");
|
Logger::info(L"CreateScheduledTaskCA Initialized.");
|
||||||
|
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
// Get the Domain/Username for the trigger.
|
// Get the Domain/Username for the trigger.
|
||||||
@ -246,7 +226,7 @@ UINT __stdcall CreateScheduledTaskCA(MSIHANDLE hInstall)
|
|||||||
wcscat_s(username_domain, L"\\");
|
wcscat_s(username_domain, L"\\");
|
||||||
wcscat_s(username_domain, username);
|
wcscat_s(username_domain, username);
|
||||||
|
|
||||||
WcaLog(LOGMSG_STANDARD, "Current user detected: %ls", username_domain);
|
Logger::info(L"Current user detected: {}", username_domain);
|
||||||
|
|
||||||
// Task Name.
|
// Task Name.
|
||||||
wstrTaskName = L"Autorun for ";
|
wstrTaskName = L"Autorun for ";
|
||||||
@ -286,7 +266,7 @@ UINT __stdcall CreateScheduledTaskCA(MSIHANDLE hInstall)
|
|||||||
pRootFolder->Release();
|
pRootFolder->Release();
|
||||||
ExitOnFailure(hr, "Cannot create PowerToys task folder: %x", hr);
|
ExitOnFailure(hr, "Cannot create PowerToys task folder: %x", hr);
|
||||||
}
|
}
|
||||||
WcaLog(LOGMSG_STANDARD, "PowerToys task folder created.");
|
Logger::info(L"PowerToys task folder created.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the same task exists, remove it.
|
// If the same task exists, remove it.
|
||||||
@ -334,7 +314,7 @@ UINT __stdcall CreateScheduledTaskCA(MSIHANDLE hInstall)
|
|||||||
hr = pLogonTrigger->put_Id(_bstr_t(L"Trigger1"));
|
hr = pLogonTrigger->put_Id(_bstr_t(L"Trigger1"));
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
WcaLogError(hr, "Cannot put the trigger ID: %x", hr);
|
Logger::error(L"Cannot put the trigger ID: {}", hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Timing issues may make explorer not be started when the task runs.
|
// Timing issues may make explorer not be started when the task runs.
|
||||||
@ -342,7 +322,7 @@ UINT __stdcall CreateScheduledTaskCA(MSIHANDLE hInstall)
|
|||||||
hr = pLogonTrigger->put_Delay(_bstr_t(L"PT03S"));
|
hr = pLogonTrigger->put_Delay(_bstr_t(L"PT03S"));
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
WcaLogError(hr, "Cannot put the trigger delay: %x", hr);
|
Logger::error(L"Cannot put the trigger delay: {}", hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define the user. The task will execute when the user logs on.
|
// Define the user. The task will execute when the user logs on.
|
||||||
@ -383,19 +363,19 @@ UINT __stdcall CreateScheduledTaskCA(MSIHANDLE hInstall)
|
|||||||
hr = pPrincipal->put_Id(_bstr_t(L"Principal1"));
|
hr = pPrincipal->put_Id(_bstr_t(L"Principal1"));
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
WcaLogError(hr, "Cannot put the principal ID: %x", hr);
|
Logger::error(L"Cannot put the principal ID: {}", hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = pPrincipal->put_UserId(_bstr_t(username_domain));
|
hr = pPrincipal->put_UserId(_bstr_t(username_domain));
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
WcaLogError(hr, "Cannot put principal user Id: %x", hr);
|
Logger::error(L"Cannot put principal user Id: {}", hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = pPrincipal->put_LogonType(TASK_LOGON_INTERACTIVE_TOKEN);
|
hr = pPrincipal->put_LogonType(TASK_LOGON_INTERACTIVE_TOKEN);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
WcaLogError(hr, "Cannot put principal logon type: %x", hr);
|
Logger::error(L"Cannot put principal logon type: {}", hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the task with the highest available privileges.
|
// Run the task with the highest available privileges.
|
||||||
@ -419,7 +399,7 @@ UINT __stdcall CreateScheduledTaskCA(MSIHANDLE hInstall)
|
|||||||
ExitOnFailure(hr, "Error saving the Task : %x", hr);
|
ExitOnFailure(hr, "Error saving the Task : %x", hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
WcaLog(LOGMSG_STANDARD, "Scheduled task created for the current user.");
|
Logger::info(L"Scheduled task created for the current user.");
|
||||||
|
|
||||||
LExit:
|
LExit:
|
||||||
ReleaseStr(wszExecutablePath);
|
ReleaseStr(wszExecutablePath);
|
||||||
@ -480,7 +460,7 @@ UINT __stdcall RemoveScheduledTasksCA(MSIHANDLE hInstall)
|
|||||||
hr = WcaInitialize(hInstall, "RemoveScheduledTasksCA");
|
hr = WcaInitialize(hInstall, "RemoveScheduledTasksCA");
|
||||||
ExitOnFailure(hr, "Failed to initialize");
|
ExitOnFailure(hr, "Failed to initialize");
|
||||||
|
|
||||||
WcaLog(LOGMSG_STANDARD, "Initialized.");
|
Logger::info(L"RemoveScheduledTasksCA Initialized.");
|
||||||
|
|
||||||
// COM and Security Initialization is expected to have been done by the MSI.
|
// COM and Security Initialization is expected to have been done by the MSI.
|
||||||
// It couldn't be done in the DLL, anyway.
|
// It couldn't be done in the DLL, anyway.
|
||||||
@ -503,7 +483,7 @@ UINT __stdcall RemoveScheduledTasksCA(MSIHANDLE hInstall)
|
|||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
// Folder doesn't exist. No need to delete anything.
|
// Folder doesn't exist. No need to delete anything.
|
||||||
WcaLog(LOGMSG_STANDARD, "The PowerToys scheduled task folder wasn't found. Nothing to delete.");
|
Logger::info(L"The PowerToys scheduled task folder wasn't found. Nothing to delete.");
|
||||||
hr = S_OK;
|
hr = S_OK;
|
||||||
ExitFunction();
|
ExitFunction();
|
||||||
}
|
}
|
||||||
@ -529,19 +509,19 @@ UINT __stdcall RemoveScheduledTasksCA(MSIHANDLE hInstall)
|
|||||||
hr = pTaskFolder->DeleteTask(taskName, 0);
|
hr = pTaskFolder->DeleteTask(taskName, 0);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
WcaLogError(hr, "Cannot delete the '%S' task: %x", taskName, hr);
|
Logger::error(L"Cannot delete the {} task: {}", taskName, hr);
|
||||||
}
|
}
|
||||||
SysFreeString(taskName);
|
SysFreeString(taskName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
WcaLogError(hr, "Cannot get the registered task name: %x", hr);
|
Logger::error(L"Cannot get the registered task name: {}", hr);
|
||||||
}
|
}
|
||||||
pRegisteredTask->Release();
|
pRegisteredTask->Release();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
WcaLogError(hr, "Cannot get the registered task item at index=%d: %x", i + 1, hr);
|
Logger::error(L"Cannot get the registered task item at index={}: {}", i + 1, hr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -553,7 +533,7 @@ UINT __stdcall RemoveScheduledTasksCA(MSIHANDLE hInstall)
|
|||||||
pRootFolder->Release();
|
pRootFolder->Release();
|
||||||
ExitOnFailure(hr, "Cannot delete the PowerToys folder: %x", hr);
|
ExitOnFailure(hr, "Cannot delete the PowerToys folder: %x", hr);
|
||||||
|
|
||||||
WcaLog(LOGMSG_STANDARD, "Deleted the PowerToys Task Scheduler folder.");
|
Logger::info(L"Deleted the PowerToys Task Scheduler folder.");
|
||||||
|
|
||||||
LExit:
|
LExit:
|
||||||
if (pService)
|
if (pService)
|
||||||
@ -1400,6 +1380,20 @@ UINT __stdcall TerminateProcessesCA(MSIHANDLE hInstall)
|
|||||||
return WcaFinalize(er);
|
return WcaFinalize(er);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void initSystemLogger()
|
||||||
|
{
|
||||||
|
static std::once_flag initLoggerFlag;
|
||||||
|
std::call_once(initLoggerFlag, []() {
|
||||||
|
WCHAR temp_path[MAX_PATH];
|
||||||
|
auto ret = GetTempPath(MAX_PATH, temp_path);
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
Logger::init("PowerToysMSI", std::wstring{ temp_path } + L"\\PowerToysMSIInstaller", L"");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// DllMain - Initialize and cleanup WiX custom action utils.
|
// DllMain - Initialize and cleanup WiX custom action utils.
|
||||||
extern "C" BOOL WINAPI DllMain(__in HINSTANCE hInst, __in ULONG ulReason, __in LPVOID)
|
extern "C" BOOL WINAPI DllMain(__in HINSTANCE hInst, __in ULONG ulReason, __in LPVOID)
|
||||||
{
|
{
|
||||||
@ -1407,6 +1401,7 @@ extern "C" BOOL WINAPI DllMain(__in HINSTANCE hInst, __in ULONG ulReason, __in L
|
|||||||
{
|
{
|
||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_ATTACH:
|
||||||
WcaGlobalInitialize(hInst);
|
WcaGlobalInitialize(hInst);
|
||||||
|
initSystemLogger();
|
||||||
TraceLoggingRegister(g_hProvider);
|
TraceLoggingRegister(g_hProvider);
|
||||||
DLL_HANDLE = hInst;
|
DLL_HANDLE = hInst;
|
||||||
break;
|
break;
|
||||||
|
@ -256,7 +256,8 @@ void ReportVCMLogs(const filesystem::path& tmpDir, const filesystem::path& repor
|
|||||||
|
|
||||||
void ReportInstallerLogs(const filesystem::path& tmpDir, const filesystem::path& reportDir)
|
void ReportInstallerLogs(const filesystem::path& tmpDir, const filesystem::path& reportDir)
|
||||||
{
|
{
|
||||||
const char* logFilePrefix = "powertoys-bootstrapper-msi-";
|
const char* bootstrapperLogFilePrefix = "powertoys-bootstrapper-msi-";
|
||||||
|
const char* PTLogFilePrefix = "PowerToysMSIInstaller_";
|
||||||
|
|
||||||
for (auto& entry : directory_iterator{ tmpDir })
|
for (auto& entry : directory_iterator{ tmpDir })
|
||||||
{
|
{
|
||||||
@ -267,7 +268,7 @@ void ReportInstallerLogs(const filesystem::path& tmpDir, const filesystem::path&
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto fileName = entry.path().filename().string();
|
const auto fileName = entry.path().filename().string();
|
||||||
if (!fileName.starts_with(logFilePrefix))
|
if (!fileName.starts_with(bootstrapperLogFilePrefix) && !fileName.starts_with(PTLogFilePrefix))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user