Archive: Trouble with varable


Trouble with varable
First, I am not a programmer, but have been using NSIS for sometime now and have manage to do some fairly complex things and have always manage to find the answers that I have needed.

I know that this is probably something very simple and will feel like an idiot once it is all sorted out, but I am having trouble passing the value of a variable. I need to determine what version of a game that a user has before installing a patch. The version information is in a file on the original media and in the installed folder called "version" with no extension. I am able to read this information, but cannot pass it on to an If statement.

Function ReadFileLine
Exch $0 ;file
Exch
Exch $1 ;line number
Push $2
Push $3

FileOpen $2 $0 r
StrCpy $3 0

Loop:
IntOp $3 $3 + 1
ClearErrors
FileRead $2 $0
IfErrors +2
StrCmp $3 $1 0 loop
FileClose $2

Pop $3
Pop $2
Pop $1
Exch $0
FunctionEnd

Section
Push 1 ;line number to read from
Push "$INSTDIR\version" ;text file to read
Call ReadFileLine
Pop $R0 ;output string (read from file.txt)

${if} $R0 == "1.000.000"
MessageBox MB_OK "Original version"
${Else}
MessageBox MB_OK "Not original version"
${EndIf}
SectionEnd


The Message Boxes, of course, are just place holders.

I believe that fileread gives back the line with $\n on it. Your comparison is failing because you should either remove the newline from the input or add it to the constant you are comparing against.


That was it. Thanks a heap.