MACOSX: Pull a getResourceAppBundlePathMacOSX() wrapper from addSysArchivesToSearchSet()

This commit is contained in:
Donovan Watteau 2022-05-06 18:59:38 +02:00 committed by Thierry Crozat
parent 63e2c001bb
commit 5118c60874
3 changed files with 23 additions and 13 deletions

View file

@ -43,8 +43,8 @@
#include "common/fs.h"
#include "common/translation.h"
#include "ApplicationServices/ApplicationServices.h" // for LSOpenFSRef
#include "CoreFoundation/CoreFoundation.h" // for CF* stuff
#include <ApplicationServices/ApplicationServices.h> // for LSOpenFSRef
#include <CoreFoundation/CoreFoundation.h> // for CF* stuff
// For querying number of MIDI devices
#include <pthread.h>
@ -132,18 +132,11 @@ void OSystem_MacOSX::addSysArchivesToSearchSet(Common::SearchSet &s, int priorit
OSystem_POSIX::addSysArchivesToSearchSet(s, priority);
// Get URL of the Resource directory of the .app bundle
CFURLRef fileUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
if (fileUrl) {
// Try to convert the URL to an absolute path
UInt8 buf[MAXPATHLEN];
if (CFURLGetFileSystemRepresentation(fileUrl, true, buf, sizeof(buf))) {
// Success: Add it to the search path
Common::String bundlePath((const char *)buf);
// Search with a depth of 2 so the shaders are found
Common::String bundlePath = getResourceAppBundlePathMacOSX();
if (!bundlePath.empty()) {
// Success: search with a depth of 2 so the shaders are found
s.add("__OSX_BUNDLE__", new Common::FSDirectory(bundlePath, 2), priority);
}
CFRelease(fileUrl);
}
}
bool OSystem_MacOSX::hasFeature(Feature f) {

View file

@ -29,5 +29,6 @@ bool hasTextInClipboardMacOSX();
Common::U32String getTextFromClipboardMacOSX();
bool setTextInClipboardMacOSX(const Common::U32String &text);
Common::String getDesktopPathMacOSX();
Common::String getResourceAppBundlePathMacOSX();
#endif

View file

@ -30,6 +30,7 @@
#include <Foundation/NSPathUtilities.h>
#include <AvailabilityMacros.h>
#include <CoreFoundation/CFString.h>
#include <CoreFoundation/CoreFoundation.h>
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
#define NSPasteboardTypeString NSStringPboardType
@ -110,3 +111,18 @@ Common::String getDesktopPathMacOSX() {
return Common::String();
return Common::String([path fileSystemRepresentation]);
}
Common::String getResourceAppBundlePathMacOSX() {
CFURLRef fileUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
if (fileUrl) {
// Try to convert the URL to an absolute path
UInt8 buf[MAXPATHLEN];
if (CFURLGetFileSystemRepresentation(fileUrl, true, buf, sizeof(buf))) {
CFRelease(fileUrl);
return Common::String((const char *)buf);
}
CFRelease(fileUrl);
}
return Common::String();
}