Archive: Cannot read ini file


Cannot read ini file
Hello,

I've created an options file which has a FileRequest field so that the user can locate a certain ini file on their system. I read this setting in like this:

!insertmacro MUI_INSTALLOPTIONS_READ $R0 "settings.ini" "Field 1" "State"

I then try to use the value of $R0 to access a field in the ini file and store in $R1, like this:

ReadIniStr $R1 "$R0" "DataSources" "ISE"

However the value for $R1 is always blank. I've also tried:

ReadIniStr $R1 $R0 "DataSources" "ISE" - same result

I've tried MessageBox-ing the value for $R0 and it is correct. If I hardcode the value like this:

ReadIniStr $R1 "C:\something.ini" "DataSources" "ISE"

then it works. I'm completely stumped... any ideas where I'm going wrong?

Thanks,

Beagle


I suspect it's a TrimNewLines issue.


Just made a simplified test for debug purpose and it woks as expected,

OutFile 'test.exe'
ShowInstDetails show

Section "boo"
writeinistr '$EXEDIR\settings.ini' 'field 1' 'state' '$EXEDIR\something.ini'
writeinistr '$EXEDIR\something.ini' 'DataSources' 'ISE' '$COMMONFILES\ISE'
readinistr $R0 '$EXEDIR\settings.ini' 'field 1' 'state'
detailprint '$R0'
readinistr $R1 '$R0' "DataSources" "ISE"
detailprint '$R1'
SectionEnd

Ah, could be! I've added the TrimNewLines function to my script:

Function TrimNewlines
Exch $0
Push $1
Push $2
StrCpy $1 0
loop:
IntOp $1 $1 - 1
StrCpy $2 $0 1 $1
StrCmp $2 "$\r" loop
StrCmp $2 "$\n" loop
IntOp $1 $1 + 1

StrCpy $0 $0 $1
Pop $2
Pop $1
Exch $0
FunctionEnd


How do I call it? I've tried this:

${TrimNewLines} $R0 $R0

which was in an example I saw, but I get an "Invalid Command" error in the compiler.


You don't need the function anymore, it's included within NSIS release Appendix E: Useful Headers.
Also take a look at my example above, might help.


I ran your debug test at it worked, so it does seem that there may be newlines/linefeeds in my variable.

I've removed the function and now just trying:

TrimNewLines $R0 $R0

and get "Invalid Command" - how do I call it? I'm using NSIS 2.12. Sorry if these are easy questions, but I'm still learning how to use NSIS. Many thanks


Firstly I'd suggest update now to last release :)
For TrimNewLines to work you need on the top of your script,

!include "TextFunc.nsh"
!insertmacro TrimNewLines

and in your section/function
${TrimNewLines} $R0 $R0

Thanks Red, working now :-)