Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I read pref files for other Apps



On 5/14/03 9:08 PM, Scott Mitchell didst favor us with:

> Well it is not my Quoting style. Mail seems to be doing this for some reason.
> I have no idea why.

Well, I didn't mean you personally, but your e-mail program. So hard to find
good software these days. LOL
>
> Well I have no idea if the Pref file is maintained by CFPreferences. The thing
> is the Pref file is created by the installer, they put the SN and other info
> in there and then, I don;t think they do anything else with it. The apps that
> it installs are supposed to check to see if the package was installed. to do
> that we need to check for the SN.

The issue is whether or not it was created with CFPreferences, or more
specifically, the format of the data in the file. If it contains standard CF
data like CFDictionaries and CFArrays, then you can read it yourself and use
CF APIs to parse it. In any case, you obviously have to know the format of
the file to find anything in it.
>
> I would love to do this with other Core foundation API's, but I don't know
> how. That is why I posted this message. I need to look for a key and then i
> need to save that value off into my own preference file.

I don't have code to do exactly what you want, but it turns out it's fairly
straightforward, if a bit tedious to write.

First you need to get the contents of the file into a CFDictionaryRef:

// fileContents is a buffer containing the contents of the file.

CFDataRef plistData = CFDataCreate( kCFAllocatorDefault, (UInt8*)
fileContents, numberOfByteInFileContents );
if ( plistData )
{
CFPropertyListRef plist = CFPropertyListCreateFromXMLData(
kCFAllocatorDefault, plistData, kCFPropertyListImmutable, nil );
if ( plist )
{
CFDictionaryRef dictRef = CFDictionaryRef( plist );

success = GetValueValueFromDictionary( dictRef, &yourBuffer ); //
Your routine.

CFRelease( plist );
}

CFRelease( plistData );
}

GetValueValueFromDictionary() will either need to know something about how
the key is stored, or it will have to use various APIs from CFDictionary.h
to parse the plist. APIs like CFDictionaryGetCount(),
CFDictionaryGetValueIfPresent(), CFDictionaryGetKeysAndValues(), or whatever
you deem necessary. You may also need some stuff from CFArray.h, as some
values in the dictionary may consist of arrays.

Larry
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: How do I read pref files for other Apps (From: Scott Mitchell <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.