[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:
Stefan Markovic 2023-02-22 10:06:59 +01:00 committed by GitHub
parent aceffe3212
commit 47999199e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 52 deletions

View File

@ -40,7 +40,6 @@ ALPHATYPE
Altdown
alwaysontop
amd
AMF
AModifier
AMPROPERTY
AMPROPSETID
@ -206,7 +205,6 @@ CHILDACTIVATE
CHILDWINDOW
Choibalsan
chrdavis
chromaticities
Chrzan
cht
Chukotka
@ -393,7 +391,6 @@ Deondre
depersist
deprioritized
depsfileslistspath
depsjsonpath
deref
DESKTOPABSOLUTEEDITING
DESKTOPABSOLUTEPARSING
@ -931,7 +928,6 @@ logconsole
logfile
LOGFONT
LOGFONTW
LOGMSG
logon
LOGPIXELSX
LOn
@ -2004,7 +2000,7 @@ WANTPALM
wbem
wbemuuid
WBounds
wca
Wca
wcautil
WCE
wcex

View File

@ -177,9 +177,7 @@
<Custom Action="DeleteWinAppSDKHardlinks" Before="RemoveFiles">
Installed AND (REMOVE="ALL")
</Custom>
<Custom Action="DeletePTInteropHardlinks" Before="RemoveFiles">
Installed AND (REMOVE="ALL")
</Custom>
<Custom Action="DeletePTInteropHardlinks" Before="CreatePTInteropHardlinks" />
<Custom Action="DeleteDotnetRuntimeHardlinks" Before="RemoveFiles">
Installed AND (REMOVE="ALL")

View File

@ -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_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)
{
DWORD len = 0;
@ -70,7 +52,6 @@ LExit:
}
UINT __stdcall ApplyModulesRegistryChangeSetsCA(MSIHANDLE hInstall)
{
initSystemLogger();
HRESULT hr = S_OK;
UINT er = ERROR_SUCCESS;
std::wstring installationFolder;
@ -85,14 +66,14 @@ UINT __stdcall ApplyModulesRegistryChangeSetsCA(MSIHANDLE hInstall)
{
if (!changeSet.apply())
{
WcaLog(LOGMSG_STANDARD, "Couldn't apply registry changeSet");
Logger::error(L"Couldn't apply registry changeSet");
failedToApply = true;
}
}
if (!failedToApply)
{
WcaLog(LOGMSG_STANDARD, "All registry changeSets applied successfully");
Logger::info(L"All registry changeSets applied successfully");
}
LExit:
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
@ -101,7 +82,6 @@ LExit:
UINT __stdcall UnApplyModulesRegistryChangeSetsCA(MSIHANDLE hInstall)
{
initSystemLogger();
HRESULT hr = S_OK;
UINT er = ERROR_SUCCESS;
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))
{
WcaLog(LOGMSG_STANDARD, "Extracted MSIX");
Logger::info(L"Extracted MSIX");
// TODO: Use to activate embedded MSIX
const auto msix_path = std::filesystem::temp_directory_path() / "hello_package.msix";
if (!msix->saveAsFile(msix_path))
{
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::Foundation;
@ -150,7 +130,7 @@ UINT __stdcall InstallEmbeddedMSIXCA(MSIHANDLE hInstall)
ExitOnFailure(hr, "Failed to AddPackage");
}
WcaLog(LOGMSG_STANDARD, "MSIX[s] were installed!");
Logger::info(L"MSIX[s] were installed!");
}
else
{
@ -181,11 +161,11 @@ UINT __stdcall UninstallEmbeddedMSIXCA(MSIHANDLE hInstall)
auto result = pm.RemovePackageAsync(p.Id().FullName()).get();
if (result)
{
WcaLog(LOGMSG_STANDARD, "MSIX was uninstalled!");
Logger::info(L"MSIX was uninstalled!");
}
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");
ExitOnFailure(hr, "Failed to initialize");
WcaLog(LOGMSG_STANDARD, "Initialized.");
Logger::info(L"CreateScheduledTaskCA Initialized.");
// ------------------------------------------------------
// 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, username);
WcaLog(LOGMSG_STANDARD, "Current user detected: %ls", username_domain);
Logger::info(L"Current user detected: {}", username_domain);
// Task Name.
wstrTaskName = L"Autorun for ";
@ -286,7 +266,7 @@ UINT __stdcall CreateScheduledTaskCA(MSIHANDLE hInstall)
pRootFolder->Release();
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.
@ -334,7 +314,7 @@ UINT __stdcall CreateScheduledTaskCA(MSIHANDLE hInstall)
hr = pLogonTrigger->put_Id(_bstr_t(L"Trigger1"));
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.
@ -342,7 +322,7 @@ UINT __stdcall CreateScheduledTaskCA(MSIHANDLE hInstall)
hr = pLogonTrigger->put_Delay(_bstr_t(L"PT03S"));
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.
@ -383,19 +363,19 @@ UINT __stdcall CreateScheduledTaskCA(MSIHANDLE hInstall)
hr = pPrincipal->put_Id(_bstr_t(L"Principal1"));
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));
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);
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.
@ -419,7 +399,7 @@ UINT __stdcall CreateScheduledTaskCA(MSIHANDLE hInstall)
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:
ReleaseStr(wszExecutablePath);
@ -480,7 +460,7 @@ UINT __stdcall RemoveScheduledTasksCA(MSIHANDLE hInstall)
hr = WcaInitialize(hInstall, "RemoveScheduledTasksCA");
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.
// It couldn't be done in the DLL, anyway.
@ -503,7 +483,7 @@ UINT __stdcall RemoveScheduledTasksCA(MSIHANDLE hInstall)
if (FAILED(hr))
{
// 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;
ExitFunction();
}
@ -529,19 +509,19 @@ UINT __stdcall RemoveScheduledTasksCA(MSIHANDLE hInstall)
hr = pTaskFolder->DeleteTask(taskName, 0);
if (FAILED(hr))
{
WcaLogError(hr, "Cannot delete the '%S' task: %x", taskName, hr);
Logger::error(L"Cannot delete the {} task: {}", taskName, hr);
}
SysFreeString(taskName);
}
else
{
WcaLogError(hr, "Cannot get the registered task name: %x", hr);
Logger::error(L"Cannot get the registered task name: {}", hr);
}
pRegisteredTask->Release();
}
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();
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:
if (pService)
@ -1400,6 +1380,20 @@ UINT __stdcall TerminateProcessesCA(MSIHANDLE hInstall)
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.
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:
WcaGlobalInitialize(hInst);
initSystemLogger();
TraceLoggingRegister(g_hProvider);
DLL_HANDLE = hInst;
break;

View File

@ -256,7 +256,8 @@ void ReportVCMLogs(const filesystem::path& tmpDir, const filesystem::path& repor
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 })
{
@ -267,7 +268,7 @@ void ReportInstallerLogs(const filesystem::path& tmpDir, const filesystem::path&
}
const auto fileName = entry.path().filename().string();
if (!fileName.starts_with(logFilePrefix))
if (!fileName.starts_with(bootstrapperLogFilePrefix) && !fileName.starts_with(PTLogFilePrefix))
{
continue;
}