Re: Saving only required files in a file wrapper?
Re: Saving only required files in a file wrapper?
- Subject: Re: Saving only required files in a file wrapper?
- From: Keith Blount <email@hidden>
- Date: Wed, 7 May 2008 13:08:41 -0700 (PDT)
Hi Ken,
Many thanks for your response... Hmm, I think you're right. I overrided -saveDocument: because it looked as though -writeToURL: and all of the other -write... methods expected you to write all the data at any one time. It's possible for my file packages to run to hundreds of megabytes, so I only ever want to write the changed files at any save point (usually only ever one or two RTFD files within the package actually require saving at any one time). There's not much in the docs about doing this - everything I can find seems to assume that you will save everything, even when it comes to packages (as file wrappers), at once, which is why I took a screwy way. I still wonder what the best way of doing it is. -writeToURL:ofType:forSaveOperation:originalContentsURL:error: perhaps?
Also, is it possible that -writeToURL: is getting called behind the back of -saveDocument:? I considered this but assumed (always a bad mistake) that it would be safe as I thought that all of the -write... methods did nothing unless you overrode them.
Many thanks again.
All the best,
Keith
P.S. I've updated the thread title to better reflect the problem.
----- Original Message ----
From: Ken Thomases <email@hidden>
To: Keith Blount <email@hidden>
Cc: email@hidden
Sent: Wednesday, May 7, 2008 4:03:23 PM
Subject: Re: Deep sleep and file wrappers?
I don't have experience with NSDocument-based applications, so take
the following with a grain of salt...
On May 6, 2008, at 1:27 PM, Keith Blount wrote:
> I have an application that saves its information as a file package.
> My NSDocument subclass overrides -saveDocument: to save individual
> files within the project folder (because there can be hundreds of
> files and I wouldn't want to save the whole file wrapper every time
> a single file is changed).
>From the docs, this doesn't seem like the right way to customize
saving. Overriding -saveDocument: may catch some cases of save
attempts, but I suspect there are other times when other methods are
invoked directly. This document describes what you need to override
to customize how the document is saved:
http://developer.apple.com/documentation/Cocoa/Conceptual/Documents/Tasks/SubclassNSDocument.html
> I never got to the bottom of the issue, and now another user has
> reported the same thing. To recap: whilst my app was open, the
> user's computer went into deep sleep (this was the case with the
> first two users; the third user cannot remember the exact
> circumstances but says his computer has had deep sleep problems
> recently). When it came out of deep sleep, everything in the
> project's file wrapper - that is, everything in the folder-with-
> extension on disk - had been wiped. All that was in there were the
> few files that were auto-saved _after_ deep sleep.
I can think of two possibilities:
1) some other method was invoked to save the document, but since you
didn't override it, it produced an empty document. The framework then
replaced the existing document on disk with the new empty document.
2) The framework sometimes juggles files to perform an "atomic"
document save operation. The writing methods of NSDocument are told
to write to a different, temporary location, then the original and the
newly saved document are swapped, then the backup is removed (unless -
keepBackupFile is overridden to return YES). If this happens in your
case, the new document will not be complete because of the way you're
only saving part of the document.
Good luck finding and fixing the problem,
Ken
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
_______________________________________________
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