Archive: [Help] Regarding Reading/Writing Unicode Files


[Help] Regarding Reading/Writing Unicode Files
  I was just wandering if there was a possibility to Find and replace strings within a Loaded Unicode File from a ANSI NSIS.

I want to replace the string found with a bunncha big content... or could i import a File(Content) to be replaced with?


Take a look at my nsisFile plugin.
You can use it to search and replace any sequence of bytes.

In your case, make sure you specify a sequence of bytes that represents Unicode characters (like 480065006C006C006F00 for "Hello")

Use bin version for ANSI NSIS
(binU version is for Unicode NSIS)


Or you can try this plug-in !
It's based on the original textreplace plug-in by Instructor but can deal with utf-16LE files.

We have used the replace function for a while now in several projects, but never done much testing on the find function

Just set option /U=1 for UTF-16LE, see the readme for additional details !


Originally posted by gringoloco023
Or you can try this plug-in !
It's based on the original textreplace plug-in by Instructor but can deal with utf-16LE files.

We have used the replace function for a while now in several projects, but never done much testing on the find function

Just set option /U=1 for UTF-16LE, see the readme for additional details !

I used UNICODE PLUGIN.
Unicode(UTF-16LE) -> ANSI Failed.

So i decided to convert UTF-16LE -> UTF-8 and UTF-8 -> ANSI and worked.
And used text replace on it. :D

Thank you anways. Will try the new plugin now.

Originally Posted by gringoloco023 (Post 2694742) Or you can try this plug-in !
It's based on the original textreplace plug-in by Instructor but can deal with utf-16LE files.

We have used the replace function for a while now in several projects, but never done much testing on the find function

Just set option /U=1 for UTF-16LE, see the readme for additional details !
It correctly reads on Unicode files but doesnt write on Unicode with ANSI NSIS.

You confuse me...

Quote:


${textreplace::FillReadBuffer} "$INSTDIR\update\modder\resource\l4d360ui_info.txt" $0

${textreplace::ReplaceInFile} "$INSTDIR\update\modder\resource\l4d360ui_tu_english.txt" "$INSTDIR\update\modder\resource\l4d360ui_tu_english.txt" "// -- End Game Lobby Changes" "$0" "/U=1 /PO=1" $1

${textreplace::FreeReadBuffer} "$0"
${textreplace::Unload}

;-------------------------------------------------

${textreplace::FillReadBuffer} "$INSTDIR\update\modder\resource\ui\l4d360ui\bloginfo.txt" $0

${textreplace::ReplaceInFile} "$INSTDIR\update\modder\resource\ui\l4d360ui\blogpost.txt" "$INSTDIR\update\modder\resource\ui\l4d360ui\blogpost.txt" "***text02" "$0" "/U=1 /PO=1" $1

${textreplace::FreeReadBuffer} "$0"
${textreplace::Unload}

;------------------------------------ EOF


I tried the ANSI Plugin with newtextreplace.nsh, it didn't replace the file content i needed in the unicode file infact it put some Chinese characters.


I would need the actual text files you are using, to reproduce this.

Could you please zip them up and supply a link ?


Originally posted by gringoloco023
I would need the actual text files you are using, to reproduce this.

Could you please zip them up and supply a link ?
Here they are.

I repeat, i try to implement a whole content of a file(ANSI text file) in these unicode text Files.

There you go, it would basically be impossible to implement a whole content of an ANSI text file into a unicode text Files. You would end up with 'Chinese' characters :) . I suggest you to re-code the ansi text file to unicode first.

As soon as I find some time I will have a look into it as well


Originally posted by gringoloco023
There you go, it would basically be impossible to implement a whole content of an ANSI text file into a unicode text Files. You would end up with 'Chinese' characters :) . I suggest you to re-code the ansi text file to unicode first.

As soon as I find some time I will have a look into it as well
oh lol so you mean ANSI to Unicode doesnt work ?

awright, i will try using unicode to unicode Writing.

Thank you :D

Edit: Even Unicode to unicode failed :(

I even tried to
ReadBuffer from a unicode file and paste it over an Unicode file. it copies few texts and fonts change to something else. Donot know what to do-.-


Sorry about this (I'm still learning C ). What I done wrong is that it was taking the string length from the handle number, instead of the text file in the buffer.

As well I fixed a bug what was including the BOM into the ReadBuffer, which then ended up in the middle of your resulting text file.

We never used anything else than just replacing basic strings, so I never realized these bugs.

Anyway, it should be fixed now :)


Originally posted by gringoloco023
Sorry about this (I'm still learning C ). What I done wrong is that it was taking the string length from the handle number, instead of the text file in the buffer.

As well I fixed a bug what was including the BOM into the ReadBuffer, which then ended up in the middle of your resulting text file.

We never used anything else than just replacing basic strings, so I never realized these bugs.

Anyway, it should be fixed now :)
thanks, will test now.

Gani, forgot about you..
  FYI, I totally rewrote the newtextreplace plugin and now there is no problem anymore to replace in one encoding with another encoding. Also the issue with case-insensative for non-ansi characters is solved.

So no more chinese letters for you :)

http://forums.winamp.com/showthread....newtextreplace

please let me know if you have any issues with the plug-in.

regards



I used UNICODE PLUGIN.
Unicode(UTF-16LE) -> ANSI Failed.

So i decided to convert UTF-16LE -> UTF-8 and UTF-8 -> ANSI and worked. It's called newtextreplace plug-in, and doesn't need any converting ! It does exactly the same as the textreplace plug-in and is used in the same way, but deals with utf-16 files if you add option /U=1

  ${textreplace::ReplaceInFile} "C:\input.txt" "C:\output.txt" "abc" "xyz" "/U=1" $0 

>
One thing I forgot to mention is that case-insensitive is not working for non-ansi characters. (As we had a need to replace just ansi characters in binary files, and to do case-insensitive in binary files got a bit complicated to the code)
It correctly reads on Unicode files but doesnt write on Unicode with ANSI NSIS.
Be sure to use the ansi version of the plug-in, 'NewTextReplace_v0.4.1\Ansi\Plugin\newtextreplace.dll'
Could you send (part of) the script your using