This commit is contained in:
朱子楚\zhuzi 2023-12-14 21:16:09 +08:00
parent 08c458c2a1
commit 5787e308dd
3 changed files with 56 additions and 3 deletions

View File

@ -8,6 +8,7 @@
#include <QStandardPaths> #include <QStandardPaths>
#include <QDir> #include <QDir>
#include <QThread> #include <QThread>
#include <QSettings>
#include "Version.h" #include "Version.h"
#ifdef WIN32 #ifdef WIN32
#include <process.h> #include <process.h>
@ -40,6 +41,55 @@ std::map<QtMsgType, int> logLevelMap = {
{QtDebugMsg,4} {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("<string>")) {
QRegularExpression re(QString::fromUtf8("\\s*<string>(.*)</string>"));
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) 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]"<<COMMIT_HASH; qInfo()<<"[GitHashCode]"<<COMMIT_HASH;
qInfo()<<"[DeviceInfo]"; qInfo()<<"[DeviceInfo]";
qInfo()<<" [DeviceId]"<<QSysInfo::machineUniqueId(); qInfo()<<" [DeviceId]"<<QSysInfo::machineUniqueId();
qInfo()<<" [Manufacturer]"<<QSysInfo::prettyProductName(); qInfo()<<" [Manufacturer]"<<prettyProductInfoWrapper();
qInfo()<<" [CPU_ABI]"<<QSysInfo::currentCpuArchitecture(); qInfo()<<" [CPU_ABI]"<<QSysInfo::currentCpuArchitecture();
qInfo()<<"[LOG_LEVEL]"<<g_logLevel; qInfo()<<"[LOG_LEVEL]"<<g_logLevel;
qInfo()<<"[LOG_PATH]"<<g_file_path; qInfo()<<"[LOG_PATH]"<<g_file_path;

View File

@ -4,6 +4,7 @@
namespace Log namespace Log
{ {
QString prettyProductInfoWrapper();
void setup(const QString &app); void setup(const QString &app);
} }

View File

@ -25,10 +25,12 @@ Q_IMPORT_QML_PLUGIN(FluentUIPlugin)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
qputenv("QT_QUICK_CONTROLS_STYLE","Basic"); qputenv("QT_QUICK_CONTROLS_STYLE","Basic");
//UOSv20 does not print logs #ifdef Q_OS_LINUX
//fix bug UOSv20 does not print logs
qputenv("QT_LOGGING_RULES",""); qputenv("QT_LOGGING_RULES","");
//v-sync does not work //fix bug UOSv20 v-sync does not work
qputenv("QSG_RENDER_LOOP","basic"); qputenv("QSG_RENDER_LOOP","basic");
#endif
QGuiApplication::setOrganizationName("ZhuZiChu"); QGuiApplication::setOrganizationName("ZhuZiChu");
QGuiApplication::setOrganizationDomain("https://zhuzichu520.github.io"); QGuiApplication::setOrganizationDomain("https://zhuzichu520.github.io");
QGuiApplication::setApplicationName("FluentUI"); QGuiApplication::setApplicationName("FluentUI");