From 97776b57760c32bff6c28e8401eb1e66419301e7 Mon Sep 17 00:00:00 2001 From: Vasily Date: Sun, 17 Mar 2019 19:21:54 +0100 Subject: [PATCH] Change binary dir to be binary dir for all OS Linux did not see AppDataLocation as the binary directory, but as an arbitrary dir in the home folder. --- src/utils/paths.cpp | 40 ++++++++++++++++------------------------ src/utils/paths.h | 1 - 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp index 52b3216..dff4c82 100644 --- a/src/utils/paths.cpp +++ b/src/utils/paths.cpp @@ -1,5 +1,6 @@ #include "paths.h" #include +#include #include #include #include @@ -8,8 +9,8 @@ namespace paths { optional binaryDirectory() { - const auto path - = QStandardPaths::writableLocation( QStandardPaths::AppDataLocation ); + const auto path = QCoreApplication::applicationDirPath(); + if ( path == "" ) { LOG( ERROR ) << "Could not find binary directory."; @@ -21,34 +22,25 @@ optional binaryDirectory() optional binaryDirectoryFindFile( const string fileName ) { - const auto path - = QStandardPaths::locate( QStandardPaths::AppDataLocation, - QString::fromStdString( fileName ), - QStandardPaths::LocateFile ); - if ( path == "" ) + const auto path = binaryDirectory(); + + if ( !path ) + { + return std::nullopt; + } + + const auto filePath = QString::fromStdString( *path ) + "/" + + QString::fromStdString( fileName ); + QFileInfo file( filePath ); + + if ( !file.exists() ) { LOG( ERROR ) << "Could not find file '" << fileName.c_str() << "' in binary directory."; return std::nullopt; } - return path.toStdString(); -} - -optional binaryDirectoryFindDirectory( const string directoryName ) -{ - const auto path - = QStandardPaths::locate( QStandardPaths::AppDataLocation, - QString::fromStdString( directoryName ), - QStandardPaths::LocateDirectory ); - if ( path == "" ) - { - LOG( ERROR ) << "Could not find directory '" << directoryName.c_str() - << "' in binary directory."; - return std::nullopt; - } - - return path.toStdString(); + return filePath.toStdString(); } optional settingsDirectory() diff --git a/src/utils/paths.h b/src/utils/paths.h index ae06208..819a67f 100644 --- a/src/utils/paths.h +++ b/src/utils/paths.h @@ -9,7 +9,6 @@ using std::string; optional binaryDirectory(); optional binaryDirectoryFindFile( string fileName ); -optional binaryDirectoryFindDirectory( string directoryName ); optional settingsDirectory();