コード例 #1
0
ファイル: osxstack.cpp プロジェクト: Bjoernke/livecode
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);
	}
}
コード例 #2
0
ファイル: MoreCFQ.c プロジェクト: paullalonde/B
extern pascal OSStatus CFQPropertyListCreateFromXMLCFURL(CFURLRef xmlFile, CFPropertyListMutabilityOptions options, CFPropertyListRef *result)
	// See comment in header.
{
	OSStatus  err;
	CFDataRef xmlData;
	
	assert(xmlFile != NULL);
	assert( result != NULL);
	assert(*result == NULL);

	xmlData = NULL;

	err = noErr;
	if ( ! CFURLCreateDataAndPropertiesFromResource(NULL, xmlFile, &xmlData, NULL, NULL, &err) && (err == noErr) ) {
		err = coreFoundationUnknownErr;
	}
	
	if (err == noErr) {
		*result = CFPropertyListCreateFromXMLData(NULL, xmlData, options, NULL);
		if (*result == NULL) {
			err = coreFoundationUnknownErr;
		}
	}

	CFQRelease(xmlData);

	assert( (err == noErr) == (*result != NULL) );
	
	return err;
}
コード例 #3
0
inline SQLite3StatementRef SQLite3StatementCreateWithBundleResource(SQLite3ConnectionRef connection, CFBundleRef bundle, CFStringRef type, CFStringRef name, CFStringRef subdir) {
  SQLite3StatementRef statement = NULL;
  if (connection) {
    SInt32 errorCode = 0;
    CFDictionaryRef properties = NULL;
    CFDataRef data = NULL;
    CFURLRef url = CFBundleCopyResourceURL(bundle, name, type, subdir);
    if (url) {
      if (CFURLCreateDataAndPropertiesFromResource(connection->allocator, url, &data, &properties, NULL, &errorCode)) {
        CFStringRef sql = CFStringCreateWithBytes(connection->allocator, CFDataGetBytePtr(data), CFDataGetLength(data), kCFStringEncodingUTF8, 0);
        if (sql) {
          statement = SQLite3StatementCreate(connection, sql);
          CFRelease(sql);
        }
        CFRelease(data);
        if (properties)
          CFRelease(properties);
      } else {
        // TODO: Error
      }
      CFRelease(url);
    }
  }
  return statement;
}
コード例 #4
0
static CFPropertyListRef getPropertyList()
{
  CFDataRef       xmlData;
  CFStringRef error;
  CFPropertyListRef propertyList;
  CFBundleRef appBundle;
  CFURLRef myRef;

  // locate the starter's bundle:
  appBundle = CFBundleGetMainBundle();
  
  // get a URL for the named resource
  myRef = CFBundleCopyResourceURL(appBundle, CFSTR(RSRCNAME), 
				  NULL, NULL);
  if (myRef == NULL) {
    return NULL;
  }
  
  // Load the XML data using its URL.
  CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, myRef, 
					   &xmlData, NULL, NULL, NULL);

  // convert to a Property List
  propertyList = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, xmlData, 
						 kCFPropertyListImmutable, 
						 &error);
  if (error != NULL) {
    return NULL;
  }

  return propertyList;
}
コード例 #5
0
ファイル: Resources.cpp プロジェクト: 2mc/supercollider
CFPropertyListRef Resources::getPropertyList(const char* filename)
{
    CFDataRef xmlCFDataRef;
    CFStringRef error;
    char cerror[10240];
    CFPropertyListRef myCFPropertyListRef = NULL;
    Boolean readOK;
    char  filePathBuf[PATH_MAX];
    CFStringRef filePath = this->getResourcePath(filename);
    CFStringGetCString(filePath, filePathBuf, sizeof(filePathBuf), kCFStringEncodingUTF8);
    CFURLRef fileURL = CFURLCreateFromFileSystemRepresentation (kCFAllocatorDefault, (const unsigned char*)filePathBuf, strlen (filePathBuf), false);
    if (fileURL!=NULL)  {
        readOK = CFURLCreateDataAndPropertiesFromResource( kCFAllocatorDefault, fileURL, &xmlCFDataRef, NULL, NULL, NULL);
        if (readOK)
        {
            myCFPropertyListRef = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, xmlCFDataRef, kCFPropertyListImmutable, &error);
            if (error != NULL){
                CFStringGetCString(error, cerror, sizeof(cerror), kCFStringEncodingUTF8);
                scprintf("getPropertyList error: %s\n", cerror);
            }
            CFRelease(xmlCFDataRef);
        }
        else{
            scprintf("Couldn't read Plist File %s\n", filePathBuf);
        }
    }
    return myCFPropertyListRef;
}
コード例 #6
0
// ---------------------------------
// Load the element strings from the given resource (XML) file into a CFPropertyListRef
static CFPropertyListRef xml_load(const CFStringRef pResourceName,const CFStringRef pResourceExtension)
{
	CFPropertyListRef tCFPropertyListRef = NULL;
	CFURLRef resFileCFURLRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), pResourceName, pResourceExtension, NULL);

	if (NULL != resFileCFURLRef)
	{
		CFDataRef resCFDataRef;

		if (CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, resFileCFURLRef, &resCFDataRef, nil, nil, nil))
		{
			if (NULL != resCFDataRef)
			{
				CFStringRef errorString;

				tCFPropertyListRef = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, resCFDataRef, kCFPropertyListImmutable, &errorString);
				if (NULL == tCFPropertyListRef)
					CFShow(errorString);
				CFRelease(resCFDataRef);
			}
		}
		CFRelease(resFileCFURLRef);
	}
	return tCFPropertyListRef;
}
コード例 #7
0
ファイル: qsettings_mac.cpp プロジェクト: xjohncz/qt5
bool QConfFileSettingsPrivate::readPlistFile(const QString &fileName, ParsedSettingsMap *map) const
{
    QCFType<CFDataRef> resource;
    SInt32 code;
    if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, urlFromFileName(fileName),
            &resource, 0, 0, &code))
        return false;

    QCFString errorStr;
    QCFType<CFPropertyListRef> propertyList =
        CFPropertyListCreateFromXMLData(kCFAllocatorDefault, resource, kCFPropertyListImmutable,
                                        &errorStr);

    if (!propertyList)
        return true;
    if (CFGetTypeID(propertyList) != CFDictionaryGetTypeID())
        return false;

    CFDictionaryRef cfdict =
        static_cast<CFDictionaryRef>(static_cast<CFPropertyListRef>(propertyList));
    int size = (int)CFDictionaryGetCount(cfdict);
    QVarLengthArray<CFPropertyListRef> keys(size);
    QVarLengthArray<CFPropertyListRef> values(size);
    CFDictionaryGetKeysAndValues(cfdict, keys.data(), values.data());

    for (int i = 0; i < size; ++i) {
        QString key = qtKey(static_cast<CFStringRef>(keys[i]));
        map->insert(QSettingsKey(key, Qt::CaseSensitive), qtValue(values[i]));
    }
    return true;
}
コード例 #8
0
ファイル: xcodeproj_ext.c プロジェクト: Ashton-W/Xcodeproj
/* @overload read_plist(path)
 *
 * Reads from the specified path and de-serializes the property list.
 *
 * @note This does not yet support all possible types that can exist in a valid property list.
 *
 * @note This currently only assumes to be given an Xcode project document.
 *       This means that it only accepts dictionaries, arrays, and strings in
 *       the document.
 *
 * @param [String] path  The path to the property list file.
 * @return [Hash]        The dictionary contents of the document.
 */
