• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Saving an AudioFile without an extension
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Saving an AudioFile without an extension


  • Subject: Re: Saving an AudioFile without an extension
  • From: David Duncan <email@hidden>
  • Date: Mon, 12 Jul 2004 08:34:04 -0400

On Jul 12, 2004, at 06:05 AM, Asher Vander Heiden wrote:

I'm having trouble with using the 'FSMakeFSSpec' to make a 'FSSpec' !

Don't use FSSpecs. They are quite wholeheartedly deprecated and can't even do what you are trying to use them for (for many reasons)

FSSpec fspec;
char* destFilePath = "/Users/lachlanbarratt/Desktop/NewFile";

error = FSMakeFSSpec(0,0,destFilePath,&fspec);

There are a number of reasons why this fails for you (and even more for why it would fail for others).
1) FSMakeFSSpec expects an HFS path. The equivalent (which still wouldn't work reliably) would be something like "Macintosh HD:Users:lachlanbarratt:Desktop:NewFile"
2) 0,0 is not guaranteed to be a useful volume/directory spec. *Right Now* it may point at the root of the file system, but it has pointed elsewhere in the past and may point elsewhere in the future.
3) While this may be just for your testing, the user's home folder isn't guaranteed to be in /Users. Mine isn't.

Modern file code uses either FSRefs or CFURLs. The equivalent code would be something like this.

FSRef desktopRef;
FSFindFolder(kOnAppropriateDisk, kDesktopFolderType, true, &desktopFolder);
CFURLRef desktopURL = CFURLCreateFromFSRef(NULL, &desktopRef);
CFURLRef newFileURL = CFURLCreateCopyAppendingPathComponent(NULL, desktopURL, CFSTR("NewFile"), false);

At this point newFileURL points at your new file (and you can release the desktopURL if you don't need it anymore) but you cannot get an FSRef to the new file unless it already exists (FSRefs can't reference non-existant files). But then AudioFile takes a parent folder and string anyway (just like CFURLCreateCopyAppendingPathComponent but the parent is an FSRef) so I'm not certain why you are using FSSpecs at all in this case...

I cannot explain why Apple have decided to use so many different types of strings ??? I've probably wasted about 2 weeks work just trying to satisfy all of Apples string requirements. This is the first and maybe the last time I work with Apple.

It's called legacy. Back in 1984 most of the Mac toolbox used Pascal strings for string handling and that set the precedent for future APIs to use Pascal strings (which are typed as unsigned char). Up until Carbon came to be, at which point CoreFoundation was created which provided for Unicode strings via CFString. Pascal strings have since been deprecated, along with all APIs that deal exclusively with Pascal strings for which there is a modern replacement. This includes FSSpecs.

In seeing the snippet below from Tim, I see that the code he uses is also deprecated (for using FSSpecs). Instead you should use FSSetCatalogInfo. This snippet is the modern method of setting type/creator

OSStatus SetTypeCreatorForFSRef(FSRef *inDocument, OSType inType, OSType inCreator)
{
FSCatalogInfo info;
OSStatus err;

err = ::FSGetCatalogInfo(inDocument, kFSCatInfoFinderInfo, &info, NULL, NULL, NULL);
if(err != noErr)
return err;
((FileInfo*)info.finderInfo)->fileType = inType;
((FileInfo*)info.finderInfo)->fileCreator = inCreator;
err = ::FSSetCatalogInfo(inDocument, kFSCatInfoFinderInfo, &info);
return err;
}

--
Reality is what, when you stop believing in it, doesn't go away.
Failure is not an option. It is a privilege reserved for those who try.

David Duncan
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.


References: 
 >RE: Saving an AudioFile without an extension (From: "Asher Vander Heiden" <email@hidden>)

  • Prev by Date: Re: Saving an AudioFile without an extension
  • Next by Date: Re: Saving an AudioFile without an extension (Modified by Marc Poirier)
  • Previous by thread: RE: Saving an AudioFile without an extension
  • Next by thread: Re: Saving an AudioFile without an extension
  • Index(es):
    • Date
    • Thread