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