From d54886620f1bf400bf2f93c5bad831969181c1d8 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Wed, 9 Oct 2019 05:35:12 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D1=87=D0=B8=D1=81=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D0=BD=D0=B0=20=D1=8D=D1=82=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/filesystem/paths.cpp | 53 ++++++++++++++++++++++-------------- src/myx/log/spdlog.cpp | 2 +- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/myx/filesystem/paths.cpp b/src/myx/filesystem/paths.cpp index e970659..3133f34 100644 --- a/src/myx/filesystem/paths.cpp +++ b/src/myx/filesystem/paths.cpp @@ -1,9 +1,11 @@ #include "paths.hpp" + #include #include "whereami++.h" #include #include +#include namespace myx { @@ -57,19 +59,22 @@ void Paths::setConfigFilePath( const QFileInfo& configFilePath ) } -Paths::Paths() : - m_prefixDirectory( "/opt/" ORGANIZATION_NAME_LOWER "/" PROJECT_NAME_LOWER ), - m_binaryDirectory( m_prefixDirectory.absolutePath() + "/bin" ), - m_configDirectory( m_prefixDirectory.absolutePath() + "/etc" ), - m_cacheDirectory( m_prefixDirectory.absolutePath() + "/var" ), - m_tempDirectory( QString::fromLocal8Bit( qgetenv( qPrintable( "TMPDIR" ) ) ) ), - m_dataDirectory( m_prefixDirectory.absolutePath() + "/share" ), - m_homeDirectory( QString::fromLocal8Bit( qgetenv( qPrintable( "HOME" ) ) ) ), - m_executableFileName( PROJECT_NAME_LOWER ), - m_configFileName( PROJECT_NAME_LOWER ".conf" ), - m_executableFilePath( m_binaryDirectory.absolutePath() + "/" + m_executableFileName ), - m_configFilePath( m_binaryDirectory.absolutePath() + "/" + m_configFileName ) +Paths::Paths() { + m_prefixDirectory = "/opt/" + QCoreApplication::organizationName().toLower() + + "/" + QCoreApplication::applicationName().toLower(); + m_binaryDirectory = m_prefixDirectory.absolutePath() + "/bin"; + m_configDirectory = m_prefixDirectory.absolutePath() + "/etc"; + m_cacheDirectory = m_prefixDirectory.absolutePath() + "/var"; + m_tempDirectory = QString::fromLocal8Bit( qgetenv( qPrintable( "TMPDIR" ) ) ); + m_dataDirectory = m_prefixDirectory.absolutePath() + "/share"; + m_homeDirectory = QString::fromLocal8Bit( qgetenv( qPrintable( "HOME" ) ) ); + m_executableFileName = QCoreApplication::applicationName().toLower(); + m_configFileName = m_executableFileName + ".conf"; + m_executableFilePath = m_binaryDirectory.absolutePath() + "/" + m_executableFileName; + m_configFilePath = m_binaryDirectory.absolutePath() + "/" + m_configFileName; + + if ( m_tempDirectory.absolutePath().isEmpty() || ( m_tempDirectory.path() == "." ) ) { m_tempDirectory = _PATH_TMP; @@ -163,7 +168,8 @@ bool Paths::updatePaths() m_configDirectory = m_prefixDirectory.absolutePath() + "/etc"; m_cacheDirectory = m_prefixDirectory.absolutePath() + "/var"; m_dataDirectory = m_prefixDirectory.absolutePath() + "/share"; - m_configFilePath = QFile( m_configDirectory.absolutePath() + "/" + PROJECT_NAME_LOWER + ".conf" ); + m_configFilePath = QFile( m_configDirectory.absolutePath() + "/" + + QCoreApplication::applicationName() + ".conf" ); } if ( m_prefixDirectory.absolutePath().startsWith( "/opt" ) || @@ -172,23 +178,29 @@ bool Paths::updatePaths() QString dataDirectory = QString::fromLocal8Bit( qgetenv( qPrintable( "XDG_DATA_HOME" ) ) ); if ( dataDirectory.isEmpty() ) { - dataDirectory = m_homeDirectory.absolutePath() + ".local/share/"; + dataDirectory = m_homeDirectory.absolutePath() + ".local/share"; } - m_dataDirectory = dataDirectory + ORGANIZATION_NAME_LOWER + "/" + PROJECT_NAME_LOWER; + m_dataDirectory = dataDirectory + "/" + + QCoreApplication::organizationName().toLower() + "/" + + QCoreApplication::applicationName().toLower(); QString configDirectory = QString::fromLocal8Bit( qgetenv( qPrintable( "XDG_CONFIG_HOME" ) ) ); if ( configDirectory.isEmpty() ) { - configDirectory = m_homeDirectory.absolutePath() + ".config/"; + configDirectory = m_homeDirectory.absolutePath() + ".config"; } - m_configDirectory = configDirectory + ORGANIZATION_NAME_LOWER + "/" + PROJECT_NAME_LOWER; + m_configDirectory = configDirectory + "/" + + QCoreApplication::organizationName().toLower() + "/" + + QCoreApplication::applicationName().toLower(); QString cacheDirectory = QString::fromLocal8Bit( qgetenv( qPrintable( "XDG_CACHE_HOME" ) ) ); if ( cacheDirectory.isEmpty() ) { - cacheDirectory = m_homeDirectory.absolutePath() + ".cache/"; + cacheDirectory = m_homeDirectory.absolutePath() + ".cache"; } - m_cacheDirectory = cacheDirectory + ORGANIZATION_NAME_LOWER + "/" + PROJECT_NAME_LOWER; + m_cacheDirectory = cacheDirectory + "/" + + QCoreApplication::organizationName().toLower() + "/" + + QCoreApplication::applicationName().toLower(); } return( true ); @@ -214,7 +226,8 @@ QString Paths::findConfigFile( const QString& defaultConfigFile ) return( defaultConfigFile ); } - auto fileName = QString::fromLocal8Bit( qgetenv( qPrintable( PROJECT_NAME_UPPER "_CONFIG" ) ) ); + auto fileName = QString::fromLocal8Bit( qgetenv( QCoreApplication::applicationName() + .toUpper().toUtf8() + "_CONFIG" ) ); if ( QFileInfo( fileName ).isReadable() ) { m_configFilePath = fileName; diff --git a/src/myx/log/spdlog.cpp b/src/myx/log/spdlog.cpp index 9bf99cf..7fec3b7 100644 --- a/src/myx/log/spdlog.cpp +++ b/src/myx/log/spdlog.cpp @@ -12,7 +12,7 @@ Logger::Logger( std::string name ) : m_logger( nullptr ), m_name( std::move( name ) ), m_outputPattern( "[%H:%M:%S %z] [%n] [%^---%L---%$] %v" ), - m_baseFileName( fmt::format( "{}_{}", PROJECT_NAME, "st" ) ), + m_baseFileName( "default" ), m_maxRotatingFileSize( rotatingFileSize ), m_maxRotatingFilesCount( 3 ), m_outputLevel( spdlog::level::trace ),