Jump to content

Recommended Posts

Posted

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.

Posted

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 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 (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.

results2.png

Edited by Steviep
Posted

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 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

@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?

Posted

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 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

  • 2 years later...
Posted

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

Posted
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.

Posted

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

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...