• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting the version string of any program
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


References: 
 >Getting the version string of any program (From: Chaz McGarvey <email@hidden>)

  • Prev by Date: Re: Insuring a path exists
  • Next by Date: Custom Dock Tile on Mac OS X 10.3
  • Previous by thread: Re: Getting the version string of any program
  • Next by thread: Re: Getting the version string of any program
  • Index(es):
    • Date
    • Thread