Skip to content
⌘ NSIS Forum Archive

NSIS how to read the unicode string lines in an utf-8 file

5 posts

meoit#

NSIS how to read the unicode string lines in an utf-8 file

NSIS how to read the unicode string lines in an utf-8 file.

I have an utf-8 file, content containing Chinese, Vietnamese character string, with the content:
我有一个包含中文,越南字符串内容的utf-8文件
nhặn được
end-line. 
Code my installer:
Unicode true
!include "MUI2.nsh"
RequestExecutionLevel user
#Convert string from Unicode (UTF-16) or ANSI to UTF-8 bytes
!define StdUtils.StrToUtf8        '!insertmacro _StdU_StrToUtf8'
!macro _StdU_StrToUtf8 out str
    push `${str}`
    StdUtils::StrToUtf8 /NOUNLOAD
    pop ${out}
!macroend
#Convert string from UTF-8 bytes to Unicode (UTF-16) or ANSI
!define StdUtils.StrFromUtf8      '!insertmacro _StdU_StrFromUtf8'
!macro _StdU_StrFromUtf8 out trnc str
    push ${trnc}
    push `${str}`
    StdUtils::StrFromUtf8 /NOUNLOAD
    pop ${out}
!macroend
;
Section
    ;${StdUtils.StrToUtf8} $1 "The five boxing wizards jump quickly."
    ;DetailPrint 'UTF-8: $1'
    ;${StdUtils.StrFromUtf8} $2 0 "$1"
    ;DetailPrint 'Plain: $2'
    ;
    FileOpen $1 'C:\Users\UserOne\Desktop\utf-8.txt' r
    ${Do}
        FileRead $1 $2
        ${If} ${Errors}
            ${ExitDo}
        ${EndIf}
        StrCpy $3 '$3$2'
    ${Loop}
    FileClose $1
    DetailPrint 'Result: $3'
    MessageBox MB_ICONINFORMATION|MB_OK '$3'
SectionEnd 
Result: bad font in the messagebox, as image:



How to fix ?

Thanks.