Steviep Posted July 29, 2019 Posted July 29, 2019 Hi all, i'm updating an installer script which must write French text with accented characters to existing .INI preference files encoded with UTF8-BOM. IniWrite ( "UTF8-BOM.ini", "section", "key", "é") When I attempt to do so, the é character appears scrambled. I've been reading through the Help documents and see we can use FileOpen for new files, but in this case I'm updating existing files. I have also been reading lots of other community posts related to this and understand there are limitations with .ini files & UTF8-BOM. I've been experimenting without success, any suggestions? Thanks.
FrancescoDiMuro Posted July 29, 2019 Posted July 29, 2019 @Steviep $FO_APPEND + $FO_UTF8? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Steviep Posted July 29, 2019 Author Posted July 29, 2019 20 minutes ago, FrancescoDiMuro said: @Steviep $FO_APPEND + $FO_UTF8? I tried mode 129 ($FO_APPEND + $FO_UTF8) with FileOpen but still no luck: #include <File.au3> $file = "UTF8-BOM.ini" $Open = FileOpen ( $file, 129) IniWrite ( $file, "section", "key", "é") FileClose ($Open) See result in screenshot attached.
FrancescoDiMuro Posted July 29, 2019 Posted July 29, 2019 @Steviep Pass to the IniWrite functions the handle obtained by FileOpen instead of the filename, and let us know Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
BrewManNH Posted July 29, 2019 Posted July 29, 2019 You need to use FileOpen with the UTF 16 LE mode to read/write Unicode to an INI file. Quote $FO_UNICODE or $FO_UTF16_LE (32) = Use Unicode UTF16 Little Endian reading and writing mode. Try that instead of the $FO_UTF8 mode. 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
Steviep Posted July 29, 2019 Author Posted July 29, 2019 (edited) @FrancescoDiMuro I tried the following but instead, it created a new file name called "1" #include <File.au3> $file = "UTF8-BOM.ini" $Open = FileOpen ( $file, 129) IniWrite ( $Open, "section", "key", "é") FileClose ($Open) @BrewManNH I tried with 32 instead of 129, but seem to have the same results: $file = "UTF8-BOM.ini" $Open = FileOpen ( $file, 32) IniWrite ( $file, "section", "key", "é") FileClose ($Open) NotePad++ is showing that the file is UTF8+BOM which is good but I just can't seem to write these characters to it. Edited July 29, 2019 by Steviep
BrewManNH Posted July 29, 2019 Posted July 29, 2019 I ran your script, and it worked fine for me. I ran this: $file = "UTF8-BOM.ini" $Open = FileOpen ( $file, 33) IniWrite ( $file, "section", "key", "é") FileClose ($Open) ShellExecute($file) I got this in the INI Quote [section] key=é 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
Steviep Posted July 29, 2019 Author Posted July 29, 2019 @BrewManNH You're right that it does work if the UTF8-BOM.ini file does not exist, but in my case i'm updating an existing .ini file which was previously encoded with UTF8-BOM. Do you think there's a way to write these characters directly to an existing UTF8-BOM .ini?
BrewManNH Posted July 29, 2019 Posted July 29, 2019 No 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
FrancescoDiMuro Posted July 29, 2019 Posted July 29, 2019 @Steviep Another wat would be to read the content of the existing UTF-8 file and write it back with the desired format Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Steviep Posted August 6, 2019 Author Posted August 6, 2019 @FrancescoDiMuro In the end, this is exactly what I decided to do. Thanks for your assistance!
FrancescoDiMuro Posted August 6, 2019 Posted August 6, 2019 @Steviep Happy to have helped Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
MatzeP Posted October 22, 2021 Posted October 22, 2021 Hi, I have the same Problem, but on my side it doesn't work like here posted. My ini File is in UTF8-BOM (according to notepad++). If I want change a value it will always be append on these File. Have anybody has an idea what I make wrong? Thanks
Developers Jos Posted October 22, 2021 Developers Posted October 22, 2021 @MatzeP, You really need to provide your source and a copy of that ini file if you want anybody to assist unless they have that famous crystal ball. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
KaFu Posted October 22, 2021 Posted October 22, 2021 Func _Ini_Initialization($sFile, $sSectioName) If FileExists($sFile) Then Return Local $h_file = FileOpen($sFile, 2 + 32) ; 32 = Use Unicode UTF16 Little Endian reading and writing mode. FileWrite($h_file, $sSectioName & @CRLF) ; you need to write something FileClose($h_file) EndFunc ;==>_Ini_Initialization _Ini_Initialization(@ScriptDir & "MPV-Enhancer.ini", "[Settings]") I always create ini-files this way, ini-file must not exist initially. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
MatzeP Posted October 22, 2021 Posted October 22, 2021 Hi, Yes your are right: Func Main() $NexusMeteringPathWorkDir=StringRegExp($NexusMeteringPath,"(^\w:\\.*\\).*\.exe",2) For $i=1 To $WindowQue[0] iniWrite($iniNexusConfigFile,"GLOBAL","AktPage",$i) Sleep(1000) Run($NexusMeteringPath, $NexusMeteringPathWorkDir[1]) Sleep(2000) Next EndFunc In $WindowsQue is a List of numbers which I must change step by step. So that the Program start with the right parameters. The ini-File is written by another Program and is written after every start of the Program. I will only change one entry. @Kafu: I have test it with FileOpen(***,32,33,128,129,256,257) and always he set the entry at the End. 130 and 258 overwrite my file and only my one entry is inside. autosave.mmp
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