summaryrefslogtreecommitdiff
path: root/platform.cpp
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-06-30 18:15:03 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2021-06-30 18:15:03 -0400
commit698ec52d5c056f3584c46e67b199adcfba9f8d2e (patch)
tree3b48df8eed852c2f4ecbdbcaaff9bf29d16f7b50 /platform.cpp
parent220aa6d13a9cb12687139305c6f68eb9cf6f73a1 (diff)
downloadabaddon-portaudio-698ec52d5c056f3584c46e67b199adcfba9f8d2e.tar.gz
abaddon-portaudio-698ec52d5c056f3584c46e67b199adcfba9f8d2e.zip
try loading resources from share, fallback to cwd
Diffstat (limited to 'platform.cpp')
-rw-r--r--platform.cpp34
1 files changed, 34 insertions, 0 deletions
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 <string>
#include <fstream>
+#include <filesystem>
+
+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 <Windows.h>
@@ -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