Bresacon Posted January 7, 2019 Posted January 7, 2019 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.
FrancescoDiMuro Posted January 7, 2019 Posted January 7, 2019 (edited) @Bresacon In the Help file, about IniWriteSection function, it is stated: If you want to use an ini file with unicode encoding, first create an .ini file by using the FileOpen() function with the mode parameter set to "Unicode UTF16 Little Endian". Edited January 7, 2019 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Bresacon Posted January 7, 2019 Author Posted January 7, 2019 (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 January 7, 2019 by Bresacon
BrewManNH Posted January 7, 2019 Posted January 7, 2019 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 GudeHow 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
Bresacon Posted January 7, 2019 Author Posted January 7, 2019 I still don't get why IniWriteSection should modify the file encoding from UTF-8 to ANSI.
BrewManNH Posted January 8, 2019 Posted January 8, 2019 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 GudeHow 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
Bresacon Posted January 8, 2019 Author Posted January 8, 2019 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now