static VALUE
read_plist(VALUE self, VALUE path) {
  CFPropertyListRef dict;
  CFStringRef       errorString;
  CFDataRef         resourceData;
  SInt32            errorCode;

  CFURLRef fileURL = str_to_url(path);
  if (CFURLCreateDataAndPropertiesFromResource(NULL, fileURL, &resourceData, NULL, NULL, &errorCode)) {
    CFRelease(fileURL);
  }
  if (!resourceData) {
    rb_raise(rb_eArgError, "Unable to read data from `%s'", RSTRING_PTR(rb_inspect(path)));
  }

  dict = CFPropertyListCreateFromXMLData(NULL, resourceData, kCFPropertyListImmutable, &errorString);
  if (!dict) {
    rb_raise(rb_eArgError, "Unable to read plist data from `%s': %s", RSTRING_PTR(rb_inspect(path)), RSTRING_PTR(cfstr_to_str(errorString)));
  }
  CFRelease(resourceData);

  register VALUE hash = rb_hash_new();
  CFDictionaryApplyFunction(dict, hash_set, (void *)hash);
  CFRelease(dict);

  return hash;
}
コード例 #9
0
/* ------------------------------------------------------------------
 *	read_user_settings ()
 */
static CFPropertyListRef read_user_settings ( const char *in_file, CFPropertyListMutabilityOptions in_opts )
{
	CFPropertyListRef	cf_prop_list	= NULL;

	CFURLRef cf_url = CFURLCreateFromFileSystemRepresentation(NULL, (const UInt8 *)in_file, strlen(in_file), FALSE);
	if ( !cf_url ) {
		msg_error( "aod: could not create URL from %s", in_file);
		return( NULL );
	}

	SInt32 err;
	CFDataRef cf_data = NULL;
	if ( !CFURLCreateDataAndPropertiesFromResource(NULL, cf_url, &cf_data, NULL, NULL, &err) ) {
		if ( msg_verbose )
			msg_info("aod: no local user settings (%s), using defaults", in_file);
		CFRelease(cf_url);
		return( NULL );
	}

	CFStringRef cf_str_err = NULL;
	if ( cf_data ) {
		cf_prop_list = CFPropertyListCreateFromXMLData( kCFAllocatorDefault, cf_data, in_opts, &cf_str_err);
		if ( cf_prop_list )
			CFRetain(cf_prop_list);
	} else
		msg_error("aod: enable to create CFData ref for %s", in_file);

	CFRelease(cf_url);
	if ( cf_str_err )
		CFRelease( cf_str_err );
	if ( cf_data )
		CFRelease( cf_data );

	return( cf_prop_list );
} /* read_user_settings */
コード例 #10
0
// Assumes the domain has already been locked
static void _loadXMLDomainIfStale(CFURLRef url, _CFXMLPreferencesDomain *domain) {
    CFAllocatorRef alloc = __CFPreferencesAllocator();
    int idx;
    if (domain->_domainDict) {
        CFDateRef modDate;
        CFAbsoluteTime modTime;
    	CFURLRef testURL = url;

        if (CFDictionaryGetCount(domain->_domainDict) == 0) {
            // domain never existed; check the parent directory, not the child
            testURL = CFURLCreateWithFileSystemPathRelativeToBase(alloc, CFSTR(".."), kCFURLPOSIXPathStyle, true, url);
        }

        modDate = (CFDateRef )CFURLCreatePropertyFromResource(alloc, testURL, kCFURLFileLastModificationTime, NULL);
        modTime = modDate ? CFDateGetAbsoluteTime(modDate) : 0.0;

        // free before possible return. we can test non-NULL of modDate but don't depend on contents after this.
        if (testURL != url) CFRelease(testURL);
        if (modDate) CFRelease(modDate);
        
        if (modDate != NULL && modTime < domain->_lastReadTime) {            // We're up-to-date
            return;
        }
    }

	
    // We're out-of-date; destroy domainDict and reload
    if (domain->_domainDict) {
        CFRelease(domain->_domainDict);
        domain->_domainDict = NULL;
    }

    // We no longer lock on read; instead, we assume parse failures are because someone else is writing the file, and just try to parse again.  If we fail 3 times in a row, we assume the file is corrupted.  REW, 7/13/99

    for (idx = 0; idx < 3; idx ++) {
        CFDataRef data;
        if (!CFURLCreateDataAndPropertiesFromResource(alloc, url, &data, NULL, NULL, NULL) || !data) {
            // Either a file system error (so we can't read the file), or an empty (or perhaps non-existant) file
            domain->_domainDict = CFDictionaryCreateMutable(alloc, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
            break;
        } else {
            CFTypeRef pList = CFPropertyListCreateFromXMLData(alloc, data, kCFPropertyListImmutable, NULL);
            CFRelease(data);
            if (pList && CFGetTypeID(pList) == CFDictionaryGetTypeID()) {
                domain->_domainDict = CFDictionaryCreateMutableCopy(alloc, 0, (CFDictionaryRef)pList);
                CFRelease(pList);
                break;
            } else if (pList) {
                CFRelease(pList);
            }
            // Assume the file is being written; sleep for a short time (to allow the write to complete) then re-read
            __CFMilliSleep(150);
        }
    }
    if (!domain->_domainDict) {
        // Failed to ever load
        domain->_domainDict = CFDictionaryCreateMutable(alloc, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    }
    domain->_lastReadTime = CFAbsoluteTimeGetCurrent();
}
コード例 #11
0
ファイル: CFUtilities.c プロジェクト: colonist4096/darling
static CFDictionaryRef _CFCopyVersionDictionary(CFStringRef path)
{
  CFURLRef url;
  CFDataRef resourceData;
  Boolean status;
  SInt32 errorCode;
  CFErrorRef err;
  CFPropertyListRef plist;

  url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, 0);
  status = CFURLCreateDataAndPropertiesFromResource(NULL, url, &resourceData,
		  NULL, NULL, &errorCode);

  if (!status)
  {
	  CFRelease(url);
	  return NULL;
  }

  plist = CFPropertyListCreateWithData(NULL, resourceData, kCFPropertyListImmutable,
		  NULL, &err);

  CFRelease(resourceData);
  CFRelease(url);

  return plist;
}
コード例 #12
0
static WTF::RetainPtr<CFDictionaryRef> readPListFile(CFStringRef fileName, bool createFile, CFBundleRef bundle)
{
    if (createFile) {
        BP_CreatePluginMIMETypesPreferencesFuncPtr funcPtr =
            (BP_CreatePluginMIMETypesPreferencesFuncPtr)CFBundleGetFunctionPointerForName(bundle, CFSTR("BP_CreatePluginMIMETypesPreferences"));
        if (funcPtr)
            funcPtr();
    }

    WTF::RetainPtr<CFDictionaryRef> map;
    WTF::RetainPtr<CFURLRef> url =
        CFURLCreateWithFileSystemPath(kCFAllocatorDefault, fileName, kCFURLPOSIXPathStyle, false);

    CFDataRef resource = 0;
    SInt32 code;
    if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, url.get(), &resource, 0, 0, &code))
        return map;

    WTF::RetainPtr<CFPropertyListRef> propertyList =
            CFPropertyListCreateFromXMLData(kCFAllocatorDefault, resource, kCFPropertyListImmutable, 0);

    CFRelease(resource);

    if (!propertyList)
        return map;

    if (CFGetTypeID(propertyList.get()) != CFDictionaryGetTypeID())
        return map;

    map = static_cast<CFDictionaryRef>(static_cast<CFPropertyListRef>(propertyList.get()));
    return map;
}
コード例 #13
0
CFArrayRef copyTrustedAppListFromBundle(CFStringRef bundlePath, CFStringRef trustedAppListFileName)
{
	CFStringRef errorString = nil;
    CFURLRef bundleURL,trustedAppsURL = NULL;
    CFBundleRef secBundle = NULL;
	CFPropertyListRef trustedAppsPlist = NULL;
	CFDataRef xmlDataRef = NULL;
	SInt32 errorCode;
    CFArrayRef trustedAppList = NULL;
	CFMutableStringRef trustedAppListFileNameWithoutExtension = NULL;

    // Make a CFURLRef from the CFString representation of the bundleÕs path.
    bundleURL = CFURLCreateWithFileSystemPath(
        kCFAllocatorDefault,bundlePath,kCFURLPOSIXPathStyle,true);

	CFRange wholeStrRange;

	if (!bundleURL)
        goto xit;

    // Make a bundle instance using the URLRef.
    secBundle = CFBundleCreate(kCFAllocatorDefault,bundleURL);
    if (!secBundle)
        goto xit;

	trustedAppListFileNameWithoutExtension =
		CFStringCreateMutableCopy(NULL,CFStringGetLength(trustedAppListFileName),trustedAppListFileName);
	wholeStrRange = CFStringFind(trustedAppListFileName,CFSTR(".plist"),0);

	CFStringDelete(trustedAppListFileNameWithoutExtension,wholeStrRange);

    // Look for a resource in the bundle by name and type
    trustedAppsURL = CFBundleCopyResourceURL(secBundle,trustedAppListFileNameWithoutExtension,CFSTR("plist"),NULL);
    if (!trustedAppsURL)
        goto xit;

    if ( trustedAppListFileNameWithoutExtension )
		CFRelease(trustedAppListFileNameWithoutExtension);

	if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault,trustedAppsURL,&xmlDataRef,NULL,NULL,&errorCode))
        goto xit;

	trustedAppsPlist = CFPropertyListCreateFromXMLData(kCFAllocatorDefault,xmlDataRef,kCFPropertyListImmutable,&errorString);
    trustedAppList = (CFArrayRef)trustedAppsPlist;

