win32: remove the limit to the manifest file

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-07-05 10:36:34 +08:00
parent df5ff50c7f
commit aed1673855
3 changed files with 46 additions and 42 deletions

View File

@ -332,17 +332,17 @@ struct VersionNumber
int patch = 0; int patch = 0;
int tweak = 0; int tweak = 0;
[[nodiscard]] friend bool operator==(const VersionNumber &lhs, const VersionNumber &rhs) noexcept [[nodiscard]] friend constexpr bool operator==(const VersionNumber &lhs, const VersionNumber &rhs) noexcept
{ {
return ((lhs.major == rhs.major) && (lhs.minor == rhs.minor) && (lhs.patch == rhs.patch) && (lhs.tweak == rhs.tweak)); return ((lhs.major == rhs.major) && (lhs.minor == rhs.minor) && (lhs.patch == rhs.patch) && (lhs.tweak == rhs.tweak));
} }
[[nodiscard]] friend bool operator!=(const VersionNumber &lhs, const VersionNumber &rhs) noexcept [[nodiscard]] friend constexpr bool operator!=(const VersionNumber &lhs, const VersionNumber &rhs) noexcept
{ {
return !(lhs == rhs); return !operator==(lhs, rhs);
} }
[[nodiscard]] friend bool operator>(const VersionNumber &lhs, const VersionNumber &rhs) noexcept [[nodiscard]] friend constexpr bool operator>(const VersionNumber &lhs, const VersionNumber &rhs) noexcept
{ {
if (lhs.major > rhs.major) { if (lhs.major > rhs.major) {
return true; return true;
@ -371,19 +371,19 @@ struct VersionNumber
return false; return false;
} }
[[nodiscard]] friend bool operator<(const VersionNumber &lhs, const VersionNumber &rhs) noexcept [[nodiscard]] friend constexpr bool operator<(const VersionNumber &lhs, const VersionNumber &rhs) noexcept
{ {
return ((lhs != rhs) && !(lhs > rhs)); return (operator!=(lhs, rhs) && !operator>(lhs, rhs));
} }
[[nodiscard]] friend bool operator>=(const VersionNumber &lhs, const VersionNumber &rhs) noexcept [[nodiscard]] friend constexpr bool operator>=(const VersionNumber &lhs, const VersionNumber &rhs) noexcept
{ {
return ((lhs > rhs) || (lhs == rhs)); return (operator>(lhs, rhs) || operator==(lhs, rhs));
} }
[[nodiscard]] friend bool operator<=(const VersionNumber &lhs, const VersionNumber &rhs) noexcept [[nodiscard]] friend constexpr bool operator<=(const VersionNumber &lhs, const VersionNumber &rhs) noexcept
{ {
return ((lhs < rhs) || (lhs == rhs)); return (operator<(lhs, rhs) || operator==(lhs, rhs));
} }
}; };

View File

@ -23,6 +23,7 @@
*/ */
#include "sysapiloader_p.h" #include "sysapiloader_p.h"
#include <QtCore/qdebug.h>
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
# include <QtCore/private/qsystemlibrary_p.h> # include <QtCore/private/qsystemlibrary_p.h>
#else #else
@ -72,8 +73,10 @@ bool SysApiLoader::isAvailable(const QString &library, const QString &function)
QFunctionPointer symbol = SysApiLoader::resolve(library, function); QFunctionPointer symbol = SysApiLoader::resolve(library, function);
if (symbol) { if (symbol) {
m_apiCache.insert(function, symbol); m_apiCache.insert(function, symbol);
qDebug() << "Successfully loaded" << function << "from" << library;
return true; return true;
} }
qWarning() << "Failed to load" << function << "from" << library;
return false; return false;
} }

View File

