From 5787e308ddb32e2340bcfb157e1132659c42b520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Thu, 14 Dec 2023 21:16:09 +0800 Subject: [PATCH] update --- example/src/helper/Log.cpp | 52 +++++++++++++++++++++++++++++++++++++- example/src/helper/Log.h | 1 + example/src/main.cpp | 6 +++-- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/example/src/helper/Log.cpp b/example/src/helper/Log.cpp index 4f431b82..b9a97222 100644 --- a/example/src/helper/Log.cpp +++ b/example/src/helper/Log.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "Version.h" #ifdef WIN32 #include @@ -40,6 +41,55 @@ std::map logLevelMap = { {QtDebugMsg,4} }; +QString Log::prettyProductInfoWrapper() +{ + auto productName = QSysInfo::prettyProductName(); +#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) +#if defined(Q_OS_MACOS) + auto macosVersionFile = QString::fromUtf8("/System/Library/CoreServices/.SystemVersionPlatform.plist"); + auto fi = QFileInfo (macosVersionFile); + if (fi.exists() && fi.isReadable()) { + auto plistFile = QFile(macosVersionFile); + plistFile.open(QIODevice::ReadOnly); + while (!plistFile.atEnd()) { + auto line = plistFile.readLine(); + if (line.contains("ProductUserVisibleVersion")) { + auto nextLine = plistFile.readLine(); + if (nextLine.contains("")) { + QRegularExpression re(QString::fromUtf8("\\s*(.*)")); + auto matches = re.match(QString::fromUtf8(nextLine)); + if (matches.hasMatch()) { + productName = QString::fromUtf8("macOS ") + matches.captured(1); + break; + } + } + } + } + } +#endif +#endif +#if defined(Q_OS_WIN) + QSettings regKey {QString::fromUtf8("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), QSettings::NativeFormat}; + if (regKey.contains(QString::fromUtf8("CurrentBuildNumber"))) { + auto buildNumber = regKey.value(QString::fromUtf8("CurrentBuildNumber")).toInt(); + if (buildNumber > 0) { + if (buildNumber < 9200) { + productName = QString::fromUtf8("Windows 7 build %1").arg(buildNumber); + } + else if (buildNumber < 10240) { + productName = QString::fromUtf8("Windows 8 build %1").arg(buildNumber); + } + else if (buildNumber < 22000) { + productName = QString::fromUtf8("Windows 10 build %1").arg(buildNumber); + } + else { + productName = QString::fromUtf8("Windows 11 build %1").arg(buildNumber); + } + } + } +#endif + return productName; +} static inline void myMessageHandler(const QtMsgType type, const QMessageLogContext &context, const QString &message) { @@ -145,7 +195,7 @@ void Log::setup(const QString &app) qInfo()<<"[GitHashCode]"<