On Apr 30, 2008, at 7:38 AM, Charles Yeomans wrote:
>> DefineEncoding to nil perhaps ?
>
> This is a no-op, as I recall.
No, it works fine. However, let's get back to the original question;
Garth wrote:
> I am trying to save a Folderitem to a .plist. I use GetSaveInfo to
> get the string. Its encoding at that time is Nil.
This is correct. It's binary data, not text.
> I store it in a .plist dictionary (I use that popular PLIST class
> that circulates).
This is a mistake. The Plist class almost certainly expects text,
not binary data.
> During the life of the session if I access the entry the encoding
> stays Nil and it works if I stuff it back to GetRelative.
Sure, because it's just handing you back the data you gave it. It's
not until it's written to a (text) file that it must be treated as text.
> However, when I exit the app, the PLIST class writes it permanently
> back the file. So when I access the string again when I start up the
> app again, often (but not always) the string retrieved has a UTF or
> some encoding to it
I'd expect it to be always. It's reading a text file, so it has to
assume some encoding for the text.
> and thus that corrupts the string and then I can't get the
> FodlerItem again.
No, having an encoding doesn't corrupt the string; it was corrupted
by trying to treat it as text. It may happen to contain line breaks
and other things that make a mess of the plist file.
FolderItem.GetRelative expects binary data, and ignores any encoding
set on the string; it would work fine if the bytes were right -- but
the bytes by this point are wrong.
> So, how do you remove an encoding from a string? Or should that be
> my question?
No, it should not. Removing the encoding from the incorrect bytes
won't make them right.
The right solution, as Norman suggested, is to EncodeBase64 your save
info (converting it from binary to text data) before stuffing it into
your plist. And then when you get it out, DecodeBase64 to get the
binary data back.
Best,
- Joe
--
Joe Strout
Inspiring Applications, Inc.
http://www.InspiringApps.com
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
|