summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheMorc <r.gracik@gmail.com>2023-08-23 03:32:22 +0200
committerTheMorc <r.gracik@gmail.com>2023-08-24 08:44:50 +0200
commit52e6167b9a8585edc0d938b32239623300398f01 (patch)
treeb72a4e48e94a4a6d7272a8a2ea106008ff307b1f
parentc166831955517d6999e6b4f48bf3085b05b06a76 (diff)
downloadabaddon-portaudio-52e6167b9a8585edc0d938b32239623300398f01.tar.gz
abaddon-portaudio-52e6167b9a8585edc0d938b32239623300398f01.zip
add hackish macOS detection for home folder, resources and cache
-rw-r--r--src/platform.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/platform.cpp b/src/platform.cpp
index 70e1c20..0a69721 100644
--- a/src/platform.cpp
+++ b/src/platform.cpp
@@ -151,6 +151,71 @@ std::string Platform::FindStateCacheFolder() {
return ".";
}
+#elif defined(__APPLE__)
+#include <CoreFoundation/CoreFoundation.h>
+#include <pwd.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+std::string Platform::FindResourceFolder() {
+ static std::string found_path;
+ static bool found = false;
+ if (found) return found_path;
+
+ CFURLRef resourceURL = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
+ char resourcePath[PATH_MAX];
+ if (CFURLGetFileSystemRepresentation(resourceURL, true, (UInt8 *)resourcePath, PATH_MAX)) {
+ if (resourceURL != NULL) {
+ CFRelease(resourceURL);
+ }
+ found_path = resourcePath;
+ found = true;
+ return found_path;
+ }
+
+ spdlog::get("discord")->warn("cant find a resources folder, will try to load from cwd");
+ found_path = ".";
+ found = true;
+ return found_path;
+}
+
+std::string Platform::FindConfigFile() {
+ const auto cfg = std::getenv("ABADDON_CONFIG");
+ if (cfg != nullptr) return cfg;
+
+ passwd *home = getpwuid(getuid());
+ const char *homeDir = home->pw_dir;
+
+ char appSupportPath[PATH_MAX];
+ snprintf(appSupportPath, sizeof(appSupportPath), "%s/Library/Application Support", homeDir);
+
+ char homefolder_path[PATH_MAX];
+ snprintf(homefolder_path, sizeof(homefolder_path), "%s/%s", appSupportPath, "com.github.uowuo.abaddon");
+
+ if (mkdir(homefolder_path, 0755) == 0) {
+ spdlog::get("discord")->warn("created Application Support dir");
+ }
+
+ char home_path[PATH_MAX];
+ snprintf(home_path, sizeof(home_path), "%s/%s", homefolder_path, "/abaddon.ini");
+
+ return home_path;
+}
+
+std::string Platform::FindStateCacheFolder() {
+
+ passwd *home = getpwuid(getuid());
+ const char *homeDir = home->pw_dir;
+
+ char appSupportPath[PATH_MAX];
+ snprintf(appSupportPath, sizeof(appSupportPath), "%s/Library/Application Support", homeDir);
+
+ char home_path[PATH_MAX];
+ snprintf(home_path, sizeof(home_path), "%s/%s", appSupportPath, "com.github.uowuo.abaddon");
+
+ return home_path;
+}
+
+
#else
std::string Platform::FindResourceFolder() {
spdlog::get("discord")->warn("unknown OS, trying to load resources from cwd");