Old 22nd March 2011, 19:19   #1
Rajada
Junior Member
 
Join Date: Mar 2011
Posts: 14
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...

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

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

[Card1]
...



to this:
code:

...
[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.
Rajada is offline   Reply With Quote
Old 22nd March 2011, 19:34   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 22nd March 2011, 19:54   #3
Rajada
Junior Member
 
Join Date: Mar 2011
Posts: 14
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.
Rajada is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Tags
ini, insert, line

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump