Getting Applications' Creator Codes - Bundled Apps vs. Single-file Apps.
Hi there, I'm trying to get the creator code for an App selected by the user.
So far I have attempted using an NSOpenPanel to select the App then use NSFileManager to get the HFSCreatorCode. See below:
- (IBAction)setProtocolInfo

id)sender
{
int result;
NSDictionary *attributesDictionary;
CFStringRef theCreatorCode;
NSArray *fileTypes = [NSArray arrayWithObject:@"app"];
NSOpenPanel *oPanel = [NSOpenPanel openPanel];
[oPanel setAllowsMultipleSelection:NO];
result = [oPanel runModalForDirectory:nil file:nil types:fileTypes];
if (result == NSOKButton) {
NSArray *filesToOpen = [oPanel filenames];
int i, count = [filesToOpen count];
for (i=0; i<count; i++) {
NSString *aFile = [filesToOpen objectAtIndex:i];
NSLog(@"aFile: %@",aFile);
attributesDictionary=[theDefaultFileManager fileAttributesAtPath:aFile traverseLink:YES];
if (!attributesDictionary)
{
NSLog(@"Path is incorrect!");
}
else
{
NSLog (@"attributesDictionary: %@", attributesDictionary);
NSLog(@"theCreatorCode: %@",[attributesDictionary fileHFSCreatorCode] );
}
}
}
}
This is all fine for old-school apps that are contained within one file (e.g. many classic apps, Interarchy), however if the user chooses a bundled app (most apps) then the path aFile is a path to a directory (the .app bundle), and therefore has no creator code.
Should I be checking if aPath is actually a directory, and if so appending "contents/macos/WhateverTheAppNameIs" to get the actual executable file (and its HFSCreatorCode.)?
Surely there is a better way.
for an example of what is logged when choosing mail and interarchy see below:
2001-11-14 11:28:17.427 internetpref[415] aFile: /Applications/Mail.app
2001-11-14 11:28:17.476 internetpref[415] attributesDictionary: {
NSFileExtensionHidden = 1;
NSFileGroupOwnerAccountName = admin;
NSFileModificationDate = 2001-11-10 01:10:57 +0000;
NSFileOwnerAccountName = root;
NSFilePosixPermissions = 509;
NSFileReferenceCount = 3;
NSFileSize = 264;
NSFileSystemFileNumber = 24999;
NSFileSystemNumber = 234881034;
NSFileType = NSFileTypeDirectory;
}
2001-11-14 11:28:17.476 internetpref[415] theCreatorCode: (null)
vs:
2001-11-14 11:30:52.778 internetpref[422] aFile: /Applications/Interarchy 5.0.1/Interarchy 5.0.1
2001-11-14 11:30:52.804 internetpref[422] attributesDictionary: {
NSFileExtensionHidden = 0;
NSFileGroupOwnerAccountName = admin;
NSFileHFSCreatorCode = 1098015592;
NSFileHFSTypeCode = 1095782476;
NSFileModificationDate = 2001-09-14 18:28:13 +0100;
NSFileOwnerAccountName = diggory;
NSFilePosixPermissions = 511;
NSFileReferenceCount = 1;
NSFileSize = 1841368;
NSFileSystemFileNumber = 177994;
NSFileSystemNumber = 234881034;
NSFileType = NSFileTypeRegular;
}
Any hints? Digs.
[ 11-14-2001: Message edited by: Diggory Laycock ]
[ 11-14-2001: Message edited by: Diggory Laycock ]