win: minor tweaks

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-10-16 13:41:41 +08:00
parent ca8e9f555d
commit e2f7c76c88
4 changed files with 151 additions and 201 deletions

View File

@ -132,20 +132,22 @@ if(FRAMELESSHELPER_BUILD_EXAMPLES)
endif()
message("#######################################")
message("CMAKE_VERSION: ${CMAKE_VERSION}")
message("CMAKE_HOST_SYSTEM: ${CMAKE_HOST_SYSTEM}")
message("CMAKE_HOST_SYSTEM_PROCESSOR: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
#message("CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}") # Currently we are not using any C compilers.
message("CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
message("CMAKE_LINKER: ${CMAKE_LINKER}")
message("CMAKE_MAKE_PROGRAM: ${CMAKE_MAKE_PROGRAM}")
message("CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message("CMake version: ${CMAKE_VERSION}")
message("Host system: ${CMAKE_HOST_SYSTEM}")
message("Host processor: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
#message("C compiler: ${CMAKE_C_COMPILER}") # Currently we are not using any C compilers.
message("C++ compiler: ${CMAKE_CXX_COMPILER}")
message("Linker: ${CMAKE_LINKER}")
message("Make program: ${CMAKE_MAKE_PROGRAM}")
message("Build type: ${CMAKE_BUILD_TYPE}")
message("#######################################")
set(__qt_inst_dir UNKNOWN)
if(DEFINED Qt6_DIR)
message("Qt installation dir: ${Qt6_DIR}")
set(__qt_inst_dir "${Qt6_DIR}")
else()
message("Qt installation dir: ${Qt5_DIR}")
set(__qt_inst_dir "${Qt5_DIR}")
endif()
message("Qt install dir: ${__qt_inst_dir}")
message("Qt version: ${QT_VERSION}")
# TODO: output shared/static Qt.
message("#######################################")

View File

@ -301,6 +301,7 @@ enum class WindowsVersion
_2000 = 0,
_XP = 1,
_XP_64 = 2,
_WS_03 = _XP_64, // Windows Server 2003
_Vista = 3,
_Vista_SP1 = 4,
_Vista_SP2 = 5,
@ -322,8 +323,10 @@ enum class WindowsVersion
_10_20H2 = 21,
_10_21H1 = 22,
_10_21H2 = 23,
_10 = _10_1507,
_11_21H2 = 24,
_11_22H2 = 25,
_11 = _11_21H2,
Latest = _11_22H2
};
Q_ENUM_NS(WindowsVersion)
@ -407,6 +410,9 @@ struct VersionNumber
[[nodiscard]] friend constexpr bool operator>(const VersionNumber &lhs, const VersionNumber &rhs) noexcept
{
if (operator==(lhs, rhs)) {
return false;
}
if (lhs.major > rhs.major) {
return true;
}
@ -425,13 +431,7 @@ struct VersionNumber
if (lhs.patch < rhs.patch) {
return false;
}
if (lhs.tweak > rhs.tweak) {
return true;
}
if (lhs.tweak < rhs.tweak) {
return false;
}
return false;
return (lhs.tweak > rhs.tweak);
}
[[nodiscard]] friend constexpr bool operator<(const VersionNumber &lhs, const VersionNumber &rhs) noexcept

View File

@ -31,34 +31,38 @@ FRAMELESSHELPER_BEGIN_NAMESPACE
namespace WindowsVersionHelper
{
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin2KOrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWinXPOrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWinXP64OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWinVistaOrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWinVistaSP1OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWinVistaSP2OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin7OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin7SP1OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin8OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin8Point1OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin8Point1Update1OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10TH1OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10TH2OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10RS1OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10RS2OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10RS3OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10RS4OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10RS5OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin1019H1OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin1019H2OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin1020H1OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin1020H2OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin21H1OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin21H2OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin11OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin1121H2OrGreater();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin1122H2OrGreater();
#define DECL(Name) [[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin##Name##OrGreater();
DECL(2K)
DECL(XP)
DECL(XP64)
DECL(Vista)
DECL(VistaSP1)
DECL(VistaSP2)
DECL(7)
DECL(7SP1)
DECL(8)
DECL(8Point1)
DECL(8Point1Update1)
DECL(10)
DECL(10TH1)
DECL(10TH2)
DECL(10RS1)
DECL(10RS2)
DECL(10RS3)
DECL(10RS4)
DECL(10RS5)
DECL(1019H1)
DECL(1019H2)
DECL(1020H1)
DECL(1020H2)
DECL(1021H1)
DECL(1021H2)
DECL(11)
DECL(1121H2)
DECL(1122H2)
#undef DECL
} // namespace WindowsVersionHelper

View File

@ -29,175 +29,119 @@ FRAMELESSHELPER_BEGIN_NAMESPACE
using namespace Global;
namespace WindowsVersionHelper
class WinVerHelper
{
Q_DISABLE_COPY_MOVE(WinVerHelper)
bool isWin2KOrGreater()
public:
explicit WinVerHelper();
~WinVerHelper();
[[nodiscard]] bool check(const WindowsVersion version) const;
private:
void initialize();
private:
bool m_flags[static_cast<int>(WindowsVersion::Latest) + 1] = {};
};
WinVerHelper::WinVerHelper()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_2000);
return result;
initialize();
}
bool isWinXPOrGreater()
WinVerHelper::~WinVerHelper() = default;
bool WinVerHelper::check(const WindowsVersion version) const
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_XP);
return result;
return m_flags[static_cast<int>(version)];
}
bool isWinXP64OrGreater()
void WinVerHelper::initialize()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_XP_64);
return result;
const auto fill = [this](const int no) -> void {
static const auto size = int(std::size(m_flags));
if ((no <= 0) || (no >= size)) {
return;
}
for (int i = 0; i != size; ++i) {
m_flags[i] = (i <= no);
}
};
#define ELIF(Version) \
else if (Utils::isWindowsVersionOrGreater(WindowsVersion::_##Version)) { \
fill(static_cast<int>(WindowsVersion::_##Version)); \
}
if (false) { /* Dummy */ }
ELIF(11_22H2)
ELIF(11_21H2)
ELIF(10_21H2)
ELIF(10_21H1)
ELIF(10_20H2)
ELIF(10_2004)
ELIF(10_1909)
ELIF(10_1903)
ELIF(10_1809)
ELIF(10_1803)
ELIF(10_1709)
ELIF(10_1703)
ELIF(10_1607)
ELIF(10_1511)
ELIF(10_1507)
ELIF(8_1_Update1)
ELIF(8_1)
ELIF(8)
ELIF(7_SP1)
ELIF(7)
ELIF(Vista_SP2)
ELIF(Vista_SP1)
ELIF(Vista)
ELIF(XP_64)
ELIF(XP)
ELIF(2000)
else { /* Dummy */ }
#undef ELIF
}
bool isWinVistaOrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_Vista);
return result;
}
Q_GLOBAL_STATIC(WinVerHelper, g_winVerHelper)
bool isWinVistaSP1OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_Vista_SP1);
return result;
}
#define IMPL(Name, Version) \
bool WindowsVersionHelper::isWin##Name##OrGreater() \
{ \
static const bool result = g_winVerHelper()->check(WindowsVersion::_##Version); \
return result; \
}
bool isWinVistaSP2OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_Vista_SP2);
return result;
}
IMPL(2K, 2000)
IMPL(XP, XP)
IMPL(XP64, XP_64)
IMPL(Vista, Vista)
IMPL(VistaSP1, Vista_SP1)
IMPL(VistaSP2, Vista_SP2)
IMPL(7, 7)
IMPL(7SP1, 7_SP1)
IMPL(8, 8)
IMPL(8Point1, 8_1)
IMPL(8Point1Update1, 8_1_Update1)
IMPL(10, 10)
IMPL(10TH1, 10_1507)
IMPL(10TH2, 10_1511)
IMPL(10RS1, 10_1607)
IMPL(10RS2, 10_1703)
IMPL(10RS3, 10_1709)
IMPL(10RS4, 10_1803)
IMPL(10RS5, 10_1809)
IMPL(1019H1, 10_1903)
IMPL(1019H2, 10_1909)
IMPL(1020H1, 10_2004)
IMPL(1020H2, 10_20H2)
IMPL(1021H1, 10_21H1)
IMPL(1021H2, 10_21H2)
IMPL(11, 11)
IMPL(1121H2, 11_21H2)
IMPL(1122H2, 11_22H2)
bool isWin7OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_7);
return result;
}
bool isWin7SP1OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_7_SP1);
return result;
}
bool isWin8OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_8);
return result;
}
bool isWin8Point1OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_8_1);
return result;
}
bool isWin8Point1Update1OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_8_1_Update1);
return result;
}
bool isWin10OrGreater()
{
return isWin10TH1OrGreater();
}
bool isWin10TH1OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1507);
return result;
}
bool isWin10TH2OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1511);
return result;
}
bool isWin10RS1OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1607);
return result;
}
bool isWin10RS2OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1703);
return result;
}
bool isWin10RS3OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1709);
return result;
}
bool isWin10RS4OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1803);
return result;
}
bool isWin10RS5OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1809);
return result;
}
bool isWin1019H1OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1903);
return result;
}
bool isWin1019H2OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1909);
return result;
}
bool isWin1020H1OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_2004);
return result;
}
bool isWin1020H2OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_20H2);
return result;
}
bool isWin21H1OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_21H1);
return result;
}
bool isWin21H2OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_21H2);
return result;
}
bool isWin11OrGreater()
{
return isWin1121H2OrGreater();
}
bool isWin1121H2OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
return result;
}
bool isWin1122H2OrGreater()
{
static const bool result = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_22H2);
return result;
}
} // namespace WindowsVersionHelper
#undef IMPL
FRAMELESSHELPER_END_NAMESPACE