Update path handling for MacOS

This commit is contained in:
Georg Hagen
2025-01-29 23:19:26 +01:00
parent f75d84c1eb
commit 2a6fe2741c
2 changed files with 24 additions and 9 deletions

View File

@@ -6,10 +6,13 @@
#include "AppFolders.hpp" #include "AppFolders.hpp"
#include "PlatformFolders.hpp" #include "PlatformFolders.hpp"
#if __APPLE__
#include <TargetConditionals.h>
#endif
namespace OpenVulkano namespace OpenVulkano
{ {
#ifdef __APPLE__ #if TARGET_OS_IOS == 1
AppFolders AppFolders::INSTANCE = AppFolders(""); AppFolders AppFolders::INSTANCE = AppFolders("");
#else #else
AppFolders AppFolders::INSTANCE = AppFolders("openVulkano"); AppFolders AppFolders::INSTANCE = AppFolders("openVulkano");
@@ -17,14 +20,14 @@ namespace OpenVulkano
void AppFolders::Init(std::string_view appName) void AppFolders::Init(std::string_view appName)
{ {
#ifndef __APPLE__ #if TARGET_OS_IOS != 1
INSTANCE = AppFolders(appName); INSTANCE = AppFolders(appName);
#endif #endif
} }
void AppFolders::Init(const std::filesystem::path& dir, std::optional<std::string_view> appName) void AppFolders::Init(const std::filesystem::path& dir, std::optional<std::string_view> appName)
{ {
#ifndef __APPLE__ #if TARGET_OS_IOS != 1
INSTANCE = AppFolders(dir, appName); INSTANCE = AppFolders(dir, appName);
#endif #endif
} }
@@ -49,7 +52,7 @@ namespace OpenVulkano
const std::filesystem::path& AppFolders::GetAppDataHomeDir() const std::filesystem::path& AppFolders::GetAppDataHomeDir()
{ {
#ifndef __APPLE__ #if TARGET_OS_IOS != 1
std::filesystem::create_directories(INSTANCE.appDataHome); std::filesystem::create_directories(INSTANCE.appDataHome);
#endif #endif
return INSTANCE.appDataHome; return INSTANCE.appDataHome;
@@ -57,7 +60,7 @@ namespace OpenVulkano
const std::filesystem::path& AppFolders::GetAppConfigHomeDir() const std::filesystem::path& AppFolders::GetAppConfigHomeDir()
{ {
#ifndef __APPLE__ #if TARGET_OS_IOS != 1
std::filesystem::create_directories(INSTANCE.appConfigHome); std::filesystem::create_directories(INSTANCE.appConfigHome);
#endif #endif
return INSTANCE.appConfigHome; return INSTANCE.appConfigHome;
@@ -65,7 +68,7 @@ namespace OpenVulkano
const std::filesystem::path& AppFolders::GetAppStateDir() const std::filesystem::path& AppFolders::GetAppStateDir()
{ {
#ifndef __APPLE__ #if TARGET_OS_IOS != 1
std::filesystem::create_directories(INSTANCE.appState); std::filesystem::create_directories(INSTANCE.appState);
#endif #endif
return INSTANCE.appState; return INSTANCE.appState;
@@ -73,7 +76,7 @@ namespace OpenVulkano
const std::filesystem::path& AppFolders::GetAppCacheDir() const std::filesystem::path& AppFolders::GetAppCacheDir()
{ {
#ifndef __APPLE__ #if TARGET_OS_IOS != 1
std::filesystem::create_directories(INSTANCE.appDataCache); std::filesystem::create_directories(INSTANCE.appDataCache);
#endif #endif
return INSTANCE.appDataCache; return INSTANCE.appDataCache;
@@ -81,7 +84,7 @@ namespace OpenVulkano
const std::filesystem::path& AppFolders::GetAppTempDir() const std::filesystem::path& AppFolders::GetAppTempDir()
{ {
#ifndef __APPLE__ #if TARGET_OS_IOS != 1
std::filesystem::create_directories(INSTANCE.appTemp); std::filesystem::create_directories(INSTANCE.appTemp);
#endif #endif
return INSTANCE.appTemp; return INSTANCE.appTemp;

View File

@@ -13,6 +13,9 @@
#include <shlobj.h> #include <shlobj.h>
#include <utf8.h> #include <utf8.h>
#include <memory> #include <memory>
#if __APPLE__
#include <TargetConditionals.h>
#endif
namespace OpenVulkano namespace OpenVulkano
{ {
@@ -51,7 +54,7 @@ namespace OpenVulkano
[[nodiscard]] std::filesystem::path GetXDGFolderDefault(const char* envName, std::string_view defaultRelativePath) [[nodiscard]] std::filesystem::path GetXDGFolderDefault(const char* envName, std::string_view defaultRelativePath)
{ {
#ifndef __APPLE__ #ifndef TARGET_OS_IOS != 1
const char* envValue = std::getenv(envName); const char* envValue = std::getenv(envName);
if (envValue) if (envValue)
{ {
@@ -66,11 +69,20 @@ namespace OpenVulkano
PlatformFolders::PlatformFolders() PlatformFolders::PlatformFolders()
{ {
#ifdef __APPLE__ #ifdef __APPLE__
#if TARGET_OS_IOS == 1
dataHome = GetHome() / "Documents/"; dataHome = GetHome() / "Documents/";
configHome = dataHome; configHome = dataHome;
stateDir = dataHome; stateDir = dataHome;
dataCache = GetHome() / "Library/Caches/"; dataCache = GetHome() / "Library/Caches/";
tempDir = dataCache; tempDir = dataCache;
#elif
const auto home = GetHome();
dataHome = home / "Library/Application Support"
configHome = dataHome;
stateDir = dataHome;
dataCache = home / "Library/Caches";
tempDir = GetXDGFolderDefault("TMPDIR", "tmp");
#endif
#elif defined(_WIN32) #elif defined(_WIN32)
dataHome = GetKnownWindowsFolder(FOLDERID_RoamingAppData, "RoamingAppData"); dataHome = GetKnownWindowsFolder(FOLDERID_RoamingAppData, "RoamingAppData");
configHome = GetKnownWindowsFolder(FOLDERID_RoamingAppData, "RoamingAppData"); configHome = GetKnownWindowsFolder(FOLDERID_RoamingAppData, "RoamingAppData");