0
votes

When I create an INI section in the inno-setup code it always creates new keys even if the key and section exist. The code I'm using is below.

[INI]
Filename: "{app}\Config\app.INI"; Section: "MAIN"; Key: "key1"; String: {code:Getkey1};  
Filename: "{app}\Config\app.INI"; Section: "MAIN"; Key: "key2"; String: {code:Getkey2};  
Filename: "{app}\Config\app.INI"; Section: "MAIN"; Key: "key3"; String: {code:Getkey3};  
Filename: "{app}\Config\app.INI"; Section: "MAIN"; Key: "key4"; String: {code:Getkey4};  

This INI file initially looks like this

[MAIN]
key1=value
key2=value
key3=value
key4=value

and becomes after install (note this ini is in the installed files)

[MAIN]
key1=value1
key2=value2
key3=value3
key4=value4
[MAIN]
key1=value1
key2=value2
key3=value3
key4=value4

So my question is how can I make the file overwrite the initial values instead of creating new.

1
From my understanding, that would create the key if it did not exist. My problem is that it creates the key when it does exist which is not to INI specification. Also I tried that just in case and it did not work. Thanks though.dhockey
Please check codepage of your INI. If it is UTF8 or Unicode you may get result you describe. The INI file should be in ANSI format, then your code will work as intended.RobeN
I cannot reproduce your problem using the code from your question. RobenN can be right. Post minimal reproducible example.Martin Prikryl
I've added more code to give more information. I don't think anything else I have would be relevant, as only the INI section is a problem right now. Everything else is working as intended. There is no language section and the code page is not set anywhere.dhockey

1 Answers

1
votes

Your code is correct.

The problem is 99%, what @RobeN has suggested in his comment.

I can indeed reproduce the problem, when the INI file has the UTF-8 BOM.

As INI files do not support UTF-8 encoding, the INI file parser misinterprets the BOM as being a part of the first line:

<bom>[MAIN]

Hence it does not consider the first line a section start and hence it won't find any [MAIN] section in the file and will create a new one.


Conclusion: Make sure there's no BOM in the INI file. For example, if you create the INI file in Windows Notepad, save the file using Ansi encoding.