diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp index d0b112e..79ed8bc 100644 --- a/src/utils/paths.cpp +++ b/src/utils/paths.cpp @@ -1,6 +1,7 @@ #include "paths.h" #include #include +#include #include namespace paths @@ -9,7 +10,6 @@ optional binaryDirectory() { const auto path = QStandardPaths::writableLocation( QStandardPaths::AppDataLocation ); - if ( path == "" ) { LOG( ERROR ) << "Could not find binary directory."; @@ -23,7 +23,6 @@ optional binaryDirectoryFindFile( const string fileName ) { const auto path = QStandardPaths::locate( QStandardPaths::AppDataLocation, QString::fromStdString( fileName ) ); - if ( path == "" ) { LOG( ERROR ) << "Could not find file '" << fileName.c_str() @@ -34,4 +33,36 @@ optional binaryDirectoryFindFile( const string fileName ) return path.toStdString(); } +optional qmlDirectory() +{ + const auto path + = QStandardPaths::locate( QStandardPaths::AppDataLocation, "res/qml/" ); + if ( path == "" ) + { + LOG( ERROR ) << "Unable to find QML directory."; + return std::nullopt; + } + + return path.toStdString(); +} + +optional qmlDirectoryFindFile( string fileName ) +{ + const auto qmlPath = qmlDirectory(); + if ( !qmlPath.has_value() ) + { + return std::nullopt; + } + + const auto path = ( *qmlPath ) + fileName; + QFileInfo filePath( QString::fromStdString( path ) ); + if ( !filePath.exists() ) + { + LOG( ERROR ) << "File: '" << path << "' not found."; + return std::nullopt; + } + + return std::move( path ); +} + } // namespace paths