From 08c4d1e4111791e01a102efe4301c9b9dd935527 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 13 Apr 2024 12:30:43 +0300 Subject: [PATCH] Fix path to logs on Windows. --- src/libs/vmisc/crashhandler/vcrashpaths.cpp | 40 ++++++++++++++------- src/libs/vmisc/vabstractapplication.cpp | 25 ++++++++----- 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/libs/vmisc/crashhandler/vcrashpaths.cpp b/src/libs/vmisc/crashhandler/vcrashpaths.cpp index 32752db18..fe58ebe7b 100644 --- a/src/libs/vmisc/crashhandler/vcrashpaths.cpp +++ b/src/libs/vmisc/crashhandler/vcrashpaths.cpp @@ -39,6 +39,30 @@ using namespace Qt::Literals::StringLiterals; +namespace +{ +auto LogDirPath(const QString &appName) -> QString +{ + const QString logs = QStringLiteral("Logs"); + + QString logDirPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); + if (logDirPath.isEmpty()) + { +#if defined(Q_OS_WINDOWS) + return QStringList{QCoreApplication::applicationDirPath(), logs, appName}.join(QDir::separator()); +#else + return QStringList{QDir::homePath(), VER_COMPANYNAME_STR, logs, appName}.join(QDir::separator()); +#endif + } +#if defined(Q_OS_WINDOWS) + QString path = QStringList{logDirPath, logs}.join(QDir::separator()); +#else + QString path = QStringList{logDirPath, VER_COMPANYNAME_STR, logs, appName}.join(QDir::separator()); +#endif + return path; +} +} // namespace + //--------------------------------------------------------------------------------------------------------------------- VCrashPaths::VCrashPaths(QString exeDir) : m_exeDir(std::move(exeDir)) @@ -48,19 +72,9 @@ VCrashPaths::VCrashPaths(QString exeDir) //--------------------------------------------------------------------------------------------------------------------- auto VCrashPaths::GetAttachmentPath(const QString &appName) -> QString { - QString logDirPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); - if (logDirPath.isEmpty()) - { - QString const logDirName = VER_COMPANYNAME_STR + "Logs"_L1; -#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) - logDirPath = - QDir::homePath() + QDir::separator() + logDirName + QDir::separator() + QCoreApplication::applicationName(); -#else - logDirPath = QCoreApplication::applicationDirPath() + QDir::separator() + logDirName + QDir::separator() + - QCoreApplication::applicationName(); -#endif - } - return QStringLiteral("%1/%2-pid%3.log").arg(logDirPath, appName.toLower()).arg(QCoreApplication::applicationPid()); + return QStringLiteral("%1/%2-pid%3.log") + .arg(LogDirPath(appName), appName.toLower()) + .arg(QCoreApplication::applicationPid()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vmisc/vabstractapplication.cpp b/src/libs/vmisc/vabstractapplication.cpp index 52702da16..a8806acf2 100644 --- a/src/libs/vmisc/vabstractapplication.cpp +++ b/src/libs/vmisc/vabstractapplication.cpp @@ -649,19 +649,28 @@ void VAbstractApplication::InitHighDpiScaling(int argc, char *argv[]) //--------------------------------------------------------------------------------------------------------------------- auto VAbstractApplication::LogDirPath() -> QString { - QString logDirPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); + const QString logs = QStringLiteral("Logs"); + + QString const logDirPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); if (logDirPath.isEmpty()) { - QString const logDirName = QCoreApplication::organizationName() + "Logs"_L1; -#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) - logDirPath = - QDir::homePath() + QDir::separator() + logDirName + QDir::separator() + QCoreApplication::applicationName(); +#if defined(Q_OS_WINDOWS) + return QStringList{QCoreApplication::applicationDirPath(), logs, QCoreApplication::applicationName()}.join( + QDir::separator()); #else - logDirPath = QCoreApplication::applicationDirPath() + QDir::separator() + logDirName + QDir::separator() + - QCoreApplication::applicationName(); + return QStringList{QDir::homePath(), QCoreApplication::organizationName(), logs, + QCoreApplication::applicationName()} + .join(QDir::separator()); #endif } - return logDirPath; +#if defined(Q_OS_WINDOWS) + QString path = QStringList{logDirPath, logs}.join(QDir::separator()); +#else + QString path = + QStringList{logDirPath, QCoreApplication::organizationName(), logs, QCoreApplication::applicationName()}.join( + QDir::separator()); +#endif + return path; } //---------------------------------------------------------------------------------------------------------------------