Fix bug with determining the location of "res/"

This commit is contained in:
Bailey Harrison 2022-09-03 17:13:38 +01:00
parent f0433f145c
commit 0743cce845

View File

@ -2,21 +2,25 @@
#ifdef _MSC_VER #ifdef _MSC_VER
#include <windows.h> #include <windows.h>
#include <direct.h>
#define MAX_PATH 260 #define MAX_PATH 260
#endif #endif
#include "log.hpp"
ResourceManager::ResourceManager() ResourceManager::ResourceManager()
{ {
#ifdef _MSC_VER #ifdef _MSC_VER
CHAR exeDirBuf[MAX_PATH + 1]; CHAR exeDirBuf[MAX_PATH + 1];
GetModuleFileNameA(NULL, exeDirBuf, MAX_PATH + 1); GetModuleFileNameA(NULL, exeDirBuf, MAX_PATH + 1);
std::filesystem::path cwd = std::filesystem::path(exeDirBuf).parent_path(); std::filesystem::path cwd = std::filesystem::path(exeDirBuf).parent_path();
(void)_chdir((const char*)std::filesystem::absolute(cwd).c_str());
#else #else
std::filesystem::path cwd = std::filesystem::current_path(); std::filesystem::path cwd = std::filesystem::current_path();
#endif #endif
if (std::filesystem::is_directory(cwd / "res")) { if (std::filesystem::is_directory(cwd / "res")) {
m_resourcesPath = std::filesystem::absolute("res"); m_resourcesPath = cwd / "res";
} else { } else {
m_resourcesPath = cwd.parent_path() / "share" / "sdltest"; m_resourcesPath = cwd.parent_path() / "share" / "sdltest";
} }
@ -26,7 +30,7 @@ ResourceManager::ResourceManager()
} }
if (std::filesystem::is_directory(m_resourcesPath) == false) { if (std::filesystem::is_directory(m_resourcesPath) == false) {
throw std::runtime_error("Unable to determine resources location"); throw std::runtime_error("Unable to determine resources location. CWD: " + cwd.string());
} }
} }