file extensions
file extensions
- Subject: file extensions
- From: James McCartney <email@hidden>
- Date: Tue, 10 Sep 2002 01:05:14 -0700
problem #1.
My app creates files that end in ".sc".
When I do a get info on one of these files and I want to choose an app
to open that file, I click on "Other..." since no app is listed.
I find my app, choose it, and then it appears in the menu.
Then when I click on "Change all..." I get the dialog that asks if I
really want to do that. I click continue, at which point the menu
reverts to having no app listed and still no .sc file will open with my
app.
problem #2.
My app creates files that end in ".rtf"
I want my app to open the .rtf files that I create. I have code to set
the type and creator codes when I write the file. This code succeeds
and when I click on a .rtf file I've created it opens in my app.
However if I edit this file with my app and resave it (my type creator
code again successfully sets the creator), then when I reopen it, it
opens in TextEdit. If I use Open to reopen my file I find that the
creator has reverted to zero. What is going on?
What SHOULD I do to get a .rtf file to open in my app as if the user
had set the Get Info to do that?
Here's my code:
- (BOOL)writeToFile:(NSString*) path ofType:(NSString *)aType
{
BOOL success;
NSTextStorage *textStorage = [textView textStorage];
NSRange range = NSMakeRange(0, [textStorage length]);
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
if ([textStorage containsAttachments]) {
NSFileWrapper *wrapper = [textStorage RTFDFileWrapperFromRange:
range documentAttributes: dict];
success = wrapper ? [wrapper writeToFile: path atomically:YES
updateFilenames: YES] : NO;
} else {
NSData *data = [textStorage RTFFromRange: range
documentAttributes: dict];
success = data ? [data writeToFile: path atomically: YES] : NO;
}
if (!success) return NO;
// get ready to set creator
NSFileManager *fmgr = [NSFileManager defaultManager];
// check to see what the creator was before.
{
NSMutableDictionary *attr2 = [fmgr fileAttributesAtPath: path
traverseLink: NO];
NSNumber* creator2 = [attr2 objectForKey: NSFileHFSCreatorCode];
int creatorval = [creator2 intValue];
printf("creator was %d SCjm %d\n", creatorval, 'SCjm');
}
// set creator.
NSMutableDictionary *attr = [NSMutableDictionary dictionary];
NSNumber *creator = [NSNumber numberWithInt: 'SCjm'];
[attr setObject: creator forKey: NSFileHFSCreatorCode];
success = [fmgr changeFileAttributes: attr atPath: path];
printf("write success %d\n", success);
// check to see what the creator is after.
NSMutableDictionary *attr2 = [fmgr fileAttributesAtPath: path
traverseLink: NO];
NSNumber* creator2 = [attr2 objectForKey: NSFileHFSCreatorCode];
int creatorval = [creator2 intValue];
printf("creator is %d SCjm %d\n", creatorval, 'SCjm');
return success;
}
--
--- james mccartney
_______________________________________________
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.