View Single Post
Old 12th February 2019, 14:28   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,260
0)

Why are your .nsh files without BOM?

1)

FileWrite will never work on anything except "Chinese" machines, it is documented to convert the string to ACP ANSI.

2)

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)

?)

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 

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote