mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
wix: install dotnet 3 after installation if needed (#2775)
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
#include <sddl.h>
|
||||
#include "version.h"
|
||||
|
||||
#include <wil/resource.h>
|
||||
|
||||
#pragma comment(lib, "advapi32.lib")
|
||||
#pragma comment(lib, "shlwapi.lib")
|
||||
|
||||
@@ -735,3 +737,64 @@ bool find_app_name_in_path(const std::wstring& where, const std::vector<std::wst
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::optional<std::string> exec_and_read_output(const std::wstring_view command, const DWORD timeout)
|
||||
{
|
||||
SECURITY_ATTRIBUTES saAttr{ sizeof(saAttr) };
|
||||
saAttr.bInheritHandle = true;
|
||||
|
||||
wil::unique_handle childStdoutRead;
|
||||
wil::unique_handle childStdoutWrite;
|
||||
if (!CreatePipe(&childStdoutRead, &childStdoutWrite, &saAttr, 0))
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (!SetHandleInformation(childStdoutRead.get(), HANDLE_FLAG_INHERIT, 0))
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
PROCESS_INFORMATION piProcInfo{};
|
||||
STARTUPINFOW siStartInfo{ sizeof(siStartInfo) };
|
||||
|
||||
siStartInfo.hStdError = childStdoutWrite.get();
|
||||
siStartInfo.hStdOutput = childStdoutWrite.get();
|
||||
siStartInfo.dwFlags |= STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
|
||||
siStartInfo.wShowWindow = SW_HIDE;
|
||||
|
||||
std::wstring cmdLine{ command };
|
||||
if (!CreateProcessW(nullptr,
|
||||
cmdLine.data(),
|
||||
nullptr,
|
||||
nullptr,
|
||||
true,
|
||||
NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE,
|
||||
nullptr,
|
||||
nullptr,
|
||||
&siStartInfo,
|
||||
&piProcInfo))
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
WaitForSingleObject(piProcInfo.hProcess, timeout);
|
||||
|
||||
childStdoutWrite.reset();
|
||||
CloseHandle(piProcInfo.hThread);
|
||||
|
||||
std::string childOutput;
|
||||
for (;;)
|
||||
{
|
||||
char buffer[4096];
|
||||
DWORD gotBytes = 0;
|
||||
if (!ReadFile(childStdoutRead.get(), buffer, sizeof(buffer), &gotBytes, nullptr) || !gotBytes)
|
||||
{
|
||||
break;
|
||||
}
|
||||
childOutput += std::string_view{ buffer, gotBytes };
|
||||
}
|
||||
|
||||
CloseHandle(piProcInfo.hProcess);
|
||||
return childOutput;
|
||||
}
|
||||
@@ -99,6 +99,8 @@ std::wstring get_resource_string(UINT resource_id, HINSTANCE instance, const wch
|
||||
// is added to the .cpp file.
|
||||
#define GET_RESOURCE_STRING(resource_id) get_resource_string(resource_id, reinterpret_cast<HINSTANCE>(&__ImageBase), L#resource_id)
|
||||
|
||||
std::optional<std::string> exec_and_read_output(const std::wstring_view command, const DWORD timeout = INFINITE);
|
||||
|
||||
// Helper class for various COM-related APIs, e.g working with security descriptors
|
||||
template<typename T>
|
||||
struct typed_storage
|
||||
|
||||
@@ -209,7 +209,7 @@ namespace updating
|
||||
return { std::move(path_str) };
|
||||
}
|
||||
|
||||
std::future<void> attempt_to_download_installer(const std::filesystem::path& destination, const winrt::Windows::Foundation::Uri& url)
|
||||
std::future<void> try_download_file(const std::filesystem::path& destination, const winrt::Windows::Foundation::Uri& url)
|
||||
{
|
||||
namespace storage = winrt::Windows::Storage;
|
||||
|
||||
@@ -218,6 +218,7 @@ namespace updating
|
||||
(void)response.EnsureSuccessStatusCode();
|
||||
auto msi_installer_file_stream = co_await storage::Streams::FileRandomAccessStream::OpenAsync(destination.c_str(), storage::FileAccessMode::ReadWrite, storage::StorageOpenOptions::AllowReadersAndWriters, storage::Streams::FileOpenDisposition::CreateAlways);
|
||||
co_await response.Content().WriteToStreamAsync(msi_installer_file_stream);
|
||||
msi_installer_file_stream.Close();
|
||||
}
|
||||
|
||||
std::future<void> try_autoupdate(const bool download_updates_automatically)
|
||||
@@ -244,7 +245,7 @@ namespace updating
|
||||
{
|
||||
try
|
||||
{
|
||||
co_await attempt_to_download_installer(installer_download_dst, new_version->msi_download_url);
|
||||
co_await try_download_file(installer_download_dst, new_version->msi_download_url);
|
||||
download_success = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
namespace updating
|
||||
{
|
||||
std::future<void> try_download_file(const std::filesystem::path& destination, const winrt::Windows::Foundation::Uri& url);
|
||||
|
||||
std::wstring get_msi_package_path();
|
||||
bool uninstall_msi_version(const std::wstring& package_path);
|
||||
bool offer_msi_uninstallation();
|
||||
|
||||
Reference in New Issue
Block a user