Re: Storing file pathes... what to do if the user move/change them ?
Re: Storing file pathes... what to do if the user move/change them ?
- Subject: Re: Storing file pathes... what to do if the user move/change them ?
- From: "John C. Daub" <email@hidden>
- Date: Wed, 11 May 2005 06:51:01 -0500
on 5/11/05 4:33 AM, Aurélien Hugelé at email@hidden wrote:
> suppose i'm working on a *mini* application that links files to
> "projects". Each project has a name and can have many files attached
> to it.
>
> Currently I'm storing the file pathes (NSString*) in an NSArray that
> i save to disk at the termination of the app. At next launch i read
> this archived NSArray and display projects with their attached files.
> I use NSFIleManager.
> This is very easy to do, but has a major drawback : what happens if
> the user move one of the files ? or if he renames one ?
>
> I've seen some applications that are able to keep the "links" alive,
> i mean that they are able to retrieve files that have been moved !
> (exactly what happens when you move an original file and that an
> Alias still point to it)
>
> how is it achieved ? i suspect carbon calls and something like
> FSRef... but then how do i keep a FSRef persistent ? how can i keep
> it in a file that i'll load at next launch ?
Not FSRef's but AliasHandle's. AliasHandle's aren't 100% bulletproof, but
they're pretty darn robust (create full aliases, not minimal ones) and your
best bet at persistent file references.
In your case, you'd want to allocate the AliasHandle and then probably
encode it in an NSData object, which you can then put into your NSArray.
There are various Cocoa-based alias wrapper classes (check the mailing list
archives), or you can just use the Alias Manager directly (see the Carbon
API documentation).
--
John C. Daub }:-)>=
<mailto:email@hidden> <http://www.hsoi.com/>
"What we have here is a failure to deallocate." - Coolhand Leak
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden