How to emulate NOTEPADE.EXE Encoding

SyntaxEditor for Windows Forms Forum

Posted 17 years ago by Ernesto Obregon
Avatar
I have a text file that contains some partially encrypted text. I can open/save the file just fine using NOTEPAD.EXE, however when using the Actipro Syntax Editor with the .LoadFile and .SaveFile Public Sub procedures the encrypted portion of my text gets altered in some way? The encrypted text is still in the file, but slightly different. The actual application that uses the encrypted text produces errors when reading it.

Again I can read/save the file in NOTEPAD.EXE without any trouble. The Actipro Syntax Editor is working terrific for everything else.

I have tried all encoding types (ASCII, BigEndianUnicode, UTF32, Unicode, UTF7 and UTF8) available through LoadFile and SaveFile sub procedures. I made sure to use the same encoding types for loading and saving and did not mix/match them.

Any ideas ?
thanks
teamels

Comments (5)

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
We just use the standard .NET code for loading files and our strings are stored internally as Unicode characters. So your attempted use of encodings would generally work if you have a non-Unicode file. However if you have encrypted data, the problem MIGHT be that when we load a file, we remove all carriage returns internally and store it as line feed delimited. I wonder if perhaps this is corrupting your encrypted data. Unfortunately that's how our document parser code works and it won't be able to be changed. Do you think that could be the issue?


Actipro Software Support

Posted 17 years ago by Ernesto Obregon
Avatar
Actipro,

Probably,it would only take a small change like that to cause it not to function in the application that uses the encrypted code.

It should not be a problem as my users really do not need to save changes when viewing this file format. I will for now just display a message that states this file type can not be saved directly and to use the other recommended methods of modifying the data. The recommended methods are why I am using the Syntax Editor for anyways.

Side thought:
Would the Syntax Editor do the same thing if I read and saved the file including the encrypted text one byte at a time using say a StreamReader/Writer in VB.NET ? Sounds memory intensive though.

thanks
teamels
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes our code will always strip carriage returns when loading the text but will save them back out by default when saving the file. However if the original file doesn't have carriage returns then new ones might be added unless you set which line terminator style to use.

One other idea, save your special section of data separately in a variable when you open the file and then before saving it, replace what the Document.Text's special section is with what you have in your variable and then use the System.IO stuff to save out the file yourself. In v4.0 you could even put a read-only region around the encrypted text to ensure they don't modify it.


Actipro Software Support

Posted 17 years ago by Ernesto Obregon
Avatar
Thanks,

I like the way v4.0 sounds with the read only section. I think I will try that.

thank you, and thanks for working the weekend
teamels
Posted 17 years ago by ernesto
Avatar
Updated 5-7-07 Never Mind, sorry. After posting this I read what I wrote and found my problem. I was not saving my files with the same encoding as I was using for loading. When I load and save the file with
System.text.encoding.default
then everything seems just fine.




I have been using the ReadOnlySpanIndicator for a read only region. This is to protect encrypted text so it is not altered when loading and saving the file. The SyntaxEditor seems to still be altering the encrypted text. When I reload the file to view it in the editor after saving I can see that the encrypted text is different. Should the read only span indicator keep it from being altered ?

Here is the code I have been using.

' Initialize the span indicator
Dim layer As SpanIndicatorLayer = editor.Document.SpanIndicatorLayers
layer = New SpanIndicatorLayer(SpanIndicatorLayer.ReadOnlyKey,SpanIndicatorLayer.ReadOnlyDisplayPriority)                editor.Document.SpanIndicatorLayers.Add(layer)
layer.Clear()
' After selecting the text to make read only between
' my start and end offset this is the line of code I use.

layer.Add(New ReadOnlySpanIndicator, New TextRange(startoffset, endoffset - 1))
Note: I have been comparing the file to what loads in the edit control to what NOTEPAD.EXE loads and when I load the file into the edit control the encrypted text looks as it should, but after saving it does not look the same in the edit control or in notepad.

This is what I use to load the file:

editor.Document.LoadFile(longFileName, System.Text.Encoding.Default)
This is what I use to save the file:

editor.Document.SaveFile(EditControl1.Document.Filename, LineTerminator.CarriageReturnNewline)
thanks
teamels

[Modified at 05/07/2007 05:08 PM]
The latest build of this product (v24.1.0) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.