Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Setup] Add support for installing both dotnet 3 and 5 #12306

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@ namespace fs = std::filesystem;

namespace updating
{
constexpr size_t REQUIRED_MINIMAL_PATCH = 15;

bool dotnet_is_installed()
bool dotnet_is_installed(const size_t major, const size_t minor, const size_t requiredMinimalPatch)
{
auto runtimes = exec_and_read_output(LR"(dotnet --list-runtimes)");
if (!runtimes)
{
return false;
}
std::regex dotnet3_1_x{ R"(Microsoft\.WindowsDesktop\.App\s3\.1\.(\d+))" };
std::array<char, 512> regexBuffer;
sprintf_s(regexBuffer.data(),
regexBuffer.size(),
R"(Microsoft\.WindowsDesktop\.App\s%zu\.%zu\.(\d+))",
major,
minor);
std::regex dotnetRegex{ regexBuffer.data() };

size_t latestPatchInstalled = 0;
using rexit = std::sregex_iterator;
for (auto it = rexit{ begin(*runtimes), end(*runtimes), dotnet3_1_x }; it != rexit{}; ++it)
for (auto it = rexit{ begin(*runtimes), end(*runtimes), dotnetRegex }; it != rexit{}; ++it)
{
if (!it->ready() || it->size() < 2)
{
Expand All @@ -40,16 +44,15 @@ namespace updating
latestPatchInstalled = std::max(patch, latestPatchInstalled);
}
}
return latestPatchInstalled >= REQUIRED_MINIMAL_PATCH;
return latestPatchInstalled >= requiredMinimalPatch;
}

std::optional<fs::path> download_dotnet()
std::optional<fs::path> download_dotnet(const wchar_t* dotnetDesktopDownloadLink)
{
const wchar_t DOTNET_DESKTOP_DOWNLOAD_LINK[] = L"https://download.visualstudio.microsoft.com/download/pr/d30352fe-d4f3-4203-91b9-01a3b66a802e/bb416e6573fa278fec92113abefc58b3/windowsdesktop-runtime-3.1.15-win-x64.exe";
const wchar_t DOTNET_DESKTOP_FILENAME[] = L"windowsdesktop-runtime.exe";

auto dotnet_download_path = fs::temp_directory_path() / DOTNET_DESKTOP_FILENAME;
winrt::Windows::Foundation::Uri download_link{ DOTNET_DESKTOP_DOWNLOAD_LINK };
winrt::Windows::Foundation::Uri download_link{ dotnetDesktopDownloadLink };

const size_t max_attempts = 3;
bool download_success = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace fs = std::filesystem;
namespace updating
{
bool dotnet_is_installed();
std::optional<fs::path> download_dotnet();
bool dotnet_is_installed(const size_t major, const size_t minor, const size_t requiredMinimalPatch);
std::optional<fs::path> download_dotnet(const wchar_t* dotnetDesktopDownloadLink);
bool install_dotnet(fs::path dotnet_download_path, const bool silent);
}
30 changes: 22 additions & 8 deletions installer/PowerToysBootstrapper/bootstrapper/bootstrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,25 +407,39 @@ int Bootstrapper(HINSTANCE hInstance)
{
if (installDotnet)
{
spdlog::debug("Detecting if dotnet is installed");
const bool dotnetInstalled = updating::dotnet_is_installed();
spdlog::debug("Dotnet is already installed: {}", dotnetInstalled);
if (!dotnetInstalled)
auto dotnet3Info = std::make_tuple(VersionHelper{ 3, 1, 15 },
L"https://download.visualstudio.microsoft.com/download/pr/d30352fe-d4f3-4203-91b9-01a3b66a802e/bb416e6573fa278fec92113abefc58b3/windowsdesktop-runtime-3.1.15-win-x64.exe");
auto dotnet5Info = std::make_tuple(VersionHelper{ 5, 0, 7 },
L"https://download.visualstudio.microsoft.com/download/pr/2b83d30e-5c86-4d37-a1a6-582e22ac07b2/c7b1b7e21761bbfb7b9951f5b258806e/windowsdesktop-runtime-5.0.7-win-x64.exe");

const std::array dotnetsToInstall = { std::move(dotnet3Info), std::move(dotnet5Info) };

for (const auto& [ver, downloadLink] : dotnetsToInstall)
{
const auto& [major, minor, minimalRequiredPatch] = ver;
spdlog::debug("Detecting if dotnet {} is installed", ver.toString());
const bool dotnetInstalled = updating::dotnet_is_installed(major, minor, minimalRequiredPatch);

if (dotnetInstalled)
{
spdlog::debug("Dotnet {} is already installed: {}", ver.toString(), dotnetInstalled);
continue;
}

bool installedSuccessfully = false;
if (const auto dotnet_installer_path = updating::download_dotnet())
if (const auto dotnetInstallerPath = updating::download_dotnet(downloadLink))
{
// Dotnet installer has its own progress bar
CloseProgressBarDialog();
installedSuccessfully = updating::install_dotnet(*dotnet_installer_path, g_Silent);
installedSuccessfully = updating::install_dotnet(*dotnetInstallerPath, g_Silent);
if (!installedSuccessfully)
{
spdlog::error("Couldn't install dotnet");
spdlog::error("Couldn't install dotnet {}", ver.toString());
}
}
else
{
spdlog::error("Couldn't download dotnet");
spdlog::error("Couldn't download dotnet {}", ver.toString());
}

if (!installedSuccessfully)
Expand Down