commit 51c64065
Removed the need for CoreServices on Mac OS X.
Based on a slight discussion on https://github.com/sago007/PlatformFolders/issues/14
Removes a major pain in the Mac OS X part.
This commit includes the code changes. The README needs updates too.
Changed files
| M | CMakeLists.txt before |
| M | sago/platform_folders.cpp before |
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 519db44..50979ce 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,25 +39,6 @@ endif()
# cxx_nullptr exists in v3.1
target_compile_features(platform_folders PRIVATE cxx_nullptr)
-# Apple requires linking to CoreServices
-# Check sys name instead of "APPLE" for cross-compilation
-if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
- # Find the framework
- # ref: https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/OSX_Technology_Overview/SystemFrameworks/SystemFrameworks.html
- find_library(_CoreServices_FRAMEWORK
- NAMES "CoreServices.framework" "CoreServices"
- PATH_SUFFIXES "CoreServices"
- PATHS "/System/Library/Frameworks"
- )
- # Make sure it was found
- if(NOT _CoreServices_FRAMEWORK)
- message(FATAL_ERROR "Could not find the CoreServices framework!")
- endif()
- # Link to the CoreServices framework. This also sets the correct linking options
- # "If the library file is in a Mac OSX framework, the Headers directory of the framework will also be processed as a usage requirement."
- target_link_libraries(platform_folders PRIVATE "${_CoreServices_FRAMEWORK}")
-endif()
-
# Cmake's find_package search path is different based on the system
# See https://cmake.org/cmake/help/latest/command/find_package.html for the list
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
diff --git a/sago/platform_folders.cpp b/sago/platform_folders.cpp
index 93b2941..f4e699e 100644
--- a/sago/platform_folders.cpp
+++ b/sago/platform_folders.cpp
@@ -131,21 +131,6 @@ static std::string GetAppDataLocal() {
return GetKnownWindowsFolder(FOLDERID_LocalAppData, "LocalAppData could not be found");
}
#elif defined(__APPLE__)
-#include <CoreServices/CoreServices.h>
-
-static std::string GetMacFolder(OSType folderType, const char* errorMsg) {
- std::string ret;
- FSRef ref;
- char path[PATH_MAX];
- OSStatus err = FSFindFolder( kUserDomain, folderType, kCreateFolder, &ref );
- if (err != noErr) {
- throw std::runtime_error(errorMsg);
- }
- FSRefMakePath( &ref, (UInt8*)&path, PATH_MAX );
- ret = path;
- return ret;
-}
-
#else
#include <map>
#include <fstream>
@@ -209,7 +194,7 @@ std::string getDataHome() {
#ifdef _WIN32
return GetAppData();
#elif defined(__APPLE__)
- return GetMacFolder(kApplicationSupportFolderType, "Failed to find the Application Support Folder");
+ return getHome()+"/Library/Application Support";
#else
return getLinuxFolderDefault("XDG_DATA_HOME", ".local/share");
#endif
@@ -219,7 +204,7 @@ std::string getConfigHome() {
#ifdef _WIN32
return GetAppData();
#elif defined(__APPLE__)
- return GetMacFolder(kApplicationSupportFolderType, "Failed to find the Application Support Folder");
+ return getHome()+"/Library/Application Support";
#else
return getLinuxFolderDefault("XDG_CONFIG_HOME", ".config");
#endif
@@ -229,7 +214,7 @@ std::string getCacheDir() {
#ifdef _WIN32
return GetAppDataLocal();
#elif defined(__APPLE__)
- return GetMacFolder(kCachedDataFolderType, "Failed to find the Application Support Folder");
+ return getHome()+"/Library/Caches";
#else
return getLinuxFolderDefault("XDG_CACHE_HOME", ".cache");
#endif
@@ -319,7 +304,7 @@ std::string PlatformFolders::getDocumentsFolder() const {
#ifdef _WIN32
return GetKnownWindowsFolder(FOLDERID_Documents, "Failed to find My Documents folder");
#elif defined(__APPLE__)
- return GetMacFolder(kDocumentsFolderType, "Failed to find Documents Folder");
+ return getHome()+"/Documents";
#else
return data->folders["XDG_DOCUMENTS_DIR"];
#endif
@@ -329,7 +314,7 @@ std::string PlatformFolders::getDesktopFolder() const {
#ifdef _WIN32
return GetKnownWindowsFolder(FOLDERID_Desktop, "Failed to find Desktop folder");
#elif defined(__APPLE__)
- return GetMacFolder(kDesktopFolderType, "Failed to find Desktop folder");
+ return getHome()+"/Desktop";
#else
return data->folders["XDG_DESKTOP_DIR"];
#endif
@@ -339,7 +324,7 @@ std::string PlatformFolders::getPicturesFolder() const {
#ifdef _WIN32
return GetKnownWindowsFolder(FOLDERID_Pictures, "Failed to find My Pictures folder");
#elif defined(__APPLE__)
- return GetMacFolder(kPictureDocumentsFolderType, "Failed to find Picture folder");
+ return getHome()+"/Pictures";
#else
return data->folders["XDG_PICTURES_DIR"];
#endif
@@ -359,7 +344,7 @@ std::string PlatformFolders::getDownloadFolder1() const {
#ifdef _WIN32
return GetKnownWindowsFolder(FOLDERID_Downloads, "Failed to find My Downloads folder");
#elif defined(__APPLE__)
- return GetMacFolder(kDownloadsFolderType, "Failed to find Download folder");
+ return getHome()+"/Downloads";
#else
return data->folders["XDG_DOWNLOAD_DIR"];
#endif
@@ -369,7 +354,7 @@ std::string PlatformFolders::getMusicFolder() const {
#ifdef _WIN32
return GetKnownWindowsFolder(FOLDERID_Music, "Failed to find My Music folder");
#elif defined(__APPLE__)
- return GetMacFolder(kMusicDocumentsFolderType, "Failed to find Music folder");
+ return getHome()+"/Music";
#else
return data->folders["XDG_MUSIC_DIR"];
#endif
@@ -379,7 +364,7 @@ std::string PlatformFolders::getVideoFolder() const {
#ifdef _WIN32
return GetKnownWindowsFolder(FOLDERID_Videos, "Failed to find My Video folder");
#elif defined(__APPLE__)
- return GetMacFolder(kMovieDocumentsFolderType, "Failed to find Movie folder");
+ return getHome()+"/Movies";
#else
return data->folders["XDG_VIDEOS_DIR"];
#endif
@@ -391,7 +376,7 @@ std::string PlatformFolders::getSaveGamesFolder1() const {
//Data that should not be user accessible should be placed under GetDataHome() instead
return GetKnownWindowsFolder(FOLDERID_Documents, "Failed to find My Documents folder")+"\\My Games";
#elif defined(__APPLE__)
- return GetMacFolder(kApplicationSupportFolderType, "Failed to find Application Support Folder");
+ return getHome()+"/Library/Application Support";
#else
return getDataHome();
#endif