mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 10:16:24 +02:00
Runner: autoupdate should prefer .exe installer instead of .msi (#4216)
This commit is contained in:
@@ -56,18 +56,11 @@ std::optional<fs::path> copy_self_to_temp_dir()
|
||||
return std::move(dst_path);
|
||||
}
|
||||
|
||||
bool install_new_version_stage_1(const bool must_restart = false)
|
||||
bool install_new_version_stage_1(const std::wstring_view installer_filename, const bool must_restart = false)
|
||||
{
|
||||
std::optional<fs::path> installer;
|
||||
for (auto path : fs::directory_iterator{ updating::get_pending_updates_path() })
|
||||
{
|
||||
if (path.path().native().find(updating::installer_filename_pattern) != std::wstring::npos)
|
||||
{
|
||||
installer.emplace(std::move(path));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!installer)
|
||||
const fs::path installer{ updating::get_pending_updates_path() / installer_filename };
|
||||
|
||||
if (!fs::is_regular_file(installer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -84,7 +77,7 @@ bool install_new_version_stage_1(const bool must_restart = false)
|
||||
|
||||
std::wstring arguments{ UPDATE_NOW_LAUNCH_STAGE2_CMDARG };
|
||||
arguments += L" \"";
|
||||
arguments += installer->c_str();
|
||||
arguments += installer.c_str();
|
||||
arguments += L"\" \"";
|
||||
arguments += get_module_folderpath();
|
||||
arguments += L"\" ";
|
||||
@@ -103,15 +96,35 @@ bool install_new_version_stage_1(const bool must_restart = false)
|
||||
}
|
||||
}
|
||||
|
||||
bool install_new_version_stage_2(std::wstring_view installer_path, std::wstring_view install_path, const bool launch_powertoys)
|
||||
bool install_new_version_stage_2(std::wstring installer_path, std::wstring_view install_path, const bool launch_powertoys)
|
||||
{
|
||||
if (MsiInstallProductW(installer_path.data(), nullptr) != ERROR_SUCCESS)
|
||||
std::transform(begin(installer_path), end(installer_path), begin(installer_path), ::towlower);
|
||||
|
||||
bool success = true;
|
||||
|
||||
if (installer_path.ends_with(L".msi"))
|
||||
{
|
||||
return false;
|
||||
success = MsiInstallProductW(installer_path.data(), nullptr) == ERROR_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If it's not .msi, then it's our .exe installer
|
||||
SHELLEXECUTEINFOW sei{ sizeof(sei) };
|
||||
sei.fMask = { SEE_MASK_FLAG_NO_UI | SEE_MASK_NOASYNC };
|
||||
sei.lpFile = installer_path.c_str();
|
||||
sei.nShow = SW_SHOWNORMAL;
|
||||
|
||||
success = ShellExecuteExW(&sei) == TRUE;
|
||||
}
|
||||
|
||||
std::error_code _;
|
||||
fs::remove(installer_path, _);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (launch_powertoys)
|
||||
{
|
||||
std::wstring new_pt_path{ install_path };
|
||||
@@ -230,7 +243,7 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
||||
}
|
||||
|
||||
run_same_elevation(target.data(), params, pidBuffer);
|
||||
|
||||
|
||||
// cleanup
|
||||
if (!pidFile.empty())
|
||||
{
|
||||
@@ -261,11 +274,13 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
||||
}
|
||||
else if (action == UPDATE_NOW_LAUNCH_STAGE1_CMDARG)
|
||||
{
|
||||
return !install_new_version_stage_1();
|
||||
std::wstring_view installerFilename{ args[2] };
|
||||
return !install_new_version_stage_1(installerFilename);
|
||||
}
|
||||
else if (action == UPDATE_NOW_LAUNCH_STAGE1_START_PT_CMDARG)
|
||||
{
|
||||
return !install_new_version_stage_1(true);
|
||||
std::wstring_view installerFilename{ args[2] };
|
||||
return !install_new_version_stage_1(installerFilename, true);
|
||||
}
|
||||
else if (action == UPDATE_NOW_LAUNCH_STAGE2_CMDARG)
|
||||
{
|
||||
@@ -274,4 +289,4 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user