Re: Getting the version of a non-bundle carbon application
Re: Getting the version of a non-bundle carbon application
- Subject: Re: Getting the version of a non-bundle carbon application
- From: Nicholas Riley <email@hidden>
- Date: Thu, 9 Oct 2003 18:45:29 -0500
- Mail-followup-to: Devin Lane <email@hidden>, Cocoa-Dev List <email@hidden>
On Thu, Oct 09, 2003 at 11:23:07AM -0700, Devin Lane wrote:
>
Hello all:
>
>
I am making a program in which I need to get the version of
>
applications. For bundle applications, this is easy, as the necessary
>
information is stored in the info.plist file. However, for non-bundle
>
apps (like Resourcer), the version information is stored in the
>
resource forks. I have absolutely no idea how to use resource forks,
>
so I was wondering if anyone knows how this might be done.
It's not as if the Resource Manager is undocumented!
Another case where NS/CFBundle doesn't work (at least in Jaguar) is
with apps that have their versions stored in the 'plst' resource.
Here's some code that I use in my 'launch' command-line tool to get
version information.
SInt16 resFork = FSOpenResFile(&fsr, fsRdPerm);
OSStatus err = ResError();
if (err != noErr) {
printf("\t[can't open resource fork: %s]\n", osstatusstr(err));
} else {
Handle h = Get1Resource('plst', 0);
if ( (err = ResError()) != noErr || h == NULL) {
if (err != noErr && err != resNotFound) osstatusexit(err, "unable to read 'plst' 0 resource");
} else {
CFDataRef plstData = CFDataCreate(NULL, *h, GetHandleSize(h));
CFStringRef error;
CFPropertyListRef infoPlist = CFPropertyListCreateFromXMLData(NULL, plstData, kCFPropertyListImmutable, &error);
if (infoPlist == NULL) {
CFStringGetCString(error, tmpBuffer, STRBUF_LEN, CFStringGetSystemEncoding());
printf("\t['plst' 0 resource invalid: %s]\n", tmpBuffer);
CFRelease(error);
} else {
// mimic CFBundle logic below
bundleID = CFDictionaryGetValue(infoPlist, kCFBundleIdentifierKey);
if (bundleID != NULL) CFRetain(bundleID);
appVersion = CFDictionaryGetValue(infoPlist, CFSTR("CFBundleShortVersionString"));
if (appVersion == NULL)
appVersion = CFDictionaryGetValue(infoPlist, kCFBundleVersionKey);
if (appVersion != NULL) CFRetain(appVersion);
CFRelease(infoPlist);
}
}
VersRecHndl vers = (VersRecHndl)Get1Resource('vers', 1);
if ( (err = ResError()) != noErr || vers == NULL) {
if (err != noErr && err != resNotFound) osstatusexit(err, "unable to read 'vers' 1 resource");
} else {
if (appVersion == NULL) { // prefer 'plst' version
appVersion = CFStringCreateWithPascalString(NULL, vers[0]->shortVersion, CFStringGetSystemEncoding()); // XXX use country code instead?
}
intVersion = ((NumVersionVariant)vers[0]->numericVersion).whole;
}
CloseResFile(resFork);
}
--
=Nicholas Riley <email@hidden> | <
http://www.uiuc.edu/ph/www/njriley>
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.