Fix path to QStandardPaths::ConfigLocation.

This commit is contained in:
Roman Telezhynskyi 2024-04-09 16:28:49 +03:00
parent f72d235344
commit d331b5dc01
2 changed files with 33 additions and 9 deletions

View File

@ -33,6 +33,12 @@
#include "../projectversion.h"
#include "vcrashpaths.h"
#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
#include "../compatibility.h"
#endif
using namespace Qt::Literals::StringLiterals;
//---------------------------------------------------------------------------------------------------------------------
VCrashPaths::VCrashPaths(QString exeDir)
: m_exeDir(std::move(exeDir))
@ -42,9 +48,18 @@ VCrashPaths::VCrashPaths(QString exeDir)
//---------------------------------------------------------------------------------------------------------------------
auto VCrashPaths::GetAttachmentPath(const QString &appName) -> QString
{
const QString logDirPath =
QStandardPaths::locate(QStandardPaths::ConfigLocation, QString(), QStandardPaths::LocateDirectory) +
QStringLiteral(VER_COMPANYNAME_STR);
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());
}
@ -64,14 +79,14 @@ auto VCrashPaths::GetHandlerPath() const -> QString
//---------------------------------------------------------------------------------------------------------------------
auto VCrashPaths::GetReportsPath() -> QString
{
return QStandardPaths::locate(QStandardPaths::AppConfigLocation, QString(), QStandardPaths::LocateDirectory) +
return QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + QDir::separator() +
QStringList{VER_COMPANYNAME_STR, "User Data", "Crashpad", "Reports"}.join(QDir::separator());
}
//---------------------------------------------------------------------------------------------------------------------
auto VCrashPaths::GetMetricsPath() -> QString
{
return QStandardPaths::locate(QStandardPaths::AppConfigLocation, QString(), QStandardPaths::LocateDirectory) +
return QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + QDir::separator() +
QStringList{VER_COMPANYNAME_STR, "User Data", "Crashpad", "Metrics"}.join(QDir::separator());
}

View File

@ -555,7 +555,7 @@ void VAbstractApplication::CheckSystemLocale()
auto CheckLanguage = [](QStandardPaths::StandardLocation type, const QStringList &test)
{
const QString path = QStandardPaths::locate(type, QString(), QStandardPaths::LocateDirectory);
const QString path = QStandardPaths::writableLocation(type);
return std::any_of(test.begin(), test.end(), [path](const QString &t) { return path.contains(t); });
};
@ -635,9 +635,18 @@ void VAbstractApplication::InitHighDpiScaling(int argc, char *argv[])
//---------------------------------------------------------------------------------------------------------------------
auto VAbstractApplication::LogDirPath() -> QString
{
const QString logDirPath =
QStandardPaths::locate(QStandardPaths::ConfigLocation, QString(), QStandardPaths::LocateDirectory) +
QCoreApplication::organizationName();
QString 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();
#else
logDirPath = QCoreApplication::applicationDirPath() + QDir::separator() + logDirName + QDir::separator() +
QCoreApplication::applicationName();
#endif
}
return logDirPath;
}