Use Application Support directory on macOS. (#553)

This commit is contained in:
squidbus
2025-03-25 09:22:48 -07:00
committed by GitHub
parent 3d3524ffe7
commit fd16c379ff
4 changed files with 19 additions and 0 deletions
+7
View File
@@ -162,6 +162,13 @@ std::filesystem::path zelda64::get_app_folder_path() {
return std::filesystem::path{getenv("APP_FOLDER_PATH")};
}
#if defined(__APPLE__)
const auto supportdir = zelda64::get_application_support_directory();
if (supportdir) {
return *supportdir / zelda64::program_id;
}
#endif
const char *homedir;
if ((homedir = getenv("HOME")) == nullptr) {
+9
View File
@@ -12,6 +12,15 @@ namespace zelda64 {
});
}
std::optional<std::filesystem::path> get_application_support_directory() {
NSArray *dirs = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
if ([dirs count] > 0) {
NSString *dir = [dirs firstObject];
return std::filesystem::path([dir UTF8String]);
}
return std::nullopt;
}
std::filesystem::path get_bundle_resource_directory() {
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
return std::filesystem::path([bundlePath UTF8String]);