Implement prototype Qml path function
This commit is contained in:
+33
-2
@@ -1,6 +1,7 @@
|
||||
#include "paths.h"
|
||||
#include <QStandardPaths>
|
||||
#include <QString>
|
||||
#include <QFileInfo>
|
||||
#include <easylogging++.h>
|
||||
|
||||
namespace paths
|
||||
@@ -9,7 +10,6 @@ optional<string> binaryDirectory()
|
||||
{
|
||||
const auto path
|
||||
= QStandardPaths::writableLocation( QStandardPaths::AppDataLocation );
|
||||
|
||||
if ( path == "" )
|
||||
{
|
||||
LOG( ERROR ) << "Could not find binary directory.";
|
||||
@@ -23,7 +23,6 @@ optional<string> 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<string> binaryDirectoryFindFile( const string fileName )
|
||||
return path.toStdString();
|
||||
}
|
||||
|
||||
optional<string> 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<string> 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
|
||||
|
||||
Reference in New Issue
Block a user