Old 25th May 2019, 10:56   #1
meoit
Member
 
Join Date: Oct 2014
Location: $DESKTOP
Posts: 90
Post 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:
PHP Code:
我有一个包含中文,越南字符串内容的utf-8文件
nhặn được
end
-line
Code my installer:
PHP Code:
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} $"The five boxing wizards jump quickly."
    
;DetailPrint 'UTF-8: $1'
    
;${StdUtils.StrFromUtf8} $2 0 "$1"
    
;DetailPrint 'Plain: $2'
    
;
    
FileOpen $'C:\Users\UserOne\Desktop\utf-8.txt' r
    
${Do}
        
FileRead $$2
        
${If} ${Errors}
            ${
ExitDo}
        ${EndIf}
        
StrCpy $'$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.
meoit is offline   Reply With Quote
Old 25th May 2019, 11:02   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,169
I don't know if the plug-in cares but does your .TXT have a BOM?

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 25th May 2019, 11:12   #3
meoit
Member
 
Join Date: Oct 2014
Location: $DESKTOP
Posts: 90
@Anders

It is UTF-8, no BOM.

Comment all for StdUtils plugins (only my test)
meoit is offline   Reply With Quote
Old 25th May 2019, 12:07   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,169
You are not even using the plug-in as far as I can see.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 25th May 2019, 12:12   #5
meoit
Member
 
Join Date: Oct 2014
Location: $DESKTOP
Posts: 90
You are right.

I must put comment for that macro plugin, cause I do not know how to use.
meoit is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump