Re: How to know if a file has been opened before?
Re: How to know if a file has been opened before?
- Subject: Re: How to know if a file has been opened before?
- From: Antonio Nunes <email@hidden>
- Date: Wed, 06 Jun 2012 09:48:19 +0100
On 5 Jun 2012, at 14:45, Stephen J. Butler wrote:
> On Tue, Jun 5, 2012 at 3:14 AM, Antonio Nunes <email@hidden> wrote:
>> On 5 Jun 2012, at 00:09, Stephen J. Butler wrote:
>>
>>> You can use extended attributes to attach information to a file. Maybe
>>> serialize your session state as a plist and use setxattr/getxattr to
>>> manipulate it. Follows the file as it's moved around.
>>
>> Thanks Stephen,
>>
>> I think the extended attributes are pretty persistent though, they'll follow the file around across to other computers, right? I wouldn't want that. I only need the data on the particular user's system. Starting to look like l'm probably better off devising my own scheme.
>
> In general, yes. It won't follow if you upload to a website, say
> Dropbox, and then someone else downloads it. But if you copy it to a
> thumb drive and send it then it will.
>
> One thing you could try is to mix the two ideas. Generate a GUID for
> each file and store that in the extended attribute. Then use the GUID
> to lookup your session information in an application CoreData store or
> simple SQLite database.
>
> Then only the GUID follows the file around, and on another machine it
> won't have the session information and you can create it fresh. Also,
> you'll have to handle the case when a file doesn't have a GUID in its
> extended attributes and attach a new one.
Thanks Stephen, I think that would be a bit overkill for my purposes though, since I really only want this info on the original machine. Also, Jens noted a possible issue with multiple copies of the same document. What I ended up doing is something not totally unlike what Graham suggested:
I create a url bookmark that contains a UUID in the name on disk. Next to it I save the data required when reopening the file, with the same UUID incorporated in the name. The when a file is opened, I test the cached bookmarks for a match with the current document. If a match is found, then the UUID leads me to the restoration data, which is then loaded and used. Using bookmarks, rather than static URLs (as I think Graham does) has the benefit that it should be more robust when the file gets moved around between sessions: When reopening the file from another directory, the bookmark URL resolves to the new location, which is exactly what is needed.
-António
----------------------------------------------------
Energy is like a muscle,
it grows stronger through being used.
----------------------------------------------------
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden