Replace dedicated functions with single binary function
There are only 1 or 2 calls to specific directories in the codebase, hence this is unnecessary and just leads to bloat.
This commit is contained in:
+13
-4
@@ -48,11 +48,20 @@ int main( int argc, char* argv[] )
|
|||||||
commandLineArgs.forceNoSound,
|
commandLineArgs.forceNoSound,
|
||||||
qmlEngine );
|
qmlEngine );
|
||||||
|
|
||||||
QString path = QStandardPaths::locate(
|
const auto path
|
||||||
QStandardPaths::AppDataLocation,
|
= paths::binaryDirectoryFindFile( "res/qml/common/mainwidget.qml" );
|
||||||
QStringLiteral( "res/qml/common/mainwidget.qml" ) );
|
|
||||||
|
|
||||||
QQmlComponent component( &qmlEngine, QUrl::fromLocalFile( path ) );
|
if ( !path.has_value() )
|
||||||
|
{
|
||||||
|
LOG( ERROR ) << "Unable to find file '" << *path << "'.";
|
||||||
|
throw std::runtime_error(
|
||||||
|
"Unable to find critical file. See log for more information." );
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto url
|
||||||
|
= QUrl::fromLocalFile( QString::fromStdString( ( *path ) ) );
|
||||||
|
|
||||||
|
QQmlComponent component( &qmlEngine, url );
|
||||||
auto errors = component.errors();
|
auto errors = component.errors();
|
||||||
for ( auto& e : errors )
|
for ( auto& e : errors )
|
||||||
{
|
{
|
||||||
|
|||||||
+10
-24
@@ -21,8 +21,10 @@ optional<string> binaryDirectory()
|
|||||||
|
|
||||||
optional<string> binaryDirectoryFindFile( const string fileName )
|
optional<string> binaryDirectoryFindFile( const string fileName )
|
||||||
{
|
{
|
||||||
const auto path = QStandardPaths::locate(
|
const auto path
|
||||||
QStandardPaths::AppDataLocation, QString::fromStdString( fileName ) );
|
= QStandardPaths::locate( QStandardPaths::AppDataLocation,
|
||||||
|
QString::fromStdString( fileName ),
|
||||||
|
QStandardPaths::LocateFile );
|
||||||
if ( path == "" )
|
if ( path == "" )
|
||||||
{
|
{
|
||||||
LOG( ERROR ) << "Could not find file '" << fileName.c_str()
|
LOG( ERROR ) << "Could not find file '" << fileName.c_str()
|
||||||
@@ -33,36 +35,20 @@ optional<string> binaryDirectoryFindFile( const string fileName )
|
|||||||
return path.toStdString();
|
return path.toStdString();
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<string> qmlDirectory()
|
optional<string> binaryDirectoryFindDirectory( string directoryName )
|
||||||
{
|
{
|
||||||
const auto path
|
const auto path
|
||||||
= QStandardPaths::locate( QStandardPaths::AppDataLocation, "res/qml/" );
|
= QStandardPaths::locate( QStandardPaths::AppDataLocation,
|
||||||
|
QString::fromStdString( directoryName ),
|
||||||
|
QStandardPaths::LocateDirectory );
|
||||||
if ( path == "" )
|
if ( path == "" )
|
||||||
{
|
{
|
||||||
LOG( ERROR ) << "Unable to find QML directory.";
|
LOG( ERROR ) << "Could not find directory '" << directoryName.c_str()
|
||||||
|
<< "' in binary directory.";
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
return path.toStdString();
|
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
|
||||||
|
|||||||
+1
-9
@@ -9,15 +9,7 @@ using std::string;
|
|||||||
|
|
||||||
optional<string> binaryDirectory();
|
optional<string> binaryDirectory();
|
||||||
optional<string> binaryDirectoryFindFile( string fileName );
|
optional<string> binaryDirectoryFindFile( string fileName );
|
||||||
|
optional<string> binaryDirectoryFindDirectory( string directoryName );
|
||||||
optional<string> qmlDirectory();
|
|
||||||
optional<string> qmlDirectoryFindFile( string fileName );
|
|
||||||
|
|
||||||
optional<string> imageDirectory();
|
|
||||||
optional<string> imageDirectoryFindFile( string fileName );
|
|
||||||
|
|
||||||
optional<string> soundDirectory();
|
|
||||||
optional<string> soundDirectoryFindFile( string fileName );
|
|
||||||
|
|
||||||
optional<string> settingsDirectory();
|
optional<string> settingsDirectory();
|
||||||
optional<string> settingsDirectoryFindFile( string fileName );
|
optional<string> settingsDirectoryFindFile( string fileName );
|
||||||
|
|||||||
Reference in New Issue
Block a user