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 Wed, 14 May 2003 15:54:05 -0700, Scottq Mitchell <email@hidden>
wrote:
> The program that I just wrote, will soon be bundled with a bunch of different
> programs, but all the programs will be registered under the one SN. What I
> need to be able to do is read the Preference file for this bundled set of
> programs, and check to make sure that the user registered. Now I can read my
> own preferences, and I know the name of the file I need to read from, and
> keys that I need to read in there. But I can not figure out how to read the
> property list form this file. Can anyone out there give me an example of how
> to do this? I searched through the list archives, but can not seem to find
> anything related to this.

If you just store the serial # as a key/value pair then you don't need to
directly access the XML, just use the CFPreference API's.

If I'm not understanding what you're doing and you do need to access the XML
data then you can use the CF XML API's to do that:

[BEGIN]
/*

<http://developer.apple.com/techpubs/macosx/CoreFoundation/PropertyListServi
ces/Property_List_Services_ConcTask/Conceptual/CFPropertyList-4.html>
*/
/**\
|**| Here's now to load an XML file into a property list:
\**/

// Read the XML file.
status = CFURLCreateDataAndPropertiesFromResource(
kCFAllocatorDefault,
myCFURLRef,
&xmlCFDataRef, // place to put file data
NULL,
NULL,
&errorCode);

// Reconstitute the dictionary using the XML data.
myCFPropertyListRef = CFPropertyListCreateFromXMLData(
kCFAllocatorDefault,
xmlCFDataRef,
kCFPropertyListImmutable,
&errorString);

/**\
|**| Here's now to save a property list into an XML file:
\**/

// Convert the plist into XML data.
xmlCFDataRef = CFPropertyListCreateXMLData( kCFAllocatorDefault,
myCFPropertyListRef );

// Create a URL that specifies the file we will create to hold the XML
data.
myCFURLRef = CFURLCreateWithFileSystemPath( kCFAllocatorDefault,
CFSTR("test.txt"), // file path name
kCFURLHFSPathStyle, false ); // is it a directory?

// Write the XML data to the file.
status = CFURLWriteDataAndPropertiesToResource (
myCFURLRef, // URL to use
xmlCFDataRef, // data to write
NULL,
&errorCode);

// Don't forget to release all of the CF objects you're responsible for.

[END]


--
Enjoy,
George Warner,
Schizophrenic Optimization Scientist
Apple Developer Technical Support (DTS)
_______________________________________________
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.



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.