@@ -1004,10 +1004,10 @@ static void do_vst2_check(lib_t& libHandle, const char* const filename, const bo | |||
return; | |||
} | |||
vstFn = (VST_Function)CFBundleGetFunctionPointerForName(bundleLoader.ref, CFSTR("main_macho")); | |||
vstFn = (VST_Function)CFBundleGetFunctionPointerForName(bundleLoader.getRef(), CFSTR("main_macho")); | |||
if (vstFn == nullptr) | |||
vstFn = (VST_Function)CFBundleGetFunctionPointerForName(bundleLoader.ref, CFSTR("VSTPluginMain")); | |||
vstFn = (VST_Function)CFBundleGetFunctionPointerForName(bundleLoader.getRef(), CFSTR("VSTPluginMain")); | |||
if (vstFn == nullptr) | |||
{ | |||
@@ -1465,9 +1465,9 @@ static void do_vst3_check(lib_t& libHandle, const char* const filename, const bo | |||
return; | |||
} | |||
v3_entry = (V3_ENTRYFN)CFBundleGetFunctionPointerForName(bundleLoader.ref, CFSTR(V3_ENTRYFNNAME)); | |||
v3_exit = (V3_EXITFN)CFBundleGetFunctionPointerForName(bundleLoader.ref, CFSTR(V3_EXITFNNAME)); | |||
v3_get = (V3_GETFN)CFBundleGetFunctionPointerForName(bundleLoader.ref, CFSTR(V3_GETFNNAME)); | |||
v3_entry = (V3_ENTRYFN)CFBundleGetFunctionPointerForName(bundleLoader.getRef(), CFSTR(V3_ENTRYFNNAME)); | |||
v3_exit = (V3_EXITFN)CFBundleGetFunctionPointerForName(bundleLoader.getRef(), CFSTR(V3_EXITFNNAME)); | |||
v3_get = (V3_GETFN)CFBundleGetFunctionPointerForName(bundleLoader.getRef(), CFSTR(V3_GETFNNAME)); | |||
#else | |||
water::String binaryfilename = filename; | |||
@@ -92,38 +92,61 @@ AutoNSAutoreleasePool::~AutoNSAutoreleasePool() | |||
// -------------------------------------------------------------------------------------------------------------------- | |||
BundleLoader::BundleLoader() noexcept | |||
: ref(nullptr), | |||
refNum(0) {} | |||
struct BundleLoader::PrivateData { | |||
CFBundleRef ref; | |||
CFBundleRefNum refNum; | |||
PrivateData() noexcept | |||
: ref(nullptr), | |||
refNum(0) {} | |||
~PrivateData() | |||
{ | |||
if (ref == nullptr) | |||
return; | |||
CFBundleCloseBundleResourceMap(ref, refNum); | |||
CFBundleUnloadExecutable(ref); | |||
CFRelease(ref); | |||
} | |||
bool load(const char* const filename) | |||
{ | |||
const CFURLRef urlRef = CFURLCreateFromFileSystemRepresentation(0, (const UInt8*)filename, (CFIndex)std::strlen(filename), true); | |||
CARLA_SAFE_ASSERT_RETURN(urlRef != nullptr, false); | |||
ref = CFBundleCreate(kCFAllocatorDefault, urlRef); | |||
CFRelease(urlRef); | |||
CARLA_SAFE_ASSERT_RETURN(ref != nullptr, false); | |||
if (! CFBundleLoadExecutable(ref)) | |||
{ | |||
CFRelease(ref); | |||
ref = nullptr; | |||
return false; | |||
} | |||
refNum = CFBundleOpenBundleResourceMap(ref); | |||
return true; | |||
} | |||
}; | |||
BundleLoader::BundleLoader() | |||
: pData(new PrivateData){} | |||
BundleLoader::~BundleLoader() | |||
{ | |||
if (ref == nullptr) | |||
return; | |||
CFBundleCloseBundleResourceMap(ref, refNum); | |||
CFBundleUnloadExecutable(ref); | |||
CFRelease(ref); | |||
delete pData; | |||
} | |||
bool BundleLoader::load(const char* const filename) | |||
{ | |||
const CFURLRef urlRef = CFURLCreateFromFileSystemRepresentation(0, (const UInt8*)filename, (CFIndex)std::strlen(filename), true); | |||
CARLA_SAFE_ASSERT_RETURN(urlRef != nullptr, false); | |||
ref = CFBundleCreate(kCFAllocatorDefault, urlRef); | |||
CFRelease(urlRef); | |||
CARLA_SAFE_ASSERT_RETURN(ref != nullptr, false); | |||
if (! CFBundleLoadExecutable(ref)) | |||
{ | |||
CFRelease(ref); | |||
ref = nullptr; | |||
return false; | |||
} | |||
return pData->load(filename); | |||
} | |||
refNum = CFBundleOpenBundleResourceMap(ref); | |||
return true; | |||
CFBundleRef& BundleLoader::getRef() const noexcept | |||
{ | |||
return pData->ref; | |||
} | |||
// -------------------------------------------------------------------------------------------------------------------- | |||
@@ -26,7 +26,6 @@ | |||
// don't include Foundation.h here | |||
typedef struct __CFBundle CFBundleRef; | |||
typedef int32_t CFBundleRefNum; | |||
CARLA_BACKEND_START_NAMESPACE | |||
@@ -64,12 +63,14 @@ private: | |||
// -------------------------------------------------------------------------------------------------------------------- | |||
struct BundleLoader { | |||
CFBundleRef ref; | |||
CFBundleRefNum refNum; | |||
BundleLoader() noexcept; | |||
BundleLoader(); | |||
~BundleLoader(); | |||
bool load(const char* const filename); | |||
CFBundleRef& getRef() const noexcept; | |||
private: | |||
struct PrivateData; | |||
PrivateData* const pData; | |||
}; | |||
// -------------------------------------------------------------------------------------------------------------------- | |||