From 535cd1f9ac80b9f9631dbe9dc9c5aa348e0b711b Mon Sep 17 00:00:00 2001 From: Andrey Nekrasov Date: Wed, 17 Mar 2021 16:49:07 +0300 Subject: [PATCH] [Auto-update] Turn off on Windows < 1903 (#10240) --- .../bootstrapper/Resources.resx | 3 +++ .../bootstrapper/bootstrapper.cpp | 14 +++++++++++--- src/common/updating/installer.cpp | 5 +++++ src/common/updating/installer.h | 2 ++ src/common/updating/updating.cpp | 15 +++++++++++++-- src/common/utils/os-detect.h | 2 +- src/common/version/helper.cpp | 11 +++++++++++ src/common/version/helper.h | 1 + 8 files changed, 47 insertions(+), 6 deletions(-) diff --git a/installer/PowerToysBootstrapper/bootstrapper/Resources.resx b/installer/PowerToysBootstrapper/bootstrapper/Resources.resx index 20df365c0f..0687da7399 100644 --- a/installer/PowerToysBootstrapper/bootstrapper/Resources.resx +++ b/installer/PowerToysBootstrapper/bootstrapper/Resources.resx @@ -158,4 +158,7 @@ A newer version is already installed. + + PowerToys requires Windows 10 version 1903 (May 2019 Update) or newer to run. + diff --git a/installer/PowerToysBootstrapper/bootstrapper/bootstrapper.cpp b/installer/PowerToysBootstrapper/bootstrapper/bootstrapper.cpp index 0cb98bd879..48aa8da473 100644 --- a/installer/PowerToysBootstrapper/bootstrapper/bootstrapper.cpp +++ b/installer/PowerToysBootstrapper/bootstrapper/bootstrapper.cpp @@ -152,8 +152,6 @@ int Bootstrapper(HINSTANCE hInstance) const auto installDirArg = cmdArgs["install_dir"].as(); const bool extract_msi_only = cmdArgs["extract_msi"].as(); - spdlog::level::level_enum severity = spdlog::level::off; - std::wstring installFolderProp; if (!installDirArg.empty()) { @@ -185,6 +183,7 @@ int Bootstrapper(HINSTANCE hInstance) { } + spdlog::level::level_enum severity = spdlog::level::off; if (logLevel == "debug") { severity = spdlog::level::debug; @@ -197,6 +196,16 @@ int Bootstrapper(HINSTANCE hInstance) SetupLogger(logDir, severity); spdlog::debug("PowerToys Bootstrapper is launched\nnoFullUI: {}\nsilent: {}\nno_start_pt: {}\nskip_dotnet_install: {}\nlog_level: {}\ninstall_dir: {}\nextract_msi: {}\n", noFullUI, g_Silent, noStartPT, skipDotnetInstall, logLevel, installDirArg, extract_msi_only); + const VersionHelper myVersion(VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION); + + // Do not support installing on Windows < 1903 + if (myVersion >= VersionHelper{0, 36, 0} && updating::is_old_windows_version()) + { + ShowMessageBoxError(IDS_OLD_WINDOWS_ERROR); + spdlog::error("PowerToys {} requires at least Windows 1903 to run.", myVersion.toString()); + return 1; + } + // If a user requested an MSI -> extract it and exit if (extract_msi_only) { @@ -212,7 +221,6 @@ int Bootstrapper(HINSTANCE hInstance) } // Check if there's a newer version installed - const VersionHelper myVersion(VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION); const auto installedVersion = updating::get_installed_powertoys_version(); if (installedVersion && *installedVersion >= myVersion) { diff --git a/src/common/updating/installer.cpp b/src/common/updating/installer.cpp index 8ca50d1ece..fd5c7574c1 100644 --- a/src/common/updating/installer.cpp +++ b/src/common/updating/installer.cpp @@ -3,6 +3,7 @@ #include "installer.h" #include #include +#include #include "utils/winapi_error.h" namespace // Strings in this namespace should not be localized @@ -192,4 +193,8 @@ namespace updating co_return false; } + bool is_old_windows_version() + { + return !Is19H1OrHigher(); + } } \ No newline at end of file diff --git a/src/common/updating/installer.h b/src/common/updating/installer.h index 27d886243c..5263fe4e3e 100644 --- a/src/common/updating/installer.h +++ b/src/common/updating/installer.h @@ -16,4 +16,6 @@ namespace updating std::optional get_installed_powertoys_version(); std::future uninstall_previous_msix_version_async(); + + bool is_old_windows_version(); } \ No newline at end of file diff --git a/src/common/updating/updating.cpp b/src/common/updating/updating.cpp index 601ea0d0e9..50fc765896 100644 --- a/src/common/updating/updating.cpp +++ b/src/common/updating/updating.cpp @@ -7,9 +7,10 @@ #include "notifications.h" #include "updating.h" -#include -#include #include +#include +#include +#include namespace // Strings in this namespace should not be localized { @@ -68,12 +69,17 @@ namespace updating { co_return nonstd::make_unexpected(strings.GITHUB_NEW_VERSION_USING_LOCAL_BUILD_ERROR); } + try { http::HttpClient client; json::JsonObject release_object; const VersionHelper current_version(VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION); VersionHelper github_version = current_version; + + // On a <1903 system, block updates to 0.36+ + const bool blockNonPatchReleases = current_version.major == 0 && current_version.minor == 35 && !Is19H1OrHigher(); + if (prerelease) { const auto body = co_await client.request(Uri{ ALL_RELEASES_ENDPOINT }); @@ -102,6 +108,11 @@ namespace updating } } + if (blockNonPatchReleases && github_version >= VersionHelper{ 0, 36, 0 }) + { + co_return version_up_to_date{}; + } + if (github_version <= current_version) { co_return version_up_to_date{}; diff --git a/src/common/utils/os-detect.h b/src/common/utils/os-detect.h index 6fad87a9b3..888c5a37ac 100644 --- a/src/common/utils/os-detect.h +++ b/src/common/utils/os-detect.h @@ -2,7 +2,7 @@ #include -// The following three helper functions determine if the user has a build version higher than or equal to 19h1, as that is a requirement for xaml islands +// The following three helper functions determine if the user has a build version higher than or equal to 19h1 (aka 1903), as that is a requirement for xaml islands // Source : Microsoft-ui-xaml github // Link: https://github.com/microsoft/microsoft-ui-xaml/blob/c045cde57c5c754683d674634a0baccda34d58c4/dev/dll/SharedHelpers.cpp template diff --git a/src/common/version/helper.cpp b/src/common/version/helper.cpp index 12ca48f8d5..0e1b477126 100644 --- a/src/common/version/helper.cpp +++ b/src/common/version/helper.cpp @@ -39,3 +39,14 @@ std::wstring VersionHelper::toWstring() const result += std::to_wstring(revision); return result; } + +std::string VersionHelper::toString() const +{ + std::string result{ "v" }; + result += std::to_string(major); + result += '.'; + result += std::to_string(minor); + result += '.'; + result += std::to_string(revision); + return result; +} diff --git a/src/common/version/helper.h b/src/common/version/helper.h index 9d3a24c571..1f91958b6f 100644 --- a/src/common/version/helper.h +++ b/src/common/version/helper.h @@ -15,4 +15,5 @@ struct VersionHelper size_t revision; std::wstring toWstring() const; + std::string toString() const; };