xit:
    if (bundleURL)
        CFRelease(bundleURL);
    if (secBundle)
        CFRelease(secBundle);
    if (trustedAppsURL)
        CFRelease(trustedAppsURL);
    if (xmlDataRef)
        CFRelease(xmlDataRef);
    if (errorString)
        CFRelease(errorString);

    return trustedAppList;
}
コード例 #14
0
ファイル: http.cpp プロジェクト: gamefreak/antares
void get(const StringSlice& url, WriteTarget out) {
    cf::Url cfurl(url);
    cf::Data cfdata;
    SInt32 error;
    if (CFURLCreateDataAndPropertiesFromResource(
            NULL, cfurl.c_obj(), &cfdata.c_obj(), NULL, NULL, &error)) {
        write(out, cfdata.data());
    } else {
        throw Exception(format("Couldn't load requested url {0}", url));
    }
}
コード例 #15
0
ファイル: cfutilities.cpp プロジェクト: Proteas/codesign
//
// CFURLAccess wrappers for specific purposes
//
CFDataRef cfLoadFile(CFURLRef url)
{
	assert(url);
	CFDataRef data;
	SInt32 error;
	if (CFURLCreateDataAndPropertiesFromResource(NULL, url,
		&data, NULL, NULL, &error)) {
		return data;
	} else {
		secdebug("cfloadfile", "failed to fetch %s error=%d", cfString(url).c_str(), int(error));
		return NULL;
	}
}
コード例 #16
0
ファイル: remotevstclient.cpp プロジェクト: griels/wacvst
RemoteVSTClient::RemoteVSTClient(CFBundleRef bundle, audioMasterCallback theMaster, AEffect *theEffect, bool showGUI) :
    RemotePluginClient(theMaster, theEffect)
{
	m_bundle = bundle;
	m_audioMaster = theMaster;
	pid_t child;

	SInt32 errorCode;
	CFDataRef data;
	CFURLRef configUrl = CFBundleCopyResourceURL(bundle, CFSTR("config"), CFSTR("plist"), NULL);
	if (configUrl == 0) {
		return;
	}
	CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, configUrl, &data, NULL, NULL, &errorCode);
	m_props = (CFDictionaryRef) CFPropertyListCreateFromXMLData( kCFAllocatorDefault, data, kCFPropertyListImmutable, NULL);

	std::string dllName(CFStringGetCStringPtr(get_path_prop(CFSTR("plugin-name")), NULL));
    std::string arg = dllName + "," + getFileIdentifiers();
    if (showGUI) arg = "-g " + arg;
	const char *argStr = arg.c_str();

	CFURLRef server_url = CFBundleCopyResourceURL(m_bundle, CFSTR("dssi-vst-server.exe"), CFSTR("so"), NULL);
	if (server_url != NULL) {
		CFStringRef server_path = CFURLCopyFileSystemPath(server_url, kCFURLPOSIXPathStyle);
		if (server_path != NULL) {
			const char *c_server_path = CFStringGetCStringPtr(server_path, NULL);
			CFStringRef wine_path =  (CFStringRef) CFDictionaryGetValue(m_props, CFSTR("wine-path"));
			if (wine_path != NULL) {
				const char *c_wine_path = CFStringGetCStringPtr(wine_path, NULL);	
				std::cerr << "RemoteVSTClient: executing " << c_server_path << "\n";
				// if no dispaly environment guess...
				// setenv("DISPLAY", ":0", 0);
				setenv("DYLD_FALLBACK_LIBRARY_PATH", "/usr/X11/lib:/usr/lib", 0);
				if ((child = fork()) < 0) {
					cleanup();
					throw((std::string)"Fork failed");
				} else if (child == 0) { // child process
					if (execlp(c_wine_path, "wine", c_server_path, argStr, NULL)) {
						perror("Exec failed");
						exit(1);
					}
				}
				syncStartup();
				return;
			}
		}
	}
	cleanup();
	throw((std::string)"Failed to find dssi-vst-server executable");
	return;
 }
