2020-08-05 22:20:50 +08:00
|
|
|
#include "pch.h"
|
2020-09-10 21:57:16 +08:00
|
|
|
#include "Generated Files/resource.h"
|
2020-07-28 00:53:29 +08:00
|
|
|
|
|
|
|
#include <common/common.h>
|
|
|
|
#include <common/notifications.h>
|
|
|
|
#include <common/RcResource.h>
|
|
|
|
#include <common/updating/updating.h>
|
|
|
|
#include <common/updating/dotnet_installation.h>
|
|
|
|
#include <common/version.h>
|
|
|
|
#include <common/appMutex.h>
|
|
|
|
#include <common/processApi.h>
|
|
|
|
|
|
|
|
#include <runner/action_runner_utils.h>
|
|
|
|
|
|
|
|
extern "C" IMAGE_DOS_HEADER __ImageBase;
|
|
|
|
|
2020-10-14 22:36:03 +08:00
|
|
|
#define STR_HELPER(x) #x
|
|
|
|
#define STR(x) STR_HELPER(x)
|
2020-07-28 00:53:29 +08:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
const wchar_t APPLICATION_ID[] = L"PowerToysInstaller";
|
|
|
|
const wchar_t TOAST_TAG[] = L"PowerToysInstallerProgress";
|
2020-10-14 22:36:03 +08:00
|
|
|
const char LOG_FILENAME[] = "powertoys-bootstrapper-" STR(VERSION_MAJOR) "." STR(VERSION_MINOR) "." STR(VERSION_REVISION) ".log";
|
|
|
|
const char MSI_LOG_FILENAME[] = "powertoys-bootstrapper-msi-" STR(VERSION_MAJOR) "." STR(VERSION_MINOR) "." STR(VERSION_REVISION) ".log";
|
|
|
|
|
2020-07-28 00:53:29 +08:00
|
|
|
}
|
2020-10-14 22:36:03 +08:00
|
|
|
#undef STR
|
|
|
|
#undef STR_HELPER
|
2020-07-28 00:53:29 +08:00
|
|
|
|
|
|
|
namespace localized_strings
|
|
|
|
{
|
|
|
|
const wchar_t INSTALLER_EXTRACT_ERROR[] = L"Couldn't extract MSI installer!";
|
|
|
|
const wchar_t TOAST_TITLE[] = L"PowerToys Installation";
|
|
|
|
const wchar_t EXTRACTING_INSTALLER[] = L"Extracting PowerToys MSI...";
|
|
|
|
const wchar_t UNINSTALLING_PREVIOUS_VERSION[] = L"Uninstalling previous PowerToys version...";
|
|
|
|
const wchar_t UNINSTALL_PREVIOUS_VERSION_ERROR[] = L"Couldn't uninstall previous PowerToys version!";
|
|
|
|
const wchar_t INSTALLING_DOTNET[] = L"Installing dotnet...";
|
|
|
|
const wchar_t DOTNET_INSTALL_ERROR[] = L"Couldn't install dotnet!";
|
|
|
|
const wchar_t INSTALLING_NEW_VERSION[] = L"Installing new PowerToys version...";
|
|
|
|
const wchar_t NEW_VERSION_INSTALLATION_DONE[] = L"PowerToys installation complete!";
|
|
|
|
const wchar_t NEW_VERSION_INSTALLATION_ERROR[] = L"Couldn't install new PowerToys version.";
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
|
|
|
std::optional<fs::path> extractEmbeddedInstaller()
|
|
|
|
{
|
|
|
|
auto executableRes = RcResource::create(IDR_BIN_MSIINSTALLER, L"BIN");
|
|
|
|
if (!executableRes)
|
|
|
|
{
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
auto installerPath = fs::temp_directory_path() / L"PowerToysBootstrappedInstaller-" PRODUCT_VERSION_STRING L".msi";
|
|
|
|
return executableRes->saveAsFile(installerPath) ? std::make_optional(std::move(installerPath)) : std::nullopt;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<fs::path> extractIcon()
|
|
|
|
{
|
|
|
|
auto iconRes = RcResource::create(IDR_BIN_ICON, L"BIN");
|
|
|
|
if (!iconRes)
|
|
|
|
{
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
auto icoPath = fs::temp_directory_path() / L"PowerToysBootstrappedInstaller.ico";
|
|
|
|
return iconRes->saveAsFile(icoPath) ? std::make_optional(std::move(icoPath)) : std::nullopt;
|
|
|
|
}
|
|
|
|
|
2020-10-14 22:36:03 +08:00
|
|
|
void setup_log(const spdlog::level::level_enum severity)
|
2020-08-07 17:00:14 +08:00
|
|
|
{
|
2020-10-14 22:36:03 +08:00
|
|
|
try
|
2020-08-07 17:00:14 +08:00
|
|
|
{
|
2020-10-14 22:36:03 +08:00
|
|
|
std::shared_ptr<spdlog::logger> logger;
|
|
|
|
if (severity != spdlog::level::off)
|
2020-08-07 17:00:14 +08:00
|
|
|
{
|
2020-10-14 22:36:03 +08:00
|
|
|
logger = spdlog::basic_logger_mt("file", LOG_FILENAME);
|
|
|
|
|
|
|
|
std::error_code _;
|
|
|
|
const DWORD msiSev = severity == spdlog::level::debug ? INSTALLLOGMODE_VERBOSE : INSTALLLOGMODE_ERROR;
|
|
|
|
const auto msiLogPath = fs::current_path(_) / MSI_LOG_FILENAME;
|
|
|
|
MsiEnableLogW(msiSev, msiLogPath.c_str(), INSTALLLOGATTRIBUTES_APPEND);
|
2020-08-07 17:00:14 +08:00
|
|
|
}
|
2020-10-14 22:36:03 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
logger = spdlog::null_logger_mt("null");
|
|
|
|
}
|
|
|
|
logger->set_pattern("[%L][%d-%m-%C-%T] %v");
|
|
|
|
logger->set_level(severity);
|
|
|
|
spdlog::set_default_logger(std::move(logger));
|
|
|
|
spdlog::set_level(severity);
|
|
|
|
spdlog::flush_every(std::chrono::seconds(5));
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2020-08-07 17:00:14 +08:00
|
|
|
}
|
|
|
|
}
|
2020-09-07 21:42:15 +08:00
|
|
|
|
|
|
|
int bootstrapper()
|
2020-07-28 00:53:29 +08:00
|
|
|
{
|
|
|
|
using namespace localized_strings;
|
|
|
|
winrt::init_apartment();
|
2020-10-14 22:36:03 +08:00
|
|
|
cxxopts::Options options{ "PowerToysBootstrapper" };
|
|
|
|
// clang-format off
|
|
|
|
options.add_options()
|
|
|
|
("h,help", "Show help")
|
|
|
|
("no_full_ui", "Use reduced UI for MSI")
|
|
|
|
("s,silent", "Suppress MSI UI and notifications")
|
|
|
|
("no_start_pt", "Do not launch PowerToys after the installation is complete")
|
|
|
|
("skip_dotnet_install", "Skip dotnet 3.X installation even if it's not detected")
|
|
|
|
("log_level", "Log level. Possible values: off|debug|error", cxxopts::value<std::string>()->default_value("off"));
|
|
|
|
// clang-format on
|
|
|
|
cxxopts::ParseResult cmdArgs;
|
|
|
|
options.allow_unrecognised_options();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
cmdArgs = options.parse(__argc, const_cast<const char**>(__argv));
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
const bool showHelp = cmdArgs["help"].as<bool>();
|
|
|
|
const bool noFullUI = cmdArgs["no_full_ui"].as<bool>();
|
|
|
|
const bool silent = cmdArgs["silent"].as<bool>();
|
|
|
|
const bool skipDotnetInstall = cmdArgs["skip_dotnet_install"].as<bool>();
|
|
|
|
const bool noStartPT = cmdArgs["no_start_pt"].as<bool>();
|
|
|
|
const auto logLevel = cmdArgs["log_level"].as<std::string>();
|
|
|
|
spdlog::level::level_enum severity = spdlog::level::off;
|
2020-07-28 00:53:29 +08:00
|
|
|
|
2020-10-14 22:36:03 +08:00
|
|
|
if (logLevel == "debug")
|
2020-08-26 18:46:19 +08:00
|
|
|
{
|
2020-10-14 22:36:03 +08:00
|
|
|
severity = spdlog::level::debug;
|
|
|
|
}
|
|
|
|
else if (logLevel == "error")
|
|
|
|
{
|
|
|
|
severity = spdlog::level::err;
|
|
|
|
}
|
|
|
|
setup_log(severity);
|
|
|
|
if (showHelp)
|
|
|
|
{
|
|
|
|
std::ostringstream helpMsg;
|
|
|
|
helpMsg << options.help();
|
|
|
|
MessageBoxA(nullptr, helpMsg.str().c_str(), "Help", MB_OK | MB_ICONINFORMATION);
|
2020-08-26 18:46:19 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::debug("PowerToys Bootstrapper is launched!\nnoFullUI: {}\nsilent: {}\nno_start_pt: {}\nskip_dotnet_install: {}\nlog_level: {}", noFullUI, silent, noStartPT, skipDotnetInstall, logLevel);
|
|
|
|
|
|
|
|
if (!noFullUI)
|
2020-08-07 17:00:14 +08:00
|
|
|
{
|
|
|
|
MsiSetInternalUI(INSTALLUILEVEL_FULL, nullptr);
|
|
|
|
}
|
2020-10-14 22:36:03 +08:00
|
|
|
if (silent)
|
2020-08-07 17:00:14 +08:00
|
|
|
{
|
|
|
|
if (is_process_elevated())
|
|
|
|
{
|
|
|
|
MsiSetInternalUI(INSTALLUILEVEL_NONE, nullptr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::debug("MSI doesn't support silent mode without elevation => restarting elevated");
|
|
|
|
// MSI fails to run in silent mode due to a suppressed UAC w/o elevation,
|
|
|
|
// so we restart ourselves elevated with the same args
|
2020-08-07 17:00:14 +08:00
|
|
|
std::wstring params;
|
2020-10-14 22:36:03 +08:00
|
|
|
int nCmdArgs = 0;
|
|
|
|
LPWSTR* argList = CommandLineToArgvW(GetCommandLineW(), &nCmdArgs);
|
2020-08-07 17:00:14 +08:00
|
|
|
for (int i = 1; i < nCmdArgs; ++i)
|
|
|
|
{
|
|
|
|
params += argList[i];
|
|
|
|
if (i != nCmdArgs - 1)
|
|
|
|
{
|
|
|
|
params += L' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const auto processHandle = run_elevated(argList[0], params.c_str());
|
|
|
|
if (!processHandle)
|
|
|
|
{
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::error("Couldn't restart elevated to enable silent mode! ({})", GetLastError());
|
2020-08-07 17:00:14 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (WaitForSingleObject(processHandle, 3600000) == WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
DWORD exitCode = 0;
|
|
|
|
GetExitCodeProcess(processHandle, &exitCode);
|
|
|
|
return exitCode;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::error("Elevated setup process timed out after 60m => using basic MSI UI ({})", GetLastError());
|
2020-08-07 17:00:14 +08:00
|
|
|
// Couldn't install using the completely silent mode in an hour, use basic UI.
|
|
|
|
TerminateProcess(processHandle, 0);
|
|
|
|
MsiSetInternalUI(INSTALLUILEVEL_BASIC, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-28 00:53:29 +08:00
|
|
|
// Try killing PowerToys and prevent future processes launch
|
|
|
|
for (auto& handle : getProcessHandlesByName(L"PowerToys.exe", PROCESS_TERMINATE))
|
|
|
|
{
|
|
|
|
TerminateProcess(handle.get(), 0);
|
|
|
|
}
|
|
|
|
auto powerToysMutex = createAppMutex(POWERTOYS_MSI_MUTEX_NAME);
|
|
|
|
|
|
|
|
auto instanceMutex = createAppMutex(POWERTOYS_BOOTSTRAPPER_MUTEX_NAME);
|
|
|
|
if (!instanceMutex)
|
|
|
|
{
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::error("Couldn't acquire PowerToys global mutex. That means setup couldn't kill PowerToys.exe process");
|
2020-07-28 00:53:29 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2020-08-04 16:12:49 +08:00
|
|
|
notifications::override_application_id(APPLICATION_ID);
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::debug("Extracting icon for toast notifications");
|
2020-07-28 00:53:29 +08:00
|
|
|
fs::path iconPath{ L"C:\\" };
|
|
|
|
if (auto extractedIcon = extractIcon())
|
|
|
|
{
|
|
|
|
iconPath = std::move(*extractedIcon);
|
|
|
|
}
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::debug("Registering app id for toast notifications");
|
2020-07-28 00:53:29 +08:00
|
|
|
notifications::register_application_id(TOAST_TITLE, iconPath.c_str());
|
|
|
|
|
|
|
|
auto removeShortcut = wil::scope_exit([&] {
|
|
|
|
notifications::unregister_application_id();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Check if there's a newer version installed, and launch its installer if so.
|
|
|
|
const VersionHelper myVersion(VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION);
|
|
|
|
if (const auto installedVersion = updating::get_installed_powertoys_version(); installedVersion && *installedVersion >= myVersion)
|
|
|
|
{
|
|
|
|
auto msi_path = updating::get_msi_package_path();
|
|
|
|
if (!msi_path.empty())
|
|
|
|
{
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::error(L"Detected a newer {} version => launching its installer", installedVersion->toWstring());
|
2020-07-28 00:53:29 +08:00
|
|
|
MsiInstallProductW(msi_path.c_str(), nullptr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::mutex progressLock;
|
|
|
|
notifications::progress_bar_params progressParams;
|
|
|
|
progressParams.progress = 0.0f;
|
|
|
|
progressParams.progress_title = EXTRACTING_INSTALLER;
|
|
|
|
notifications::toast_params params{ TOAST_TAG, false, std::move(progressParams) };
|
2020-10-14 22:36:03 +08:00
|
|
|
if (!silent)
|
2020-08-07 17:00:14 +08:00
|
|
|
{
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::debug("Launching progress toast notification");
|
2020-08-07 17:00:14 +08:00
|
|
|
notifications::show_toast_with_activations({}, TOAST_TITLE, {}, {}, std::move(params));
|
|
|
|
}
|
2020-07-28 00:53:29 +08:00
|
|
|
|
|
|
|
auto processToasts = wil::scope_exit([&] {
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::debug("Processing HWND messages for 2s so toast have time to show up");
|
2020-07-28 00:53:29 +08:00
|
|
|
run_message_loop(true, 2);
|
|
|
|
});
|
|
|
|
|
2020-10-14 22:36:03 +08:00
|
|
|
if (!silent)
|
2020-08-07 17:00:14 +08:00
|
|
|
{
|
|
|
|
// Worker thread to periodically increase progress and keep the progress toast from losing focus
|
|
|
|
std::thread{ [&] {
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::debug("Started worker thread for progress bar update");
|
2020-08-07 17:00:14 +08:00
|
|
|
for (;; Sleep(3000))
|
2020-07-28 00:53:29 +08:00
|
|
|
{
|
2020-08-07 17:00:14 +08:00
|
|
|
std::scoped_lock lock{ progressLock };
|
|
|
|
if (progressParams.progress == 1.f)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2020-09-07 21:42:15 +08:00
|
|
|
progressParams.progress = std::min(0.99f, progressParams.progress + 0.001f);
|
2020-08-07 17:00:14 +08:00
|
|
|
notifications::update_progress_bar_toast(TOAST_TAG, progressParams);
|
2020-07-28 00:53:29 +08:00
|
|
|
}
|
2020-08-07 17:00:14 +08:00
|
|
|
} }.detach();
|
|
|
|
}
|
2020-07-28 00:53:29 +08:00
|
|
|
|
|
|
|
auto updateProgressBar = [&](const float value, const wchar_t* title) {
|
2020-10-14 22:36:03 +08:00
|
|
|
if (silent)
|
2020-08-07 17:00:14 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2020-07-28 00:53:29 +08:00
|
|
|
std::scoped_lock lock{ progressLock };
|
|
|
|
progressParams.progress = value;
|
|
|
|
progressParams.progress_title = title;
|
|
|
|
notifications::update_progress_bar_toast(TOAST_TAG, progressParams);
|
|
|
|
};
|
|
|
|
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::debug("Extracting embedded MSI installer");
|
2020-07-28 00:53:29 +08:00
|
|
|
const auto installerPath = extractEmbeddedInstaller();
|
|
|
|
if (!installerPath)
|
|
|
|
{
|
2020-10-14 22:36:03 +08:00
|
|
|
if (!silent)
|
2020-08-07 17:00:14 +08:00
|
|
|
{
|
|
|
|
notifications::show_toast(INSTALLER_EXTRACT_ERROR, TOAST_TITLE);
|
|
|
|
}
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::error("Couldn't install the MSI installer ({})", GetLastError());
|
2020-07-28 00:53:29 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
auto removeExtractedInstaller = wil::scope_exit([&] {
|
|
|
|
std::error_code _;
|
|
|
|
fs::remove(*installerPath, _);
|
|
|
|
});
|
|
|
|
|
|
|
|
updateProgressBar(.25f, UNINSTALLING_PREVIOUS_VERSION);
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::debug("Acquiring existing MSI package path");
|
2020-07-28 00:53:29 +08:00
|
|
|
const auto package_path = updating::get_msi_package_path();
|
2020-10-14 22:36:03 +08:00
|
|
|
if (!package_path.empty())
|
|
|
|
{
|
|
|
|
spdlog::debug(L"Existing MSI package path: {}", package_path);
|
|
|
|
}
|
|
|
|
else
|
2020-07-28 00:53:29 +08:00
|
|
|
{
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::debug("Existing MSI package path not found");
|
|
|
|
}
|
|
|
|
if (!package_path.empty() && !updating::uninstall_msi_version(package_path) && !silent)
|
|
|
|
{
|
|
|
|
spdlog::error("Couldn't install the existing MSI package ({})", GetLastError());
|
2020-07-28 00:53:29 +08:00
|
|
|
notifications::show_toast(UNINSTALL_PREVIOUS_VERSION_ERROR, TOAST_TITLE);
|
|
|
|
}
|
2020-10-14 22:36:03 +08:00
|
|
|
const bool installDotnet = !skipDotnetInstall;
|
2020-08-26 18:46:19 +08:00
|
|
|
if (installDotnet)
|
|
|
|
{
|
|
|
|
updateProgressBar(.5f, INSTALLING_DOTNET);
|
|
|
|
}
|
2020-09-07 21:42:15 +08:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-10-14 22:36:03 +08:00
|
|
|
if (installDotnet)
|
2020-09-07 21:42:15 +08:00
|
|
|
{
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::debug("Detecting if dotnet is installed");
|
|
|
|
const bool dotnetInstalled = updating::dotnet_is_installed();
|
|
|
|
spdlog::debug("Dotnet is installed: {}", dotnetInstalled);
|
|
|
|
if (!dotnetInstalled &&
|
|
|
|
!updating::install_dotnet(silent) &&
|
|
|
|
!silent)
|
|
|
|
{
|
|
|
|
notifications::show_toast(DOTNET_INSTALL_ERROR, TOAST_TITLE);
|
|
|
|
}
|
2020-09-07 21:42:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (...)
|
2020-07-28 00:53:29 +08:00
|
|
|
{
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::error("Unknown exception during dotnet installation");
|
2020-09-07 21:42:15 +08:00
|
|
|
MessageBoxW(nullptr, L".NET Core installation", L"Unknown exception encountered!", MB_OK | MB_ICONERROR);
|
2020-07-28 00:53:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
updateProgressBar(.75f, INSTALLING_NEW_VERSION);
|
|
|
|
|
2020-08-26 18:46:19 +08:00
|
|
|
// Always skip dotnet install, because we should've installed it from here earlier
|
|
|
|
std::wstring msiProps = L"SKIPDOTNETINSTALL=1 ";
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::debug("Launching MSI installation for new package {}", installerPath->string());
|
2020-08-26 18:46:19 +08:00
|
|
|
const bool installationDone = MsiInstallProductW(installerPath->c_str(), msiProps.c_str()) == ERROR_SUCCESS;
|
2020-07-28 00:53:29 +08:00
|
|
|
updateProgressBar(1.f, installationDone ? NEW_VERSION_INSTALLATION_DONE : NEW_VERSION_INSTALLATION_ERROR);
|
|
|
|
if (!installationDone)
|
|
|
|
{
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::error("Couldn't install new MSI package ({})", GetLastError());
|
2020-07-28 00:53:29 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::debug("Installation completed");
|
2020-08-07 17:00:14 +08:00
|
|
|
|
2020-10-14 22:36:03 +08:00
|
|
|
if (!noStartPT && !silent)
|
2020-07-28 00:53:29 +08:00
|
|
|
{
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::debug("Starting the newly installed PowerToys.exe");
|
2020-08-07 17:00:14 +08:00
|
|
|
auto newPTPath = updating::get_msi_package_installed_path();
|
|
|
|
if (!newPTPath)
|
|
|
|
{
|
2020-10-14 22:36:03 +08:00
|
|
|
spdlog::error("Couldn't determine new MSI package install location ({})", GetLastError());
|
2020-08-07 17:00:14 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2020-07-28 00:53:29 +08:00
|
|
|
*newPTPath += L"\\PowerToys.exe";
|
|
|
|
SHELLEXECUTEINFOW sei{ sizeof(sei) };
|
|
|
|
sei.fMask = { SEE_MASK_FLAG_NO_UI | SEE_MASK_NOASYNC | SEE_MASK_NO_CONSOLE };
|
|
|
|
sei.lpFile = newPTPath->c_str();
|
|
|
|
sei.nShow = SW_SHOWNORMAL;
|
|
|
|
ShellExecuteExW(&sei);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-09-07 21:42:15 +08:00
|
|
|
|
|
|
|
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return bootstrapper();
|
|
|
|
}
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
{
|
|
|
|
MessageBoxA(nullptr, ex.what(), "Unhandled stdexception encountered!", MB_OK | MB_ICONERROR);
|
|
|
|
}
|
|
|
|
catch (winrt::hresult_error const& ex)
|
|
|
|
{
|
|
|
|
winrt::hstring message = ex.message();
|
|
|
|
MessageBoxW(nullptr, message.c_str(), L"Unhandled winrt exception encountered!", MB_OK | MB_ICONERROR);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
auto lastErrorMessage = get_last_error_message(GetLastError());
|
|
|
|
std::wstring message = lastErrorMessage ? std::move(*lastErrorMessage) : L"";
|
|
|
|
MessageBoxW(nullptr, message.c_str(), L"Unknown exception encountered!", MB_OK | MB_ICONERROR);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|