Defined paths in Paths helper class

This commit is contained in:
Nav
2022-01-02 20:25:25 +00:00
parent addb3ef64e
commit 0faa97fc68
2 changed files with 22 additions and 5 deletions

View File

@@ -154,17 +154,16 @@ void Application::shutdown() {
} }
void Application::loadProjectConfiguration() { void Application::loadProjectConfiguration() {
auto currentPath = std::filesystem::current_path().string(); auto jsonConfigFile = QFile(QString::fromStdString(Paths::projectConfigPath()));
auto jsonConfigFile = QFile(QString::fromStdString(currentPath + "/bloom.json"));
if (!jsonConfigFile.exists()) { if (!jsonConfigFile.exists()) {
throw InvalidConfig("Bloom configuration file (bloom.json) not found. Working directory: " throw InvalidConfig("Bloom configuration file (bloom.json) not found. Working directory: "
+ currentPath); + Paths::projectDirPath());
} }
if (!jsonConfigFile.open(QIODevice::ReadOnly)) { if (!jsonConfigFile.open(QIODevice::ReadOnly)) {
throw InvalidConfig("Failed to load Bloom configuration file (bloom.json) Working directory: " throw InvalidConfig("Failed to load Bloom configuration file (bloom.json) Working directory: "
+ currentPath); + Paths::projectDirPath());
} }
auto jsonObject = QJsonDocument::fromJson(jsonConfigFile.readAll()).object(); auto jsonObject = QJsonDocument::fromJson(jsonConfigFile.readAll()).object();

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <filesystem>
namespace Bloom namespace Bloom
{ {
@@ -19,10 +20,27 @@ namespace Bloom
* *
* @return * @return
*/ */
static inline std::string resourcesDirPath() { static std::string resourcesDirPath() {
return Paths::applicationDirPath() + "/../resources/"; return Paths::applicationDirPath() + "/../resources/";
} }
/**
* Returns the path to the current project's directory (the working directory, from which Bloom was run)
*
* @return
*/
static std::string projectDirPath() {
return std::filesystem::current_path().string();
}
/**
* Returns the path to the current project's configuration file (bloom.json).
*
* @return
*/
static std::string projectConfigPath() {
return std::filesystem::current_path().string() + "/bloom.json";
}
/** /**
* Returns the path to Bloom's compiled resources. * Returns the path to Bloom's compiled resources.
* *