コード例 #17
0
OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize)
{
    // load the actual file
    CFDataRef fileData = nil;
    CFDictionaryRef propertyDictionary = nil;
    SInt32 errorCode;
    if (CFURLCreateDataAndPropertiesFromResource(NULL, url, &fileData, &propertyDictionary, nil, &errorCode)) {
        
        CFIndex dataLength = CFDataGetLength(fileData);
        UInt8 *bytes = (UInt8 *)CFDataGetBytePtr(fileData);
        long pages = dataLength / ONE_LCD_FRAME_BYTESIZE;
        CGSize lcdSize = CGSizeMake(LCD_FRAME_PIXEL_WIDTH, LCD_FRAME_PIXEL_HEIGHT * pages);
        CGContextRef cgContext = QLThumbnailRequestCreateContext(thumbnail, lcdSize, true, NULL);
        if(cgContext) {
            
            CGColorRef lcdForegroundColor = CGColorCreateGenericRGB(0.467, 0.522, 0.047, 1.000);
            CGColorRef lcdBackgroundColor = CGColorCreateGenericRGB(0.227, 0.192, 0.000, 1.000);
            CGContextSetFillColorWithColor(cgContext, lcdBackgroundColor);
            CGContextFillRect(cgContext, CGRectMake(0,0,lcdSize.width,lcdSize.height));
            
            CGPoint origin = CGPointMake(0,0);
            while (pages-- > 0) {
                CGContextSetFillColorWithColor(cgContext, lcdForegroundColor);
                //                CGContextFillRect(cgContext, CGRectMake(origin.x,origin.y,10,10));
                for (int y=0;y<9;y++) {
                    for (int x=0; x < LCD_FRAME_PIXEL_WIDTH; x++) {
                        UInt8 byte = bytes[y*LCD_FRAME_PIXEL_WIDTH + (LCD_FRAME_PIXEL_WIDTH - x - 1)];
                        if (byte > 0) {
                            UInt8 byteMask = 1;
                            for (int littleY = 0; littleY < 8; littleY++) {
                                if ((byte & (byteMask << littleY))) {
                                    CGContextFillRect(cgContext, CGRectMake(origin.x + x,origin.y + y*8 + littleY,1,1));
                                }
                            }
                        }
                    }
                }
                origin.y += 68;
                bytes    += ONE_LCD_FRAME_BYTESIZE;
            }
            
            // When we are done with our drawing code QLPreviewRequestFlushContext() is called to flush the context
            QLThumbnailRequestFlushContext(thumbnail, cgContext);
        }
        CFRelease(cgContext);
        CFRelease(fileData);
        CFRelease(propertyDictionary);
    }
    return noErr;
}
コード例 #18
0
const void *
macosx_parse_plist(const char *path)
{
  CFPropertyListRef plist = NULL;
  const char url_header[] = "file://";
  char *url_text = NULL;
  CFURLRef url = NULL;
  CFAllocatorRef cf_alloc = kCFAllocatorDefault;
  size_t url_text_len = ((sizeof(url_header) - 1UL) + strlen(path) + 1UL);
  url_text = (char *)xmalloc(url_text_len);

  /* Create URL text for the Info.plist file: */
  strcpy(url_text, url_header);
  strcat(url_text, path);

  /* Generate a CoreFoundation URL from the URL text: */
  url = CFURLCreateWithBytes(cf_alloc, (const UInt8 *)url_text,
			     url_text_len, kCFStringEncodingUTF8, NULL);
  if (url)
    {
      /* Extract the contents of the file into a CoreFoundation data
	 buffer.  */
      CFDataRef data = NULL;
      if (CFURLCreateDataAndPropertiesFromResource(cf_alloc, url, &data,
						   NULL, NULL, NULL)
          && (data != NULL))
	{
	  /* Create the property list from XML data or from the binary
	     plist data.  */
	  plist = CFPropertyListCreateFromXMLData(cf_alloc, data,
						  kCFPropertyListImmutable,
						  NULL);
	  CFRelease(data);
	  if (plist != NULL)
	    {
	      /* Make sure the property list was a CFDictionary, free it
               * and NULL the pointer if it was not as such: */
	      if (CFGetTypeID(plist) != CFDictionaryGetTypeID())
		{
		  CFRelease(plist);
		  plist = NULL;
		}
	    }
	}
      CFRelease(url);
    }

  xfree(url_text);
  return plist;
}
コード例 #19
0
ファイル: AquaticPrime.c プロジェクト: samdeane/AquaticPrime
CFDictionaryRef APCreateDictionaryForLicenseFile(CFURLRef path)
{
    // Read the XML file
    CFDataRef data;
    SInt32 errorCode;
    Boolean status;
    status = CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, path, &data, NULL, NULL, &errorCode);
    
    if (errorCode || status != true)
        return NULL;
    
    CFDictionaryRef licenseDictionary = APCreateDictionaryForLicenseData(data);
    CFRelease(data);
    return licenseDictionary;
}
コード例 #20
0
ファイル: main.c プロジェクト: Frederikus/eid-mw
CFDictionaryRef CreateDictionaryFromPlist(CFStringRef stringPlist, SInt32 *errorCode)
{
    CFDataRef dataRef;
    CFStringRef errorStringRef;
    
    CFURLRef fileURLRef = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,stringPlist,kCFURLPOSIXPathStyle,false);
    Boolean status = CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault,fileURLRef,&dataRef,NULL,NULL,errorCode);
    if (!status) {
        //error
    }
    CFDictionaryRef dictRef = CFPropertyListCreateFromXMLData(kCFAllocatorDefault,dataRef,
                                                              kCFPropertyListMutableContainersAndLeaves,&errorStringRef);
    CFRelease(fileURLRef);
    CFRelease(dataRef);
    return dictRef;
}
コード例 #21
0
static CFDictionaryRef
__copyTemplates()
{
	CFBundleRef     bundle;
	CFErrorRef	error		= NULL;
	Boolean		ok;
	CFDictionaryRef templates;
	CFURLRef	url;
	CFDataRef       xmlTemplates    = NULL;

	bundle = _SC_CFBundleGet();
	if (bundle == NULL) {
		return NULL;
	}

	url = CFBundleCopyResourceURL(bundle, CFSTR("NetworkConfiguration"), CFSTR("plist"), NULL);
	if (url == NULL) {
		return NULL;
	}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated"
	ok = CFURLCreateDataAndPropertiesFromResource(NULL, url, &xmlTemplates, NULL, NULL, NULL);
#pragma GCC diagnostic pop
	CFRelease(url);
	if (!ok || (xmlTemplates == NULL)) {
		return NULL;
	}

	// convert the XML data into a property list
	templates = CFPropertyListCreateWithData(NULL, xmlTemplates, kCFPropertyListImmutable, NULL, &error);
	CFRelease(xmlTemplates);
	if (templates == NULL) {
		if (error != NULL) {
			SCLog(TRUE, LOG_DEBUG, CFSTR("could not load SCNetworkConfiguration templates: %@"), error);
			CFRelease(error);
		}
		return NULL;
	}

	if (!isA_CFDictionary(templates)) {
		CFRelease(templates);
		return NULL;
	}

	return templates;
}
コード例 #22
0
CFPropertyListRef	 ReadPresetFromPresetFile (char* filePath)
{	
	if (!filePath)
		return NULL;
	
	FSRef ref;
	if (FSPathMakeRef((UInt8 *)filePath, &ref, NULL))
		return NULL;
		
	CFDataRef			resourceData = NULL;
	CFPropertyListRef   theData = NULL;
	CFStringRef			errString = NULL;
	CFURLRef			fileURL = CFURLCreateFromFSRef (kCFAllocatorDefault, &ref);
		if (fileURL == NULL) {
			goto home;
		}
		
	SInt32				result;
    
   // Read the XML file.
   Boolean status; status = CFURLCreateDataAndPropertiesFromResource (kCFAllocatorDefault, fileURL,
                                                                &resourceData,	// place to put file data
                                                                NULL, NULL, &result);
        if (status == false || result) {
            goto home;
        }
    
	theData = CFPropertyListCreateFromXMLData (kCFAllocatorDefault, resourceData,  
													kCFPropertyListImmutable, &errString);
        if (theData == NULL || errString) {
            if (theData)
				CFRelease (theData);
			theData = NULL;
			goto home;
       }
	
home:
	if (fileURL)
		CFRelease (fileURL);
	if (resourceData)
		CFRelease (resourceData);
    if (errString)
		CFRelease (errString);
		
	return theData;
}
コード例 #23
0
ファイル: iPoTApi.cpp プロジェクト: blitmaster/T-PoT
// Translates an iPod binary Property-list into a text property list.
//
// Returns:
//		true	on success
//		false	on failure
//
bool CiPoTApi::TranslatePLIST(char *originalFile, char *newFile)
{
	CFPropertyListRef propertyList;
	CFURLRef fileURL;
	CFStringRef inputFile, errorString;
	CFDataRef resourceData;
	Boolean status;
	SInt32 errorCode;
	bool ok = false;

	// Create a URL that specifies the file we will create to hold the XML data.
	inputFile = CFStringCreateWithCString(kCFAllocatorDefault, originalFile, kStrEncoding);
	fileURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, inputFile, kPathStyle, false);
	if (!fileURL)
		return false;
	// Read the XML file.
	status = CFURLCreateDataAndPropertiesFromResource(
		kCFAllocatorDefault, fileURL, &resourceData, NULL, NULL, &errorCode);
	if (resourceData) {
		// Reconstitute the dictionary using the XML data.
		propertyList = CFPropertyListCreateFromXMLData(
			kCFAllocatorDefault, resourceData,kCFPropertyListImmutable, &errorString);
		if (propertyList != NULL) {
			CFStringRef outputFile;
			CFDataRef xmlData;
			Boolean status;
			SInt32 errorCode;
			
			CFRelease(fileURL);
			outputFile = CFStringCreateWithCString(kCFAllocatorDefault, newFile, kStrEncoding);
			fileURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, outputFile, kPathStyle, false);
			// Convert the property list into XML data.
			xmlData = CFPropertyListCreateXMLData(kCFAllocatorDefault, propertyList);
			// Write the XML data to the file.
			status = CFURLWriteDataAndPropertiesToResource(fileURL, xmlData, NULL, &errorCode);
			ok = status ? true : false;
			CFRelease(xmlData);
			CFRelease(outputFile);
			CFRelease(propertyList);
		}
	}
	CFRelease(inputFile);
	CFRelease(fileURL);
	return ok;
}
コード例 #24
0
static CFDictionaryRef _CFCopyVersionDictionary(CFStringRef path) {
    CFPropertyListRef plist = NULL;
    CFDataRef data;
    CFURLRef url;

    url = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, path, kCFURLPOSIXPathStyle, false);
    if (url && CFURLCreateDataAndPropertiesFromResource(kCFAllocatorSystemDefault, url, &data, NULL, NULL, NULL)) {
	plist = CFPropertyListCreateFromXMLData(kCFAllocatorSystemDefault, data, kCFPropertyListMutableContainers, NULL);
	CFRelease(data);
    }
    if (url) CFRelease(url);
    
    if (plist) {
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
	CFBundleRef locBundle = NULL;
	CFStringRef fullVersion, vers, versExtra, build;
	CFStringRef versionString = _CFCopyLocalizedVersionKey(&locBundle, _kCFSystemVersionProductVersionStringKey);
	CFStringRef buildString = _CFCopyLocalizedVersionKey(&locBundle, _kCFSystemVersionBuildStringKey);
	CFStringRef fullVersionString = _CFCopyLocalizedVersionKey(&locBundle, CFSTR("FullVersionString"));
	if (locBundle) CFRelease(locBundle);

        // Now build the full version string
        if (CFEqual(fullVersionString, CFSTR("FullVersionString"))) {
            CFRelease(fullVersionString);
            fullVersionString = CFStringCreateWithFormat(kCFAllocatorSystemDefault, NULL, CFSTR("%@ %%@ (%@ %%@)"), versionString, buildString);
        }
        vers = (CFStringRef)CFDictionaryGetValue((CFDictionaryRef)plist, _kCFSystemVersionProductVersionKey);
        versExtra = (CFStringRef)CFDictionaryGetValue((CFDictionaryRef)plist, _kCFSystemVersionProductVersionExtraKey);
        if (vers && versExtra) vers = CFStringCreateWithFormat(kCFAllocatorSystemDefault, NULL, CFSTR("%@ %@"), vers, versExtra);
        build = (CFStringRef)CFDictionaryGetValue((CFDictionaryRef)plist, _kCFSystemVersionBuildVersionKey);
        fullVersion = CFStringCreateWithFormat(kCFAllocatorSystemDefault, NULL, fullVersionString, (vers ? vers : CFSTR("?")), build ? build : CFSTR("?"));
        if (vers && versExtra) CFRelease(vers);
        
	CFDictionarySetValue((CFMutableDictionaryRef)plist, _kCFSystemVersionProductVersionStringKey, versionString);
	CFDictionarySetValue((CFMutableDictionaryRef)plist, _kCFSystemVersionBuildStringKey, buildString);
	CFDictionarySetValue((CFMutableDictionaryRef)plist, CFSTR("FullVersionString"), fullVersion);
 	CFRelease(versionString);
	CFRelease(buildString);
	CFRelease(fullVersionString);
        CFRelease(fullVersion);
#endif
    }    
    return (CFDictionaryRef)plist;
}
コード例 #25
0
ファイル: prelink.c プロジェクト: OpenDarwin-CVS/SEDarwin
static CFMutableDictionaryRef copyInfoDict(CFBundleRef bundle)
{
    CFMutableDictionaryRef infoDict = NULL;
    CFURLRef		   infoDictURL;
    CFDataRef		   data;

    infoDictURL = _CFBundleCopyInfoPlistURL(bundle);
    if (infoDictURL)
    {
	if (CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, infoDictURL, &data,
		    NULL, NULL, NULL))
	{
	    infoDict = (CFMutableDictionaryRef) CFPropertyListCreateFromXMLData(kCFAllocatorDefault,
						data, kCFPropertyListMutableContainers, NULL);
	}
	CFRelease(infoDictURL);
    }
    return( infoDict );
}
コード例 #26
0
ファイル: HID_Name_Lookup.c プロジェクト: CarlKenner/gz3doom
/*************************************************************************
 *
 * hu_LoadFromXMLFile( inCFURLRef )
 *
 * Purpose: load a property list from an XML file
 *
 * Inputs: inCFURLRef			- URL for the file
 *
 * Returns: CFPropertyListRef - the data
 */
