On Sat, Jul 25, 2009 at 10:21 PM, Kyle Sluder<kyle.slu...@gmail.com> wrote:
> Also not a safe option; other Apple apps can access the XML file, includeing
> CoreServices (for the media picker in the Open panel). Unfortunately we
> don't know how they do it and therefore can't be guaranteed that they won't
> also break if you have a lock on the database file.

Thanks for the heads up. I'm afraid the end users would be upset if
the app required iTunes to be running all of a sudden, though. So I'll
try with the Core Foundation methods for now (without locking the
file). Hopefully it won't result in a crash if the file is modified
while read, just a NULL pointer or invalid data (which is fine
considering how often the data is read, I'll just rely on the last
valid object).

CFPropertyListRef CreateMyPropertyListFromFile( CFURLRef fileURL ) {
   CFPropertyListRef propertyList;
   CFStringRef       errorString;
   CFDataRef         resourceData;
   Boolean           status;
   SInt32            errorCode;

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

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

   if (resourceData) {
        CFRelease( resourceData );
   } else {
        CFRelease( errorString );
    }
        
   return propertyList;
}
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to