Added BLOOM_COMPILED_RESOURCES_PATH_OVERRIDE macro to avoid using compiled resources in debug builds

This commit is contained in:
Nav
2021-05-30 19:05:18 +01:00
parent 3c60fee231
commit 602328d9d1
16 changed files with 155 additions and 60 deletions

19
src/Helpers/Paths.cpp Normal file
View File

@@ -0,0 +1,19 @@
#include <unistd.h>
#include <array>
#include <filesystem>
#include <climits>
#include <src/Exceptions/Exception.hpp>
#include "Paths.hpp"
using namespace Bloom;
std::string Paths::applicationDirPath() {
auto pathCharArray = std::array<char, PATH_MAX>();
if (readlink("/proc/self/exe", pathCharArray.data(), PATH_MAX) < 0) {
throw Exceptions::Exception("Failed to obtain application directory path.");
}
return std::filesystem::path(std::string(pathCharArray.begin(), pathCharArray.end())).parent_path();
}

43
src/Helpers/Paths.hpp Normal file
View File

@@ -0,0 +1,43 @@
#pragma once
#include <string>
namespace Bloom
{
class Paths
{
public:
/**
* Returns the path to the directory in which the Bloom binary resides.
*
* @return
*/
static std::string applicationDirPath();
/**
* Returns the path to the Resources directory, located in the application directory.
*
* @return
*/
static inline std::string resourcesDirPath() {
return Paths::applicationDirPath() + "/../resources/";
}
/**
* Returns the path to Bloom's compiled resources.
*
* If the debug configuration is enabled, this function will return the absolute path to Bloom's source code,
* meaning we won't use compiled resources for debug builds. This is useful for debugging and tweaking QT UI
* files such as QT stylesheets and UI templates.
* @return
*/
static inline const std::string compiledResourcesPath() {
#ifdef BLOOM_COMPILED_RESOURCES_PATH_OVERRIDE
return std::string(BLOOM_COMPILED_RESOURCES_PATH_OVERRIDE);
#else
return std::string(":/compiled");
#endif
}
};
}