View Single Post
Old 12th February 2019, 16:15   #3
Pawel
Moderator
 
Pawel's Avatar
 
Join Date: Aug 2004
Location: Poland
Posts: 522
Send a message via ICQ to Pawel
Anders,
First of all - thank you for your answer and time you spent to help me.

Quote:
Originally Posted by Anders View Post
Why are your .nsh files without BOM?
No reason. It works fine without BOM so I didn't touch it. I will try to change it and use BOM in future.

Quote:
Originally Posted by Anders View Post
FileWrite will never work on anything except "Chinese" machines, it is documented to convert the string to ACP ANSI.
Yes, now I know. I just tried everything I thought may work. Everything! (the main problem is that I couldn't tell if Chinese text is OK or not - each time I have to ask my translator).

Quote:
Originally Posted by Anders View Post
That file does not have a BOM, use FileWriteUTF16LE /BOM $R0 "" before writing the strings. Most editors that can read UTF-16 will support the BOM on these files. (Technically, all editors that can read UTF-16 can also read the BOM because it is a valid Unicode character but they might not recognize it as a BOM and switch to UTF-16 automatically)
Yes, you are absolutely right. Normally I use UTF-16LE with BOM. In this case (when creating MNU file) BOM is not accepted (it only accept ANSI and UTF-8, and this is not gonna change in nearest future - compatibility reasons). So I was creating UTF16LE (no BOM) file and then converted it to UTF-8 (no BOM) - but it was not working for Chinese anyway). I hope you understand now why I hate this encoding stuff

Quote:
Originally Posted by Anders View Post
To write in a custom codepage you must do the conversion and writing yourself:

PHP Code:
!macro WriteConvertedUnicodeToFile handle codepage string
Push 
$0
Push 
$1
Push 
${handle}
!
define /ReDef /Math REGMEMNSCAP ${NSIS_MAX_STRLEN} - 24
!define /ReDef /Math REGMEMNSCAP ${REGMEMNSCAP} * ${NSIS_CHAR_SIZE}
System::Call 'KERNEL32::WideCharToMultiByte(i${codepage},i0,ws,i-1,@r0,i${REGMEMNSCAP},p0,p0)i.s' `${string}`
Pop $1
TodoError checkFailed if $1 is 0 or $> ${REGMEMNSCAP}
IntOp $$# Don't write \0
System::Call 'KERNEL32::WriteFile(ps,pr0,ir1,*i,p0)i.r1'
TodoError checkFailed if $1 is 0
Pop 
$1
Pop 
$0
!macroend

Unicode True
LangString UFM_INSTALL_DATE 0 
"${U+5b89}${U+88c5}${U+65e5}${U+671f}:" # "安装日期:" without Unicode .nsi
Section
FileOpen $R0 
"$%temp%\utf8.txt" w
!insertmacro WriteConvertedUnicodeToFile $R0 65001 'Hello "$(UFM_INSTALL_DATE)" World$\r$\n'
FileClose $R0
FileOpen $R0 
"$%temp%\20936.txt" w
!insertmacro WriteConvertedUnicodeToFile $R0 20936 'Hello "$(UFM_INSTALL_DATE)" World$\r$\n'
FileClose $R0
SectionEnd 
As I understand this little macro will make me happy again, right?
I will test it and I hope this will resolve all my problems.

-Pawel
Pawel is offline   Reply With Quote