Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > getting HFSCreatorCode - how to treat Bundled Apps vs. monolithic apps?

getting HFSCreatorCode - how to treat Bundled Apps vs. monolithic apps?
Thread Tools
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Nov 14, 2001, 05:20 AM
 
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 ]
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Nov 14, 2001, 05:38 AM
 
Why is it that I try to figure this out on my own for a couple of days - before bothering the good people of this forum.

Then as soon as I have posted the question I spot this:

"If you need to further determine if path is a package, use NSWorkspace's isFilePackageAtPath:."


which makes it easier to spot packages - but my question remains - should I append "contents/macos/TheAppName" to the path to get the actual app?

What if the user has changed the name of the App-bundle?

Digs
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Nov 14, 2001, 08:01 AM
 
OK I've worked it out:

Why is it that I always find the piece of documentation that's been hiding from me *just* after I post to these boards? Typical! At least it means I'm beginning to work things out for myself

if anyone is interested here is my code - it's to do with checking for bundles:

- (IBAction)setProtocolInfoid)sender
{
int result;

NSDictionary *attributesDictionary;

NSString *theCFBundleSignature;
NSNumber *theOldSchoolCreatorCode;
NSBundle *theAppBundle;

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(@"Path of chosen app (aFile): %@",aFile);

theAppBundle = [NSBundle bundleWithPath:aFile];
if (nil == theAppBundle)
// path leads to a monolithic app
{
attributesDictionary=[theDefaultFileManager fileAttributesAtPath:aFile traverseLink:YES];
if (!attributesDictionary)
{
// no file here.
NSLog(@"Path is incorrect! There is no executable file here.");
}
else
{
// Get the CreatorCode
theOldSchoolCreatorCode= [attributesDictionary objectForKey:@"NSFileHFSCreatorCode"];
NSLog (@"theOldSchoolCreatorCode %@", theOldSchoolCreatorCode);
}
} else
{
// path leads to a bundle
// Get the CFBundleSignature.
aFile = [theAppBundle executablePath];
NSLog(@"aFile is a path to a bundle. New path to executable (aFile): %@",aFile);
theCFBundleSignature=[[theAppBundle infoDictionary] objectForKey:@"CFBundleSignature"];
NSLog (@"The CFBundleSignature: %@", theCFBundleSignature);
}
} // for (i=0; i<count; i++) - looping thru chosen files
} // if (result == NSOKButton)
} // - (IBAction)setProtocolInfoid)sender
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:54 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2