How to Versions Browser when document won't open?

2014-03-20 Thread Jerry Krinock
A user sent me a corrupt document file.  It won’t open.  Yes, it’s a Core Data 
SQLite file, and dumping it using sqlite3 on the command line doesn’t help 
either.  It looks like some bits got smashed at one point…

ZMACSTER INTEGER, ZUSERDESCRIPTION VARC???,???…

Anyhow, I was wondering if Versions Browser could come to the rescue by 
restoring a recent version, even if Time Machine is not available.  Of course, 
the problem for the user is that if the document won’t open, you can’t get into 
Versions Browser.

Has anyone ever dealt with this?  Is it worth while trying to dig into 
/.DocumentRevisions-V100?  Or should I try and mess with the metadata somehow, 
to try and fool my app into thinking that it’s opening the corrupt file when in 
fact it’s opening a new empty file?

Jerry Krinock


___

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

Re: How to Versions Browser when document won't open?

2014-03-21 Thread Jerry Krinock
It looks like we have a solution to the problem of the user not being able to 
restore a corrupt document from Versions Browser because the document is 
corrupt, and so she can’t open it, and so she can’t File > Revert to > Browse 
All Versions.

The solution is:

• Override -[NSDocument openDocumentWithContentsOfURL:display:error:].
• After invoking super, look in returned error for SQLite error code:11, 
'database disk image is malformed’.
• If that error is found, clear all data from the document on the disk.
• In its place, copy in data from a good, empty document.
• Invoke super again.  The document will open this time.
• Display a sheet informing user that document was corrupt and suggest File > 
Revert to > Browse All Versions.

I’ve not written the code yet, just done the above manually with a Core Data 
SQLite document that has legacy Delete/Rollback journaling.  Corruption was 
simulated by punching out the middle of the file with a hex editor.  I also 
used a hex editor to nuke and pave the document.  Result: Versions Browser 
showed previous versions of the corrupted document, as desired.  After 
restoring one, I was able to edit, save, close, and re-open it and nothing 
complained.

Happily, no reverse engineering of /.DocumentRevisions-V100 was necessary, but 
I’m still open to any better ideas.  Did I miss an easier solution to this 
problem that is built into Cocoa?

I’m aware that the magic in NS(Persistent)Document often comes back to bite 
with a vengeance days or weeks later.  I shall post again if I have any trouble.


___

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