static CFPropertyListRef hu_LoadFromXMLFile(CFURLRef inCFURLRef) {
	CFDataRef xmlCFDataRef;
	CFPropertyListRef myCFPropertyListRef = NULL;
	
	// Read the XML file.
	SInt32 error;
	if ( CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, inCFURLRef, &xmlCFDataRef, NULL, NULL, &error) ) {
		CFStringRef errorString;
		// Reconstitute the dictionary using the XML data.
		myCFPropertyListRef = CFPropertyListCreateFromXMLData(kCFAllocatorDefault,
		                                                      xmlCFDataRef,
		                                                      kCFPropertyListImmutable,
		                                                      &errorString);
		// Release the XML data
		CFRelease(xmlCFDataRef);
	}
	
	return (myCFPropertyListRef);
}   // hu_LoadFromXMLFile
コード例 #27
0
ファイル: 22249_1.c プロジェクト: B-Rich/osf_db
int main() {
	SInt32 ret_code;
	UInt8 *myPtr;
	CFDataRef myData;
	CFStringRef url = CFSTR("http://localhost:8080/index.html");
	
	printf("Requesting URL\n");
	
	CFURLRef myURL = CFURLCreateWithString(kCFAllocatorDefault, url, NULL);
	CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, myURL, &myData,
											NULL, NULL, &ret_code);
	
	if (myData != NULL) {
		myPtr = (UInt8 *)CFDataGetBytePtr(myData);
		printf("Data: %s\n", myPtr);
	}
	
	CFRelease(myURL);
	CFRelease(url);
}
コード例 #28
0
static CFPropertyListRef CreateMyPropertyListFromFile(const char *posixfile)
{
	CFPropertyListRef propertyList;
	CFStringRef       errorString;
	CFDataRef         resourceData;
	SInt32            errorCode;
	CFURLRef          fileURL;

	fileURL = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, posixfile, strlen(posixfile), false);
	if (!fileURL)
		fprintf(stderr, "%s: CFURLCreateFromFileSystemRepresentation(%s) failed\n", argv0, posixfile);
	if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, fileURL, &resourceData, NULL, NULL, &errorCode))
		fprintf(stderr, "%s: CFURLCreateDataAndPropertiesFromResource(%s) failed: %d\n", argv0, posixfile, (int)errorCode);
	propertyList = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, resourceData, kCFPropertyListImmutable, &errorString);
	if (!propertyList)
		fprintf(stderr, "%s: propertyList is NULL\n", argv0);
	CFRelease(resourceData);

	return propertyList;
}
コード例 #29
0
ファイル: plist.cpp プロジェクト: aosm/samba
static CFPropertyListRef load_plist_from_path(const char * path)
{
    CFURLRef	    url = NULL;
    CFDataRef	    data = NULL;
    CFStringRef	    err = NULL;

    CFPropertyListRef plist = NULL;

    url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,
		    (const UInt8 *)path, strlen(path),
		    false /* isDirectory */);

    if (url == NULL) {
	VERBOSE("failed to build CFURL for '%s'\n", path);
	goto done;
    }

    if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault,
			url, &data, NULL, NULL, NULL)) {
	VERBOSE("failed to read CFURL data for '%s'\n", path);
	goto done;
    }

    /* Despite the name, this actually reads both binary and XML plists. */
    plist = CFPropertyListCreateFromXMLData(kCFAllocatorDefault,
		    data, kCFPropertyListImmutable, &err);
    if (!plist) {
	char errbuf[256];

	CFStringGetCString(err, errbuf, sizeof(errbuf), kCFStringEncodingUTF8);
	VERBOSE("plist parse error for '%s': %s\n",
	    path, errbuf);
    }

done:
    safe_release(err);
    safe_release(url);
    safe_release(data);

    return plist;
}
コード例 #30
0
// not used
static CFPropertyListRef XML_HIDCookieStringLoad (void)
{
	CFPropertyListRef tCFPropertyListRef = NULL;
	CFURLRef resFileCFURLRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(),CFSTR("HID_cookie_strings"),CFSTR("plist"),NULL);
	CFDataRef resCFDataRef;

	if (CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault,resFileCFURLRef,&resCFDataRef,nil,nil,nil))
	{
		if (NULL != resCFDataRef)
		{
			CFStringRef errorString;

			tCFPropertyListRef = CFPropertyListCreateFromXMLData(kCFAllocatorDefault,resCFDataRef,kCFPropertyListImmutable,&errorString);
			if (NULL == tCFPropertyListRef)
				CFShow(errorString);
			CFRelease(resCFDataRef);
		}
	}
	if (NULL != resFileCFURLRef)
		CFRelease(resFileCFURLRef);
	return tCFPropertyListRef;
}