Re: Adding a 'usro' resource
Re: Adding a 'usro' resource
- Subject: Re: Adding a 'usro' resource
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Tue, 05 Apr 2011 11:31:36 +0700
On 4 Apr 2011, at 23:38, "Gerriet M. Denkmann" <email@hidden> wrote:
> I want to make certain files to be opended by default by my own editor.
> These files might contain all sort of file extentions.
> In Finder.app I could do: File â∫‚ Always open with..., but I want to do this programmatically.
>
> I guess I have to add a 'usro' Resource (see: <http://sutes.co.uk/2009/09/creator-codes-are-not-replaced.html>).
>
> But I have great difficulties finding and understanding the relevant documentation.
>
> Also: I cannot find the 'usro' string in any header file (and Xcode does not give any information either).
>
> So, does anybody has some code snippets to share which can read, modify, write a 'usro' resource?
>
The code below seems to work - but looks like a really bad hack. (All error handling removed for brevity).
Maybe someone has a better solution?
+ (NSString *)openerForFsRef: (FSRef *)fsRef;
{
NSString *opener = nil;
SInt16 file = FSOpenResFile( fsRef, fsRdPerm );
// The total number of unique resource types in the current resource file.
ResourceCount typesCount = Count1Types();
for( short typeIndex = 1; typeIndex <= typesCount; typeIndex++ ) // iterate over all types
{
ResType theType;
Get1IndType( &theType, typeIndex );
// The total number of resources of a given type in the current resource file.
ResourceCount rsrcCount = Count1Resources( theType );
for( int rsrcIndex = 1; rsrcIndex <= rsrcCount; rsrcIndex++ ) // iterate over resources for current type
{
Handle rsrcHandle = Get1IndResource( theType, rsrcIndex );
if ( theType == NSHFSTypeCodeFromFileType( @"'usro'" ) )
{
// this probably is a bad hack - what if there are more than 255 chars in the opener string?
const unsigned char *bytes = *rsrcHandle;
NSUInteger lenn = bytes[0] - 1;
NSData *daa = [ NSData dataWithBytes: &bytes[4] length: lenn ];
opener = [ [ NSString alloc ] initWithData: daa encoding: NSUTF8StringEncoding ];
[ opener autorelease ];
};
};
};
CloseResFile( file );
return opener;
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden