From 698ec52d5c056f3584c46e67b199adcfba9f8d2e Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Wed, 30 Jun 2021 18:15:03 -0400 Subject: try loading resources from share, fallback to cwd --- platform.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'platform.cpp') diff --git a/platform.cpp b/platform.cpp index 5d913a3..48d2104 100644 --- a/platform.cpp +++ b/platform.cpp @@ -1,6 +1,14 @@ #include "platform.hpp" #include #include +#include + +bool IsFolder(std::string_view path) { + std::error_code ec; + const auto status = std::filesystem::status(path, ec); + if (ec) return false; + return status.type() == std::filesystem::file_type::directory; +} #if defined(_WIN32) && defined(_MSC_VER) #include @@ -59,3 +67,29 @@ bool Platform::SetupFonts() { return true; } #endif + +#if defined(_WIN32) +std::string Platform::FindResourceFolder() { + return "."; +} + +#elif defined(__linux__) +std::string Platform::FindResourceFolder() { + static std::string path; + static bool found = false; + if (found) return path; + + if (IsFolder("/usr/share/abaddon/res") && IsFolder("/usr/share/abaddon/css")) { + path = "/usr/share/abaddon"; + } else { + puts("resources are not in /usr/share/abaddon, will try to load from cwd"); + path = "."; + } + found = true; + return path; +} +#else +std::string Platform::FindResourceFolder() { + puts("unknown OS, trying to load resources from cwd"); +} +#endif -- cgit v1.2.3