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]"<