void UnloadBundle(CFBundleRef theBundle) { /*get bundle resource and convert from xml to propertylist struct so we can look for revdontunload attribute and not unload- necessary for external that interface with Cocoa*/ Boolean dontunload = False; CFPropertyListRef tCFPropertyListRef = NULL; short resrefnum = CFBundleOpenBundleResourceMap (theBundle ); CFURLRef resFileCFURLRef = CFBundleCopyResourceURL(theBundle,CFSTR("revinfo"),CFSTR("plist"),NULL); CFDataRef resCFDataRef; if (resFileCFURLRef && CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault,resFileCFURLRef,&resCFDataRef,nil,nil,nil)) { if (resCFDataRef) { CFStringRef errorString; tCFPropertyListRef = CFPropertyListCreateFromXMLData(kCFAllocatorDefault,resCFDataRef,kCFPropertyListImmutable,&errorString); CFRelease(resCFDataRef); } } if (tCFPropertyListRef) { if (CFDictionaryGetValueIfPresent((CFDictionaryRef)tCFPropertyListRef,CFSTR("revdontunload"),NULL)) dontunload = True; } if (resFileCFURLRef) CFRelease(resFileCFURLRef); CFBundleCloseBundleResourceMap (theBundle,resrefnum); if (theBundle && !dontunload) { CFBundleUnloadExecutable(theBundle); CFRelease(theBundle); } }
OSErr AcroPluginCFragInitFunction( const CFragInitBlock * initBlock ) { OSErr err = __initialize(initBlock); if (err == noErr) { #if TARGET_API_MAC_CARBON if (initBlock->fragLocator.where == kDataForkCFragLocator) { // Mac OS X 10.1 and earlier has a bug where packaged CFM libs are still passed // kDataForkCFragLocator instead of kCFBundleCFragLocator. Apple claims this will // fixed in Jaguar. FSSpec spec = *initBlock->fragLocator.u.onDisk.fileSpec; // See if parent folder is named "MacOS" FSMakeFSSpec(spec.vRefNum, spec.parID, "\p", &spec); if (IdenticalString(spec.name, "\pMacOS", NULL) == 0) { // See if parent folder is named "Contents" FSMakeFSSpec(spec.vRefNum, spec.parID, "\p", &spec); if (IdenticalString(spec.name, "\pContents", NULL) == 0) { // Get Bundle Ref FSRef fsRef; FSMakeFSSpec(spec.vRefNum, spec.parID, "\p", &spec); if (noErr == FSpMakeFSRef(&spec, &fsRef)) { CFURLRef cfURL = CFURLCreateFromFSRef(NULL, &fsRef); if (cfURL) { gPluginBundle = CFBundleCreate(NULL, cfURL); #if DEBUG CFShow(cfURL); CFShow(gPluginBundle); #endif if (gPluginBundle) gResFile = CFBundleOpenBundleResourceMap(gPluginBundle); CFRelease(cfURL); } } } } }
// Opens the resource fork for the plugin // Also checks if the plugin is a CFBundle and opens gets the correct resource static short OpenPluginResourceFork(nsIFile *pluginFile) { FSSpec spec; OSErr err = toFSSpec(pluginFile, spec); Boolean targetIsFolder, wasAliased; err = ::ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased); short refNum = ::FSpOpenResFile(&spec, fsRdPerm); if (refNum < 0) { nsCString path; pluginFile->GetNativePath(path); CFBundleRef bundle = getPluginBundle(path.get()); if (bundle) { refNum = CFBundleOpenBundleResourceMap(bundle); CFRelease(bundle); } } return refNum; }
// Opens the resource fork for the plugin // Also checks if the plugin is a CFBundle and opens gets the correct resource static short OpenPluginResourceFork(nsIFile *pluginFile) { FSSpec spec; nsCOMPtr<nsILocalFileMac> lfm = do_QueryInterface(pluginFile); if (!lfm || NS_FAILED(lfm->GetFSSpec(&spec))) return -1; Boolean targetIsFolder, wasAliased; ::ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased); short refNum = ::FSpOpenResFile(&spec, fsRdPerm); if (refNum < 0) { nsCString path; pluginFile->GetNativePath(path); CFBundleRef bundle = getPluginBundle(path.get()); if (bundle) { refNum = CFBundleOpenBundleResourceMap(bundle); ::CFRelease(bundle); } } return refNum; }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Name: InitContext Input Parameters: Output Parameters: context : Pointer to global context. <function> : Status code. Description: Allocates and initializes the context data for this module. Change History (most recent first): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ static OSStatus InitContext(PrintDialogPDEOnlyContextPtr* context) { OSStatus err = noErr; // Error condition. /* Allocate the global context. */ *context = (PrintDialogPDEOnlyContextPtr) calloc(1, sizeof(PrintDialogPDEOnlyContext)); if (NULL != *context) { CFBundleRef theBundleRef = NULL; /* the calloc above initializes our context data to 0. (*context)->thePrintSelTextOnlyControlRef = NULL; (*context)->theBundleRef = NULL; (*context)->titleStringRef = NULL; */ (*context)->theResFile = -1; // Open the resource fork theBundleRef = CFBundleGetBundleWithIdentifier(kPrintDialogPDEBundleID); if(theBundleRef) { (*context)->theResFile = CFBundleOpenBundleResourceMap(theBundleRef); if ((*context)->theResFile == -1) err = kPMGeneralError; (*context)->theBundleRef = theBundleRef; } else err = kPMInvalidPDEContext; // this really needs a better error code } else err = kPMInvalidPDEContext; return (err); } // InitContext
int load(std::string name) { int rval = -1; vstPluginMain pluginMain = NULL; CFStringRef path = NULL; CFURLRef urlRef = NULL; CFURLRef exeRef = NULL; Boolean success; // Start clean m_bundle = NULL; // Don't really know what this should be initialize to m_resource = -1; // Convert the path to a CFSTring path = CFStringCreateWithCString(NULL, name.c_str(), kCFStringEncodingUTF8); // Convert the path to a URL urlRef = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, path, kCFURLPOSIXPathStyle, true); if (urlRef == NULL) goto error; // Create the bundle using the URL m_bundle = CFBundleCreate(kCFAllocatorDefault, urlRef); // Bail if the bundle wasn't created if (m_bundle == NULL) goto error; // Retrieve a reference to the executable exeRef = CFBundleCopyExecutableURL(m_bundle); if (exeRef == NULL) goto error; // Convert back to path UInt8 exePath[PATH_MAX]; if(!CFURLGetFileSystemRepresentation(exeRef, true, exePath, sizeof(exePath))) goto error; // Attempt to open it m_module = dlopen((char *) exePath, RTLD_NOW | RTLD_LOCAL); if (m_module == NULL) goto error; // Try to locate the new plugin entry point pluginMain = (vstPluginMain) dlsym(m_module, "VSTPluginMain"); // If not found, try finding the old entry point if (pluginMain == NULL) { pluginMain = (vstPluginMain) dlsym(m_module, "main_macho"); } // Must not be a VST plugin if (pluginMain == NULL) goto error; // Open the resource map ... some plugins (like GRM Tools) need this. m_resource = CFBundleOpenBundleResourceMap(m_bundle); // Initialize the plugin m_effect = pluginMain(audioMaster); // Was it successful? if(!m_effect) goto error; m_effect->user = this; // callDispatcher(effOpen, 0, 0, NULL, 0.0); // Ensure that it looks like a plugin and can deal with ProcessReplacing // calls. Also exclude synths for now. if(m_effect->magic == kEffectMagic && !(m_effect->flags & effFlagsIsSynth) && m_effect->flags & effFlagsCanReplacing) { // mVendor = GetString(effGetVendorString); // mName = GetString(effGetEffectName); // mInputs = mAEffect->numInputs; // mOutputs = mAEffect->numOutputs; // We could even go so far as to run a small test here. rval = 0; goto cleanup; } else { goto error; } error: if(m_effect) { callDispatcher(effClose, 0, 0, NULL, 0.0); m_effect = NULL; } if(m_resource != -1) { CFBundleCloseBundleResourceMap(m_bundle, m_resource); m_resource = -1; } if(m_module) { dlclose(m_module); m_module = NULL; } if(m_bundle) { CFRelease(m_bundle); m_bundle = NULL; } if(pluginMain) { pluginMain = NULL; } cleanup: if(exeRef) { CFRelease(exeRef); exeRef = NULL; } if(urlRef) { CFRelease(urlRef); urlRef = NULL; } if(path) { CFRelease(path); path = NULL; } return rval; }
bool PluginPackage::fetchInfo() { if (!load()) return false; WTF::RetainPtr<CFDictionaryRef> mimeDict; WTF::RetainPtr<CFTypeRef> mimeTypesFileName = CFBundleGetValueForInfoDictionaryKey(m_module, CFSTR("WebPluginMIMETypesFilename")); if (mimeTypesFileName && CFGetTypeID(mimeTypesFileName.get()) == CFStringGetTypeID()) { WTF::RetainPtr<CFStringRef> fileName = (CFStringRef)mimeTypesFileName.get(); WTF::RetainPtr<CFStringRef> homeDir = homeDirectoryPath().createCFString(); WTF::RetainPtr<CFStringRef> path = CFStringCreateWithFormat(0, 0, CFSTR("%@/Library/Preferences/%@"), homeDir.get(), fileName.get()); WTF::RetainPtr<CFDictionaryRef> plist = readPListFile(path.get(), /*createFile*/ false, m_module); if (plist) { // If the plist isn't localized, have the plug-in recreate it in the preferred language. WTF::RetainPtr<CFStringRef> localizationName = (CFStringRef)CFDictionaryGetValue(plist.get(), CFSTR("WebPluginLocalizationName")); CFLocaleRef locale = CFLocaleCopyCurrent(); if (localizationName != CFLocaleGetIdentifier(locale)) plist = readPListFile(path.get(), /*createFile*/ true, m_module); CFRelease(locale); } else { // Plist doesn't exist, ask the plug-in to create it. plist = readPListFile(path.get(), /*createFile*/ true, m_module); } mimeDict = (CFDictionaryRef)CFDictionaryGetValue(plist.get(), CFSTR("WebPluginMIMETypes")); } if (!mimeDict) mimeDict = (CFDictionaryRef)CFBundleGetValueForInfoDictionaryKey(m_module, CFSTR("WebPluginMIMETypes")); if (mimeDict) { CFIndex propCount = CFDictionaryGetCount(mimeDict.get()); Vector<const void*, 128> keys(propCount); Vector<const void*, 128> values(propCount); CFDictionaryGetKeysAndValues(mimeDict.get(), keys.data(), values.data()); for (int i = 0; i < propCount; ++i) { String mimeType = (CFStringRef)keys[i]; mimeType = mimeType.lower(); WTF::RetainPtr<CFDictionaryRef> extensionsDict = (CFDictionaryRef)values[i]; WTF:RetainPtr<CFNumberRef> enabled = (CFNumberRef)CFDictionaryGetValue(extensionsDict.get(), CFSTR("WebPluginTypeEnabled")); if (enabled) { int enabledValue = 0; if (CFNumberGetValue(enabled.get(), kCFNumberIntType, &enabledValue) && enabledValue == 0) continue; } Vector<String> mimeExtensions; WTF::RetainPtr<CFArrayRef> extensions = (CFArrayRef)CFDictionaryGetValue(extensionsDict.get(), CFSTR("WebPluginExtensions")); if (extensions) { CFIndex extensionCount = CFArrayGetCount(extensions.get()); for (CFIndex i = 0; i < extensionCount; ++i) { String extension =(CFStringRef)CFArrayGetValueAtIndex(extensions.get(), i); extension = extension.lower(); mimeExtensions.append(extension); } } m_mimeToExtensions.set(mimeType, mimeExtensions); String description = (CFStringRef)CFDictionaryGetValue(extensionsDict.get(), CFSTR("WebPluginTypeDescription")); m_mimeToDescriptions.set(mimeType, description); } m_name = (CFStringRef)CFBundleGetValueForInfoDictionaryKey(m_module, CFSTR("WebPluginName")); m_description = (CFStringRef)CFBundleGetValueForInfoDictionaryKey(m_module, CFSTR("WebPluginDescription")); } else { int resFile = CFBundleOpenBundleResourceMap(m_module); UseResFile(resFile); Vector<String> mimes = stringListFromResourceId(MIMEListStringStringNumber); if (mimes.size() % 2 != 0) return false; Vector<String> descriptions = stringListFromResourceId(MIMEDescriptionStringNumber); if (descriptions.size() != mimes.size() / 2) return false; for (size_t i = 0; i < mimes.size(); i += 2) { String mime = mimes[i].lower(); Vector<String> extensions; mimes[i + 1].lower().split(UChar(','), extensions); m_mimeToExtensions.set(mime, extensions); m_mimeToDescriptions.set(mime, descriptions[i / 2]); } Vector<String> names = stringListFromResourceId(PluginNameOrDescriptionStringNumber); if (names.size() == 2) { m_description = names[0]; m_name = names[1]; } CFBundleCloseBundleResourceMap(m_module, resFile); } LOG(Plugins, "PluginPackage::fetchInfo(): Found plug-in '%s'", m_name.utf8().data()); if (isPluginBlacklisted()) { LOG(Plugins, "\tPlug-in is blacklisted!"); return false; } return true; }
bool VSTEffect::Load() { vstPluginMain pluginMain; bool success = false; mModule = NULL; mAEffect = NULL; #if defined(__WXMAC__) // Start clean mBundleRef = NULL; // Don't really know what this should be initialize to mResource = -1; // Convert the path to a CFSTring wxMacCFStringHolder path(mPath); // Convert the path to a URL CFURLRef urlRef = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, path, kCFURLPOSIXPathStyle, true); if (urlRef == NULL) { return false; } // Create the bundle using the URL CFBundleRef bundleRef = CFBundleCreate(kCFAllocatorDefault, urlRef); // Done with the URL CFRelease(urlRef); // Bail if the bundle wasn't created if (bundleRef == NULL) { return false; } // Retrieve a reference to the executable CFURLRef exeRef = CFBundleCopyExecutableURL(bundleRef); if (exeRef == NULL) { CFRelease(bundleRef); return false; } // Convert back to path UInt8 exePath[PATH_MAX]; success = CFURLGetFileSystemRepresentation(exeRef, true, exePath, sizeof(exePath)); // Done with the executable reference CFRelease(exeRef); // Bail if we couldn't resolve the executable path if (success == FALSE) { CFRelease(bundleRef); return false; } // Attempt to open it mModule = dlopen((char *) exePath, RTLD_NOW | RTLD_LOCAL); if (mModule == NULL) { CFRelease(bundleRef); return false; } // Try to locate the new plugin entry point pluginMain = (vstPluginMain) dlsym(mModule, "VSTPluginMain"); // If not found, try finding the old entry point if (pluginMain == NULL) { pluginMain = (vstPluginMain) dlsym(mModule, "main_macho"); } // Must not be a VST plugin if (pluginMain == NULL) { dlclose(mModule); mModule = NULL; CFRelease(bundleRef); return false; } // Need to keep the bundle reference around so we can map the // resources. mBundleRef = bundleRef; // Open the resource map ... some plugins (like GRM Tools) need this. mResource = (int) CFBundleOpenBundleResourceMap(bundleRef); #else { wxLogNull nolog; // Try to load the library wxDynamicLibrary *lib = new wxDynamicLibrary(mPath); if (!lib) { return false; } // Bail if it wasn't successful if (!lib->IsLoaded()) { delete lib; return false; } // Try to find the entry point, while suppressing error messages pluginMain = (vstPluginMain) lib->GetSymbol(wxT("VSTPluginMain")); if (pluginMain == NULL) { pluginMain = (vstPluginMain) lib->GetSymbol(wxT("main")); if (pluginMain == NULL) { delete lib; return false; } } // Save the library reference mModule = lib; } #endif // Initialize the plugin mAEffect = pluginMain(audioMaster); // Was it successful? if (mAEffect) { // mAEffect->user = this; // callDispatcher(effOpen, 0, 0, NULL, 0.0); // Ensure that it looks like a plugin and can deal with ProcessReplacing // calls. Also exclude synths for now. if (mAEffect->magic == kEffectMagic && !(mAEffect->flags & effFlagsIsSynth) && mAEffect->flags & effFlagsCanReplacing) { mVendor = GetString(effGetVendorString); mName = GetString(effGetEffectName); mInputs = mAEffect->numInputs; mOutputs = mAEffect->numOutputs; // We could even go so far as to run a small test here. success = true; } } if (!success) { Unload(); } return success; }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // AURenderQualityPopup::AURenderQualityPopup // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ AURenderQualityPopup::AURenderQualityPopup (AUCarbonViewBase *inBase, Point inLocation, int inRightEdge, ControlFontStyleRec & inFontStyle) : AUPropertyControl (inBase) { Rect r; r.top = inLocation.v; r.bottom = r.top + 17; r.left = inLocation.h; r.right = r.left + inRightEdge; ControlFontStyleRec fontStyle = inFontStyle; inFontStyle.just = teFlushRight; ControlRef ref; CFBundleRef mainBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.audio.units.Components")); if (mainBundle != NULL) { CFMutableStringRef renderTitle = CFStringCreateMutable(NULL, 0); CFStringAppend(renderTitle, CFCopyLocalizedStringFromTableInBundle( CFSTR("Render Quality"), CFSTR("CustomUI"), mainBundle, CFSTR("The Render Quality Popup menu title"))); CFStringAppend(renderTitle, CFSTR(":")); OSErr theErr = CreateStaticTextControl (GetCarbonWindow(), &r, renderTitle, &inFontStyle, &ref); if (theErr == noErr) EmbedControl(ref); r.left = r.right + 8; r.right = r.left + 100; short bundleRef = CFBundleOpenBundleResourceMap (mainBundle); theErr = CreatePopupButtonControl (mView->GetCarbonWindow(), &r, NULL, /*kQualityMenuID*/ -12345, false, -1, 0, 0, &mControl); MenuRef menuRef; verify_noerr(CreateNewMenu(kQualityMenuID, 0, &menuRef)); verify_noerr(AppendMenuItemTextWithCFString (menuRef, CFCopyLocalizedStringFromTableInBundle(CFSTR("Maximum"), CFSTR("CustomUI"), mainBundle, CFSTR("")), 0, kChangeRenderQualityCmd, 0)); verify_noerr(AppendMenuItemTextWithCFString (menuRef, CFCopyLocalizedStringFromTableInBundle(CFSTR("High"), CFSTR("CustomUI"), mainBundle, CFSTR("")), 0, kChangeRenderQualityCmd, 0)); verify_noerr(AppendMenuItemTextWithCFString (menuRef, CFCopyLocalizedStringFromTableInBundle(CFSTR("Medium"), CFSTR("CustomUI"), mainBundle, CFSTR("")), 0, kChangeRenderQualityCmd, 0)); verify_noerr(AppendMenuItemTextWithCFString (menuRef, CFCopyLocalizedStringFromTableInBundle(CFSTR("Low"), CFSTR("CustomUI"), mainBundle, CFSTR("")), 0, kChangeRenderQualityCmd, 0)); verify_noerr(AppendMenuItemTextWithCFString (menuRef, CFCopyLocalizedStringFromTableInBundle(CFSTR("Minimum"), CFSTR("CustomUI"), mainBundle, CFSTR("")), 0, kChangeRenderQualityCmd, 0)); verify_noerr(SetControlData(mControl, 0, kControlPopupButtonMenuRefTag, sizeof(menuRef), &menuRef)); verify_noerr(SetControlFontStyle (mControl, &inFontStyle)); SetControl32BitMaximum(mControl, 5); UInt32 renderQuality; UInt32 size = sizeof(UInt32); AudioUnitGetProperty (mView->GetEditAudioUnit(), kAudioUnitProperty_RenderQuality, kAudioUnitScope_Global, 0, &renderQuality, &size); HandlePropertyChange(renderQuality); EmbedControl(mControl); theErr = AudioUnitAddPropertyListener(mView->GetEditAudioUnit(), kAudioUnitProperty_RenderQuality, RenderQualityListener, this); CFBundleCloseBundleResourceMap (mainBundle, bundleRef); CFRelease(renderTitle); } RegisterEvents(); }