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 ),