Archive: WriteINIStr Question?


WriteINIStr Question?
More of an irritation than a problem really. Basically i have an INI file stored on the network and i'm just using nsis to write a whole host of settings into this file gathered from terminals around the network.

The irritation is that the last terminal which used my installer there always seems to be a space after the equals sign.

As per the example below the last section written was ANDREW. However if i ran the install prog again to right section JAMES for example the spaces would all be under the JAMES section and disappear from the ANDREW section.

[JAMES]
Description=James PC Upstairs
IP Address=192.168.1.57
Visible=Yes

[HARRY]
Description=Harry's PC Upstairs
IP Address=192.168.1.59
Visible=Yes

[ANDREW]
Description= Andrew's PC Downstairs
IP Address= 192.168.1.51
Visible= Yes

Any ideas guys?


WriteINIStr only calls to the Windows API function WritePrivateProfileString, and the compiler doesn't add any spaces. Can we see the script please?


It would appear that if you write a value into an INI file with a space before it
i.e "TEST= Poop" then the next time nsis writes into that INI file it strips the space out leaving "TEST=Poop".


Like I said, NSIS only calls WritePrivateProfileString, so if WritePrivateProfileString is making this, I think it the reading function can handle it and it shouldn't pose any problems.

It would help if you post your script... If you don't want to post it i public, you can just PM it to me.


; The file to write
OutFile "test.exe"

Name "INI Test"

!define CLIENTNAME $6
!define SECTIONNAME "CLIENTNAME=${CLIENTNAME}"

Section

; Getting Clientname From Registry

ReadRegStr ${CLIENTNAME} HKLM "System\CurrentControlSet\Control\ComputerName\ComputerName" ComputerName

WriteINIStr C:\test.ini ${SECTIONNAME} "1" " Something 1"
WriteINIStr C:\test.ini ${SECTIONNAME} "2" " Something 2"
WriteINIStr C:\test.ini ${SECTIONNAME} "2" " Something 3"
; It happens because the space is here........^

SectionEnd


Hmm... Why did you put those spaces? I thought you didn't want spaces....


The spaces will be removed when you go to read the profile string. So it is really pointless to try to preserve any spaces.

If you really need to, then you may want to use a custom ini file reader that will do that.


I'm trying to do some minor formatting in an INI file and noticed this doesn't honor the spaces:


!insertmacro MUI_INSTALLOPTIONS_WRITE a.ini "Field 1" "Text" " foo"

but this does:

!insertmacro MUI_INSTALLOPTIONS_WRITE a.ini "Field 1" "Text" "\r\n foo"

I can't figure out a way to get the spaces without adding a new line first. Using \t works, but I'd prefer a shorter indention. Anyone know how to do this?

Thanks.

Use quotes.