Re: Getting the version string of any program
Re: Getting the version string of any program
- Subject: Re: Getting the version string of any program
- From: Stephane Sudre <email@hidden>
- Date: Wed, 9 Jun 2004 11:08:30 +0200
On mardi, juin 8, 2004, at 09:45 PM, Chaz McGarvey wrote:
Hi.
Is there a robust way to get a version number or string from any
program (bundle or not) using Cocoa or Carbon?
Not sure this is dealing with all the possible cases:
// Get Version
tBundle=[NSBundle bundleWithPath:tPath];
if (tBundle!=nil)
{
NSDictionary * tInfoDictionary;
tInfoDictionary=[tBundle infoDictionary];
if (tInfoDictionary!=nil)
{
tVersion=[tInfoDictionary objectForKey:@"CFBundleShortVersionString"];
if (tVersion==nil)
{
tVersion=@"1.0";
}
}
}
else
{
CFBundleRef tBundleRef;
short resNum=0;
tBundleRef=CFBundleCreate(NULL,(CFURLRef) [NSURL
fileURLWithPath:tPath]);
if (tBundleRef!=NULL)
{
resNum=CFBundleOpenBundleResourceMap(tBundleRef);
}
else
{
}
if (resNum!=0)
{
VersRecHndl tVersionHandle;
unsigned long tNumVersion;
tVersionHandle=(VersRecHndl) Get1IndResource('vers',1);
if (tVersionHandle!=NULL)
{
tNumVersion=*((unsigned long *)
&((*tVersionHandle)->numericVersion));
if ((tNumVersion & 0x00040000)!=0)
{
tVersion=[NSString stringWithFormat:@"%d.%d.%d",(tNumVersion &
0xFF000000)>>24, (tNumVersion & 0x00F00000)>>20, (tNumVersion &
0x000F0000)>>16];
}
else
{
tVersion=[NSString stringWithFormat:@"%d.%d",(tNumVersion &
0xFF000000)>>24, (tNumVersion & 0x00F00000)>>20];
}
}
if (tBundleRef!=NULL)
{
CFBundleCloseBundleResourceMap(tBundleRef,resNum);
// Release Memory
CFRelease(tBundleRef);
}
}
}
_______________________________________________
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.