mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
[Setup] Add logging for registry changes + add logger for powerpreview
- cleanup logger project + remove SettingsAPI dependency
This commit is contained in:
committed by
Andrey Nekrasov
parent
d036740c8b
commit
bef119b03b
@@ -2,6 +2,9 @@
|
||||
#include "resource.h"
|
||||
#include <ProjectTelemetry.h>
|
||||
|
||||
#include <spdlog/sinks/base_sink.h>
|
||||
|
||||
#include "../../src/common/logger/logger.h"
|
||||
#include "../../src/common/utils/MsiUtils.h"
|
||||
#include "../../src/common/utils/modulesRegistry.h"
|
||||
#include "../../src/common/updating/installer.h"
|
||||
@@ -26,6 +29,24 @@ 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;
|
||||
@@ -34,7 +55,7 @@ HRESULT getInstallFolder(MSIHANDLE hInstall, std::wstring& installationDir)
|
||||
len += 1;
|
||||
installationDir.resize(len);
|
||||
HRESULT hr = MsiGetPropertyW(hInstall, L"CustomActionData", installationDir.data(), &len);
|
||||
if(installationDir.length())
|
||||
if (installationDir.length())
|
||||
{
|
||||
installationDir.resize(installationDir.length() - 1);
|
||||
}
|
||||
@@ -44,24 +65,30 @@ LExit:
|
||||
}
|
||||
UINT __stdcall ApplyModulesRegistryChangeSetsCA(MSIHANDLE hInstall)
|
||||
{
|
||||
initSystemLogger();
|
||||
HRESULT hr = S_OK;
|
||||
UINT er = ERROR_SUCCESS;
|
||||
std::wstring installationFolder;
|
||||
bool failedToApply = false;
|
||||
|
||||
hr = WcaInitialize(hInstall, "ApplyModulesRegistryChangeSets");
|
||||
ExitOnFailure(hr, "Failed to initialize");
|
||||
hr = getInstallFolder(hInstall, installationFolder);
|
||||
ExitOnFailure(hr, "Failed to get installFolder.");
|
||||
|
||||
for (const auto& changeSet : getAllModulesChangeSets(installationFolder, false))
|
||||
{
|
||||
if (!changeSet.apply())
|
||||
{
|
||||
WcaLog(LOGMSG_STANDARD, "Couldn't apply registry changeSet");
|
||||
failedToApply = true;
|
||||
}
|
||||
}
|
||||
|
||||
ExitOnFailure(hr, "Failed to extract msix");
|
||||
|
||||
if (!failedToApply)
|
||||
{
|
||||
WcaLog(LOGMSG_STANDARD, "All registry changeSets applied successfully");
|
||||
}
|
||||
LExit:
|
||||
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
|
||||
return WcaFinalize(er);
|
||||
@@ -69,6 +96,7 @@ LExit:
|
||||
|
||||
UINT __stdcall UnApplyModulesRegistryChangeSetsCA(MSIHANDLE hInstall)
|
||||
{
|
||||
initSystemLogger();
|
||||
HRESULT hr = S_OK;
|
||||
UINT er = ERROR_SUCCESS;
|
||||
std::wstring installationFolder;
|
||||
|
||||
Reference in New Issue
Block a user