Re: FSSpec for saving a movie with FlattenMovieData() from an NSString*?
Re: FSSpec for saving a movie with FlattenMovieData() from an NSString*?
- Subject: Re: FSSpec for saving a movie with FlattenMovieData() from an NSString*?
- From: Aki Inoue <email@hidden>
- Date: Mon, 22 Apr 2002 01:42:09 -0700
Probably you're bitten by the FSRef limitation that it can only
represents existing files.
You need a little trick here. You have to get the FSRef for the parent
directory first, then, create the file. FlattenMovieData doesn't care
about the file's existence.
NSString *path;
NSString *directory = [path stringByDeletingLastPathComponent];
NSString *filename = [path lastPathComponent];
FSRef directoryRef;
FSSpec fileSpec;
OSStatus status;
UniChar buffer[255]; // HFS+ filename max is 255
status = FSPathMakeRef([directory fileSystemRepresentation],
&directoryRef, NULL);
[filename getCharacters:buffer];
status = FSCreateFileUnicode(&directoryRef, [filename length],
buffer, kFSCatInfoNone, NULL, NULL, &fileSpec);
Of course, you could pre-create the file with NSFileManager & use the
path->FSRef->FSSpec technique if you prefer that.
Aki
On 2002.04.21, at 23:08, Timothy J. Wood wrote:
On Sunday, April 21, 2002, at 10:22 PM, Michael B. Johnson wrote:
[...[
I can't figure out how to go from @"/tmp/foo.mov" to an FSSpec that it
likes.
[...]
NSURL *fileUrl = [NSURL fileURLWithPath:fileName];
FSSpec fileFSSpec;
FSRef fileFSRef;
// get an FSRef for our file
Boolean gotFSRef = CFURLGetFSRef((CFURLRef)fileUrl,
&fileFSRef);
// get an FSSpec for the same file
status = FSGetCatalogInfo(&fileFSRef, kFSCatInfoNone, NULL,
NULL, &fileFSSpec, NULL);
This looks right to me. We have some working code in
OmniFoundation/OFCodeFragment (and similar code a couple other places
in our frameworks) that does:
CFURLRef url;
FSRef fsRef;
FSSpec fsSpec;
OSErr err;
Boolean success;
path = [aPath copy];
url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
(CFStringRef)path, kCFURLPOSIXPathStyle, false);
success = CFURLGetFSRef(url, &fsRef);
CFRelease(url);
if (!success) {
...
}
err = FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &fsSpec,
NULL);
if (err != noErr) {
...
}
... and then proceeds to use the fsSpec to open a code fragment.
So, maybe the problem is some subtle difference between +[NSURL
fileURLWithPath:] and CFURLCreateWithFileSystemPath() or perhaps you
are getting a valid FSSpec and something is going wrong after that
point.
-tim
_______________________________________________
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.
_______________________________________________
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.