コード例 #1
0
ファイル: osxcode.cpp プロジェクト: Proteas/codesign
void Bundle::resources(vector<string> &paths, const char *type, const char *subdir)
{
	CFRef<CFArrayRef> cfList = CFBundleCopyResourceURLsOfType(cfBundle(),
		CFTempString(type), CFTempString(subdir));
	CFIndex size = CFArrayGetCount(cfList);
	paths.reserve(size);
	for (CFIndex n = 0; n < size; n++)
		paths.push_back(cfString(CFURLRef(CFArrayGetValueAtIndex(cfList, n))));
}
コード例 #2
0
void MDSAttrParser::parseAttrs(CFStringRef subdir)
{
	/* get all *.mdsinfo files */
	CFArrayRef bundleInfoFiles = CFBundleCopyResourceURLsOfType(mBundle,
		CFSTR(MDS_INFO_TYPE),
		subdir);
	if(bundleInfoFiles == NULL) {
		Syslog::alert("MDSAttrParser: no mdsattr files for %s", mPath);
		return;
	}
	assert(CFGetTypeID(bundleInfoFiles) == CFArrayGetTypeID());
	
	/* process each .mdsinfo file */
	CFIndex numFiles = CFArrayGetCount(bundleInfoFiles);
	for(CFIndex i=0; i<numFiles; i++) {
		/* get filename as CFURL */
		CFURLRef infoUrl = NULL;
		
		infoUrl = reinterpret_cast<CFURLRef>(
			CFArrayGetValueAtIndex(bundleInfoFiles, i));
		if(infoUrl == NULL) {
			MPDebug("MDSAttrParser: CFBundleCopyResourceURLsOfType screwup 1");
			continue;
		}
		if(CFGetTypeID(infoUrl) != CFURLGetTypeID()) {
			MPDebug("MDSAttrParser: CFBundleCopyResourceURLsOfType screwup 2");
			continue;
		}
		
		// @@@  Workaround for 4234967: skip any filename beginning with "._"
		CFStringRef lastComponent = CFURLCopyLastPathComponent(infoUrl);
		if (lastComponent) {
			CFStringRef resFilePfx = CFSTR("._");
			// setting the search length and location like this permits, 
			// e.g., ".foo.mdsinfo" to be valid
			CFIndex resFilePfxLen = CFStringGetMaximumSizeForEncoding(CFStringGetLength(resFilePfx), kCFStringEncodingUTF8);
			CFRange range = CFRangeMake(0, resFilePfxLen);
			Boolean skip = CFStringFindWithOptions(lastComponent, 
												   resFilePfx, 
												   range,
												   0/*options*/,
												   NULL/*returned substr*/);
			CFRelease(lastComponent);
			if (skip == true) {
				Syslog::warning("MDSAttrParser: ignoring resource file");
				continue;
			}
		}
		
		parseFile(infoUrl, subdir);
	} /* for each mdsinfo */
	CF_RELEASE(bundleInfoFiles);
}
コード例 #3
0
// --------------------------------------------------------------------------------------
static DataBrowserItemID addItemsToIconDB(ControlRef iconDataBrowser, ControlRef *userPanes)
{
    IconDBItemDataRec *itemsData, *rowItemData;
    CFBundleRef mainBundle;
    CFIndex rowNumber;
    DataBrowserItemID items[kNumberOfRows];
    CFStringRef catNameKeys[kNumberOfRows];

    itemsData = CFAllocatorAllocate(kCFAllocatorDefault,
                                    kNumberOfRows * sizeof(IconDBItemDataRec), 0);
    mainBundle = CFBundleGetMainBundle();

    if (!gIconsRegistered)		// if we didn't register our icons already, we need to
    {
        CFArrayRef iconURLs;
        FSRef iconFile;
        FSSpec iconSpec;

        iconURLs = CFBundleCopyResourceURLsOfType(mainBundle, CFSTR("icns"),
                   CFSTR("PrefCategories"));
        for (rowNumber = 0; rowNumber < kNumberOfRows; rowNumber++)
        {
            CFURLGetFSRef(CFArrayGetValueAtIndex(iconURLs, rowNumber), &iconFile);

#if TARGET_API_MAC_OSX
#pragma unused (iconSpec)
            RegisterIconRefFromFSRef(kAppSignature, 'Cat0' + rowNumber, &iconFile,
                                     &((itemsData + rowNumber)->icon));
#else
            FSGetCatalogInfo(&iconFile, kFSCatInfoNone, NULL, NULL, &iconSpec, NULL);
            RegisterIconRefFromIconFile(kAppSignature, 'Cat0' + rowNumber, &iconSpec,
                                        &((itemsData + rowNumber)->icon));
#endif
        }

        CFRelease(iconURLs);
        gIconsRegistered = true;
    }
    else	// the icons are already registered so we just have to get them
    {
        for (rowNumber = 0; rowNumber < kNumberOfRows; rowNumber++)
        {
            GetIconRef(kOnSystemDisk, kAppSignature, 'Cat0' + rowNumber,
                       &((itemsData + rowNumber)->icon));
        }
    }

    catNameKeys[0] = CFSTR("Panel 1");	// this is necessary because you have to use
    catNameKeys[1] = CFSTR("Panel 2");	// constant strings with CFSTR
    catNameKeys[2] = CFSTR("Panel 3");	// if we didn't do this then we couldn't get
    catNameKeys[3] = CFSTR("Panel 4");	// the strings in a loop
    catNameKeys[4] = CFSTR("Panel 5");
    catNameKeys[5] = CFSTR("Panel 6");
    catNameKeys[6] = CFSTR("Panel 7");
    catNameKeys[7] = CFSTR("Panel 8");
    catNameKeys[8] = CFSTR("Panel 9");
    catNameKeys[9] = CFSTR("Panel 10");

    for (rowNumber = 0; rowNumber < kNumberOfRows; rowNumber++)		// now get the names
    {   // and set the user panes
        rowItemData = itemsData + rowNumber;
        items[rowNumber] = (DataBrowserItemID)rowItemData;

        /* We use CFCopyLocalilzedStringFromTableInBundle here instead of
           CFCopyLocalizedString to avoid a call to CFBundleGetMainBundle every trip
           around the loop. */
        rowItemData->name = CFCopyLocalizedStringFromTableInBundle(catNameKeys[rowNumber],
                            NULL, mainBundle, NULL);
        rowItemData->userPane = *(userPanes + rowNumber);
    }

    AddDataBrowserItems(iconDataBrowser, kDataBrowserNoItem, kNumberOfRows, items,
                        kDataBrowserItemNoProperty);

    return *items;
}