Clean up pass
This commit is contained in:
@@ -7,11 +7,22 @@
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <windows.h>
|
||||
|
||||
namespace RenderCadenceCompositor
|
||||
{
|
||||
namespace
|
||||
{
|
||||
std::filesystem::path ExecutableDirectory()
|
||||
{
|
||||
char path[MAX_PATH] = {};
|
||||
const DWORD length = GetModuleFileNameA(nullptr, path, static_cast<DWORD>(sizeof(path)));
|
||||
if (length == 0 || length >= sizeof(path))
|
||||
return std::filesystem::current_path();
|
||||
return std::filesystem::path(path).parent_path();
|
||||
}
|
||||
|
||||
std::string ReadTextFile(const std::filesystem::path& path, std::string& error)
|
||||
{
|
||||
std::ifstream input(path, std::ios::binary);
|
||||
@@ -76,6 +87,17 @@ AppConfigProvider::AppConfigProvider() :
|
||||
{
|
||||
}
|
||||
|
||||
bool AppConfigProvider::LoadDefault(std::string& error)
|
||||
{
|
||||
const std::filesystem::path path = FindConfigFile();
|
||||
if (path.empty())
|
||||
{
|
||||
error = "Could not locate config/runtime-host.json from current directory or executable directory.";
|
||||
return false;
|
||||
}
|
||||
return Load(path, error);
|
||||
}
|
||||
|
||||
bool AppConfigProvider::Load(const std::filesystem::path& path, std::string& error)
|
||||
{
|
||||
mConfig = DefaultAppConfig();
|
||||
@@ -183,4 +205,28 @@ void VideoFormatDimensions(const std::string& formatName, unsigned& width, unsig
|
||||
width = 1920;
|
||||
height = 1080;
|
||||
}
|
||||
|
||||
std::filesystem::path FindConfigFile(const std::filesystem::path& relativePath)
|
||||
{
|
||||
std::vector<std::filesystem::path> starts;
|
||||
starts.push_back(std::filesystem::current_path());
|
||||
starts.push_back(ExecutableDirectory());
|
||||
|
||||
for (std::filesystem::path start : starts)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
const std::filesystem::path candidate = start / relativePath;
|
||||
if (std::filesystem::exists(candidate))
|
||||
return candidate;
|
||||
|
||||
const std::filesystem::path parent = start.parent_path();
|
||||
if (parent.empty() || parent == start)
|
||||
break;
|
||||
start = parent;
|
||||
}
|
||||
}
|
||||
|
||||
return std::filesystem::path();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user