Archive: Inserting a line into an .ini file


Inserting a line into an .ini file
I have recently taken over (read, been given control unexpectedly) leading a project wherein a NSIS installer is used. I've had code experience before, but this is very different than Java and C based code I know moderately well. My installer uses the following function, allowing me to rewrite lines in an ini file. For example...

WriteINIStr "$INSTDIR\System\Nerf.ini" "Engine.GameEngine" "CacheSizeMegs" "256"


would affect in the ini the line "CacheSizeMegs=256" under the heading "[Engine.GameEngine]".

My first question would be is this function something that came with the language? In other words a native or built in function? I can't seem to find a definition for it in the installer.

My second question is can I insert lines using the same or a similar function? To be more clear, I need it to change a section in the ini from this:

...
[Engine.HUD]
HudMode=0
Crosshair=10

[Card1]
...


to this:

...
[Engine.HUD]
HudMode=0
Crosshair=10

[NerfI.NerfHUD]
CrosshairColor=(R=0,G=160,B=225,A=0)
bAllowCustomCrosshairs=True

[Card1]
...


which involves adding a new header and two lines below it. So I need to know the best way to go about it.

Thanks in advance, and excuse me if my terminology is a bit off, I've only got what I know from previous code experience and what I have managed to self teach myself about this language in the very few hours I've had to tinker with it.

WriteINIStr is in the user manual. It uses the WritePrivateProfileString Win32 function underneath. If you need to add more entries, add more WriteINIStr lines. The order that they are in the INI file is not important. WriteINIStr will add the entries under the section if it already exists (after any existing values) or if the section does not already exist, will add the section to the end of the INI file.

Stu


Okay! Thanks for clearing that up. Yes I knew the order isn't important as you said, but I had no idea it could create the sections too. That helps immensely, thanks a bunch.