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

View File

@@ -13,6 +13,9 @@
#include <shlobj.h>
#include <utf8.h>
#include <memory>
#if __APPLE__
#include <TargetConditionals.h>
#endif
namespace OpenVulkano
{
@@ -51,7 +54,7 @@ namespace OpenVulkano
[[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);
if (envValue)
{
@@ -66,11 +69,20 @@ namespace OpenVulkano
PlatformFolders::PlatformFolders()
{
#ifdef __APPLE__
#if TARGET_OS_IOS == 1
dataHome = GetHome() / "Documents/";
configHome = dataHome;
stateDir = dataHome;
dataCache = GetHome() / "Library/Caches/";
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)
dataHome = GetKnownWindowsFolder(FOLDERID_RoamingAppData, "RoamingAppData");
configHome = GetKnownWindowsFolder(FOLDERID_RoamingAppData, "RoamingAppData");