@ -193,37 +193,40 @@ private:
T *p = nullptr; T *p = nullptr;
}; };
[[nodiscard]] static inline bool [[nodiscard]] static inline bool doCompareWindowsVersion(const VersionNumber &targetOsVer)
doCompareWindowsVersion(const DWORD dwMajor, const DWORD dwMinor, const DWORD dwBuild)
{ {
#if 0 static const std::optional<VersionNumber> currentOsVer = []() -> std::optional<VersionNumber> {
if (API_NT_AVAILABLE(RtlGetVersion)) { if (API_NT_AVAILABLE(RtlGetVersion)) {
using RtlGetVersionPtr = NTSTATUS(WINAPI *)(PRTL_OSVERSIONINFOW); using RtlGetVersionPtr = NTSTATUS(WINAPI *)(PRTL_OSVERSIONINFOW);
static const auto pRtlGetVersion = const auto pRtlGetVersion =
reinterpret_cast<RtlGetVersionPtr>( reinterpret_cast<RtlGetVersionPtr>(SysApiLoader::instance()->get(kRtlGetVersion));
SysApiLoader::instance()->get(kRtlGetVersion));
RTL_OSVERSIONINFOEXW osvi; RTL_OSVERSIONINFOEXW osvi;
SecureZeroMemory(&osvi, sizeof(osvi)); SecureZeroMemory(&osvi, sizeof(osvi));
osvi.dwOSVersionInfoSize = sizeof(osvi); osvi.dwOSVersionInfoSize = sizeof(osvi);
if (pRtlGetVersion(reinterpret_cast<PRTL_OSVERSIONINFOW>(&osvi)) == STATUS_SUCCESS) { if (pRtlGetVersion(reinterpret_cast<PRTL_OSVERSIONINFOW>(&osvi)) == STATUS_SUCCESS) {
VersionNumber realOsVer = {}; return VersionNumber{int(osvi.dwMajorVersion), int(osvi.dwMinorVersion), int(osvi.dwBuildNumber)};
realOsVer.major = osvi.dwMajorVersion;
realOsVer.minor = osvi.dwMinorVersion;
realOsVer.patch = osvi.dwBuildNumber;
VersionNumber testOsVer = {};
testOsVer.major = dwMajor;
testOsVer.minor = dwMinor;
testOsVer.tweak = dwBuild;
return (realOsVer >= testOsVer);
} }
} }
#endif return std::nullopt;
}();
if (currentOsVer.has_value()) {
return (currentOsVer >= targetOsVer);
}
// We can fallback to "VerifyVersionInfoW" if we can't determine the current system
// version, but this function will be affected by the manifest file of your application.
// For example, if you don't claim your application supports Windows 10 explicitly
// in the manifest file, Windows will assume your application only supports up to Windows
// 8.1, so this function will be told the current system is at most Windows 8.1, to keep
// good backward-compatiability. This behavior usually won't cause any issues if you
// always use an appropriate manifest file for your application, however, it does cause
// some issues for people who don't use the manifest file at all. There have been some
// bug reports about it already.
OSVERSIONINFOEXW osvi; OSVERSIONINFOEXW osvi;
SecureZeroMemory(&osvi, sizeof(osvi)); SecureZeroMemory(&osvi, sizeof(osvi));
osvi.dwOSVersionInfoSize = sizeof(osvi); osvi.dwOSVersionInfoSize = sizeof(osvi);
osvi.dwMajorVersion = dwMajor; osvi.dwMajorVersion = targetOsVer.major;
osvi.dwMinorVersion = dwMinor; osvi.dwMinorVersion = targetOsVer.minor;
osvi.dwBuildNumber = dwBuild; osvi.dwBuildNumber = targetOsVer.patch;
DWORDLONG dwlConditionMask = 0; DWORDLONG dwlConditionMask = 0;
const auto op = VER_GREATER_EQUAL; const auto op = VER_GREATER_EQUAL;
VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, op); VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, op);
@ -423,8 +426,7 @@ private:
bool Utils::isWindowsVersionOrGreater(const WindowsVersion version) bool Utils::isWindowsVersionOrGreater(const WindowsVersion version)
{ {
const VersionNumber ver = WindowsVersions[static_cast<int>(version)]; return doCompareWindowsVersion(WindowsVersions[static_cast<int>(version)]);
return doCompareWindowsVersion(ver.major, ver.minor, ver.patch);
} }
bool Utils::isDwmCompositionEnabled() bool Utils::isDwmCompositionEnabled()
@ -818,9 +820,8 @@ quint32 Utils::getPrimaryScreenDpi(const bool horizontal)
if (API_D2D_AVAILABLE(D2D1CreateFactory)) { if (API_D2D_AVAILABLE(D2D1CreateFactory)) {
using D2D1CreateFactoryPtr = using D2D1CreateFactoryPtr =
HRESULT(WINAPI *)(D2D1_FACTORY_TYPE, REFIID, CONST D2D1_FACTORY_OPTIONS *, void **); HRESULT(WINAPI *)(D2D1_FACTORY_TYPE, REFIID, CONST D2D1_FACTORY_OPTIONS *, void **);
static const auto pD2D1CreateFactory = const auto pD2D1CreateFactory =
reinterpret_cast<D2D1CreateFactoryPtr>( reinterpret_cast<D2D1CreateFactoryPtr>(SysApiLoader::instance()->get(kD2D1CreateFactory));
SysApiLoader::instance()->get(kD2D1CreateFactory));
HumbleComPtr<ID2D1Factory> d2dFactory = nullptr; HumbleComPtr<ID2D1Factory> d2dFactory = nullptr;
HRESULT hr = pD2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory), HRESULT hr = pD2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory),
nullptr, reinterpret_cast<void **>(&d2dFactory)); nullptr, reinterpret_cast<void **>(&d2dFactory));
@ -1442,10 +1443,10 @@ bool Utils::setBlurBehindWindowEnabled(const WId windowId, const BlurMode mode,
qWarning() << "Failed to resolve DwmExtendFrameIntoClientArea() from DWMAPI.DLL."; qWarning() << "Failed to resolve DwmExtendFrameIntoClientArea() from DWMAPI.DLL.";
return false; return false;
} }
static const auto pSetWindowCompositionAttribute = const auto pSetWindowCompositionAttribute =
reinterpret_cast<SetWindowCompositionAttributePtr>( reinterpret_cast<SetWindowCompositionAttributePtr>(
SysApiLoader::instance()->get(kSetWindowCompositionAttribute)); SysApiLoader::instance()->get(kSetWindowCompositionAttribute));
static const bool isBuild22523OrGreater = doCompareWindowsVersion(10, 0, 22523); static const bool isBuild22523OrGreater = doCompareWindowsVersion({10, 0, 22523});
static const bool isWin11OrGreater = isWindowsVersionOrGreater(WindowsVersion::_11_21H2); static const bool isWin11OrGreater = isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
static const bool isWin10OrGreater = isWindowsVersionOrGreater(WindowsVersion::_10_1507); static const bool isWin10OrGreater = isWindowsVersionOrGreater(WindowsVersion::_10_1507);
const BlurMode blurMode = [mode]() -> BlurMode { const BlurMode blurMode = [mode]() -> BlurMode {