On 05/06/2012, at 8:50 AM, Antonio Nunes wrote:

> The next question is, what is a handy way to keep track of the restoration 
> data that goes with the URL, since that will have to be saved separately from 
> the bookmark data. Using only the file name won't do, I need some kind of 
> unique ID, or a unique URL that can be derived from the bookmark data.  I 
> know I can think up a scheme, but I wonder if there is a proper way to do 
> this, like obtaining a unique file ID.


I do something similar to map an SVG file to its thumbnail image, which is 
costly to generate, and is stored separately from the original file.

Once I've created the thumbnail (or whatever data you want to associate with 
the file), I make a dictionary with the original file's URL as the key and a 
UUID string as the value. The UUID is then used as the filename for the 
thumbnail, which is stored in my Application Support folder. The dictionary is 
written out to a plist in the same location. Using a UUID avoids any 
possibility of accidentally creating a filename that clashes with one written 
earlier. The users never has to see these files so the obscure names don't 
matter.

The dictionary plist of course, has to have a fixed name that you can load when 
your app starts up. Then as a file is opened, look up its "extra data" file via 
the dictionary and do whatever you want with it.

I don't bother culling out thumbnail files that are never needed (if the 
original file is deleted for example), I just let the cache grow as disk space 
is super-abundant. You might want to give the user a way to discard this cache 
though if you were worried about it.

--Graham
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please 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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to