Inside StYNCies, Part 2
Subject:   Writing to StickiesDatabase
Date:   2009-05-03 10:00:39
From:   bobidden
Hi Everyone,
For a project, I am trying to write to the StickiesDatabase. I have used this tutorial to read the database, and implemented the remaining methods to write to the StickiesDatabase. It nearly works - I just have one error. The database that I write looks the same as the actual one, however it will not load into Stickies. When I compare the two files at the Hex level, I notice that, in the header section created by NSArchiver, there is a "00" instead of a "01" as in the version written by Stickies. This is preventing in from being loaded - when I change that value, Stickies can read my database.

Does anyone have an idea of direction that I could go to solve this bug? I have tried writing a script to replace that one value, however I don't like leaving buggy code (and the script is quite painful to write). I did not deal with versioning at all (even though the article suggested that I would) so I am wondering if that is part of my problem. If anyone could provide some help, I would greatly appreciate it.


Here is the code that I added to the tutorial - this is in the document class (there was some stuff in the AppController, but that was just t initialize the documents):

- (id)initWithData:(NSData*)d {
mRTFDData = [d retain];
mWindowColor = 0;
mWindowFlags = 0;
NSPoint origin;
origin.x = 0;
origin.y = 0;
NSSize size;
size.width = 500;
size.height = 500;
mWindowFrame.size = size;
mWindowFrame.origin = origin;
mModificationDate = [NSDate date];
mCreationDate = [NSDate date];

return self;

-(id)initWithString:(NSAttributedString *)s{
NSRange range;
range.location = 0;
range.length = [s length];
NSRangePointer rangePt;
[self initWithData:[s RTFDFromRange:range documentAttributes:[s attributesAtIndex:0 effectiveRange:nil]]];
return self;

- (void)encodeWithCoder:(NSCoder*)c {
[c encodeObject:mRTFDData];
[c encodeValueOfObjCType:@encode(int) at:&mWindowFlags];
[c encodeValueOfObjCType:@encode(NSRect) at:&mWindowFrame];
[c encodeValueOfObjCType:@encode(int) at:&mWindowColor];
[c encodeObject:mCreationDate];
[c encodeObject:mModificationDate];