Jump to content

Recommended Posts

Posted

It looks like IniWriteSection doesn't observe the unicode encoding for the .ini file it processes. Please, run this:

Local $sINIfile = "file.ini"
Local $sINIfile_settings = "settings"
Local $sINIfile_settings_data[5][2] = [[4, ""], ["data1", "1±1"], ["data2", "2±1"], ["data3", "3²"], ["data4", "4³"]]

FileWrite($sINIfile, "[" & $sINIfile_settings & "]" & @CRLF)
For $c = 1 To $sINIfile_settings_data[0][0]
    FileWrite($sINIfile, $sINIfile_settings_data[$c][0] & "=" & $sINIfile_settings_data[$c][1] & @CRLF)
Next

This creates a file called file.ini with some data in ini-like file format. The file gets created by default with a UTF-8 no BOM encoding as it uses ASCII extended characters. Everything's perfect.

Now, if you run this:

Local $sINIfile = "file.ini"
Local $sINIfile_settings = "settings"
Local $sINIfile_settings_data[5][2] = [[4, ""], ["data1", "1±1"], ["data2", "2±1"], ["data3", "3²"], ["data4", "4³"]]

IniWriteSection($sINIfile, $sINIfile_settings, $sINIfile_settings_data)

It creates the same file but with ANSI encoding.

Furthermore, if that .ini file was already existing with UTF-8 no BOM encoding and it gets processed by IniWriteSection it will be rewritten as ANSI.

Am I missing something? Thanks in advance.

Posted (edited)

I see. But it looks like doesn't have to be UTF-16 Little Endian. If I use the $FO_UNICODE or $FO_UTF16_LE modes, IniWriteSection keeps the encoding. Ok. But if I create the file with $FO_UTF16_LE_NOBOM or even $FO_UTF8 stil keeps it.

It only appears to be overriding the encoding if it's UTF-8 no BOM.

Edited by Bresacon
Posted

Try using a Unicode language, such as Hebrew, you'll find that it's not going to work with just UTF-8 with or w/o BOM.

Your example with a bit of translated Hebrew in it, try it without the FileOpen and it won't work correctly.

#include <FileConstants.au3>
; Create a constant variable in Local scope of the filepath that will be read/written to.
Local $sINIfile = "file.ini"
Local $sINIfile_settings = "settings"
FileOpen($sINIfile, BitOR($FO_UTF16_LE, $FO_OVERWRITE))
Local $sINIfile_settings_data[5][2] = [[4, ""], ["data1", "1±1"], ["data2", "2±1"], ["data3", "3²"], ["data4", "לפני 87 שנה אבותינו."]]

IniWriteSection($sINIfile, $sINIfile_settings, $sINIfile_settings_data)
ShellExecute($sINIfile, "", @ScriptDir, "Open")

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

Because INI files by design are ASCII only files, they aren't Unicode compatible out of the box, and the Windows API that is used to create/modify them aren't Unicode aware.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

But if I use UTF-16 -as you put in your example- the encoding will stay untouched after IniWriteSection.

Ok, I'll let it be, this is going nowhere. Thanks everybody.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...