Archive: How to write a UTF-8 file


How to write a UTF-8 file
Hi everyone.

I'm working on this for a whole day, but still couldn't find the answer. This is my problem:

1. I need to write a UTF-8 config file with nsis.

2. I'm using NSIS Unicode.

3. I've tried this code:

    FileOpen $0 $EXEDIR\CONFIG.PATH w
FileWrite $0 $EXEDIR
FileClose $0


This create a ANSI file.

4. I've tried FileWriteUTF16LE. It create a UTF-16LE file.

5. Finally I found a solution: Write a ANSI file. Then use the Unicode plugin to convent that file to UTF-8. But that is a ansi plugin, it's a bit complex to use in NSIS Unicode. So I don't think that is a good idea.

Could someone tell me how to directly write a UTF-8 file in NSIS? Use WinAPI or something?

Great appreciate.


David Pi

Unicode NSIS must be translating the string to ANSI before passing it to WriteFile. Try calling WriteFile directly using the System plug-in.

Stu


Thank you very much. This explained my question. But how to directly call WriteFile? Any examples? I know little about System Plugin.


Try a search.

Stu


You have to perform some steps with the system plugin:
0 allocate byte buffer
1 WideCharToMultiByte to convert from UTF16 to UTF8
2 kernel32::WriteFile to write the converted buffer