Re: Creating localized directories
Re: Creating localized directories
- Subject: Re: Creating localized directories
- From: Brian Stern <email@hidden>
- Date: Mon, 19 Mar 2007 15:29:14 -0400
On Mar 19, 2007, at 3:09 PM, Michael Watson wrote:
Well, the NSApplicationSupportDirectory constant is just an
integer, and won't tell me what the name of the directory is
supposed to be, to create it if necessary.
The app launches and looks for its support directory. If it's not
found, we want to create it, but before we do that, we want to make
sure the Application Support directory exists. If not, we need to
create it. If it's not there, I don't know what it's supposed to be
named, so I can't create it.
Looks like the only function that will handle this is FSFindFolder,
as it knows what the directory is supposed to be named before
creating it. Is that mechanism exposed anywhere else?
As far as 10.4 support goes, the app will be 10.4 and later,
anyway. Not a concern. (Already using that constant elsewhere.)
I use this function for getting those system folder paths that aren't
available from NSSearchPathForDirectoriesInDomains. You can easily
add a parameter for creating the folder to pass to FSFindFolder.
Note that non-admin users may not have permissions to create the
Application Support folder. You might prefer to create your support
directory at install time.
NSString* SystemFolderPath(OSType folderType, short domain)
{
FSRef folder;
NSString* result = nil;
OSErr err = FSFindFolder(domain, folderType, kDontCreateFolder,
&folder);
if (err == noErr)
{
CFURLRef url = CFURLCreateFromFSRef(kCFAllocatorDefault, &folder);
if (url != NULL)
{
result = [(NSURL *)url path];
CFRelease(url);
}
}
return result;
}
--
Brian Stern
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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