Newbie Help With Updater Code
Hi all, I am working on my first NSIS updater project and need some help. I am trying to create an updater that compares an ini file on our internal web site (“update”) with a shared user local ini file (“install”). If the update version is higher than the install, it will download the specified file to the user’s folder & edit the version number in the install ini. After checking for/ downloading the updates, it will open the “application”.
So, I found a great example here that would loop through each line in an ini file and return the section, key, and value and then tried to add my code:
First, I wanted to be able to prevent users from opening the “app” in case I needed to do some maintenance on the system. So the updater should look at the “lockout” key first and either exit or continue on. This seems to work fine.
Next I wanted it to search for users computer name in the update file (the “app” has several files housed on a share drive and one file that sits on the users C drive) and update that if necessary. This also seems to work fine.
After that, it should loop through all of the entries in the [Files] section, compare to the install ini, and update if necessary. This is where I am stuck.
I have tested the individual pieces and they seem to work, but I am clearly missing something when it comes to stitching it all together. It fails at the “ReadINIFileKeys” section. I do not think I am handling/passing my variables correctly- but I cannot figure it out. Below is the code- I would greatly appreciate any input.

THE CODE:
OutFile "LOOP_TEST.exe"
SilentInstall silent

Var Ufile ;update ini file on sharepoint ($R0)
Var Ifile ;install ini file installed on F drive ($R1)
Var Usection ;section header of update ini file ($Usection)
Var Ukey ;key of update ini file ($R4)
Var Uval ;key value of update ini file ($R5)
Var LockOutSetting
Var LockoutMsg ;lockout message from update ini file
Var UserName ;user computer name
Var Uversion ;front end version in update ini
Var Iversion ;front end version in install ini
Var UPath ;path to update file location on sharepoint
Var DPath ;path to download the update file to
Var MyFileName ;name of file to download

Function .onInit
#-------Start New Code Added By Me-------------
#get computer name
ReadRegStr $UserName HKLM "System\CurrentControlSet\Control\ComputerName\ActiveComputerName" "ComputerName"
#MessageBox MB_OK "$UserName"
StrCpy $Ufile "R:\SANDBOX\NSIS\METACupdate.ini"
StrCpy $Ifile "R:\SANDBOX\NSIS\METACinstall.ini"
;check to see if system is locked out
ReadINIStr $LockOutSetting $Ufile "Settings" "LockOut"
StrCmp $LockOutSetting "yes" LockedOut NotLockedOut
LockedOut:
ReadINIStr $LockOutMsg $Ufile "Settings" "LockOutMsg"
MessageBox MB_OK "$LockOutMsg"
abort
NotLockedOut:
MessageBox MB_OK "Not Locked Out"
;check the computers version number- if computer name isn't found, close
ReadINIStr $Uversion $Ufile "Files" $UserName
StrCmp $Uversion "" "" FoundIt
MessageBox MB_OK "Could not identify computer- application will close"
abort
FoundIt: ;compare the version numbers
MessageBox MB_OK "Found Uversion"
ReadINIStr $Iversion $Ifile "Files" $UserName
StrCmp $Uversion $Iversion NoUpdate GetUpdate
GetUpdate:
StrCpy $Ukey $UserName
StrCpy $MyFileName "mylicense.txt"
call DownloadUpdate
WriteINIStr $Ifile "Files" $UserName $Uversion
;abort
NoUpdate:

MessageBox MB_OK "Before ReadINIFileKeys loop: Usection= $Usection : Ukey= $Ukey : Uval= $Uval"
#----End New Code Added by Me---------------------
Call ReadINIFileKeys

FunctionEnd
Function StrTrimNewlines
Exch $Ufile
Push $Ifile
Push $R2
StrCpy $Ifile 0

loop:
IntOp $Ifile $Ifile - 1
StrCpy $R2 $Ufile 1 $Ifile
StrCmp $R2 "$\r" loop
StrCmp $R2 "$\n" loop

IntOp $Ifile $Ifile + 1
IntCmp $Ifile 0 no_trim_needed
StrCpy $Ufile $Ufile $Ifile

no_trim_needed:
Pop $R2
Pop $Ifile
Exch $Ufile
FunctionEnd

Function SplitFirstStrPart
Exch $Ufile
Push $Ifile
Push $R2
StrLen $Ifile $Ufile
IntOp $Ifile $Ifile + 1
loop:
IntOp $Ifile $Ifile - 1
StrCpy $R2 $Ufile 1 -$Ifile
StrCmp $Ifile 0 exit0
StrCmp $R2 "=" exit1 loop ; Change " " to "\" if str=dirpath
exit0:
StrCpy $Ifile ""
Goto exit2
exit1:
IntOp $Ifile $Ifile - 1
StrCpy $R2 $Ufile "" -$Ifile
IntOp $Ifile $Ifile + 1
StrCpy $Ufile $Ufile -$Ifile
StrCpy $Ifile $R2
exit2:
Pop $R2
Exch $Ifile ;rest
Exch
Exch $Ufile ;first
FunctionEnd
Function ReadINIFileKeys
Exch $Ifile ;INI file to write
Exch
Exch $Ufile ;INI file to read
Push $R2
Push $R3
Push $Ukey ;uni var
Push $Uval ;uni var
Push $Usection ;last INI section

FileOpen $R2 $Ufile r

Loop:
FileRead $R2 $R3 ;get next line into R3
IfErrors Exit

Push $R3
Call StrTrimNewLines
#Call TrimNewLines
Pop $R3

StrCmp $R3 "" Loop ;if blank line, skip

StrCpy $Ukey $R3 1 ;get first char into R4
StrCmp $Ukey ";" Loop ;check it for semicolon and skip line if so(ini comment)

StrCpy $Ukey $R3 "" -1 ;get last char of line into R4
StrCmp $Ukey "]" 0 +6 ;if last char is ], parse section name, else jump to parse key/value
StrCpy $Usection $R3 -1 ;get all except last char
StrLen $Ukey $Usection ;get str length
IntOp $Ukey $Ukey - 1 ;subtract one from length
StrCpy $Usection $Usection "" -$Ukey ;copy all but first char to trim leading [, placing the section name in R6
Goto Loop

Push "=" ;push delimiting char
Push $R3
Call SplitFirstStrPart
Pop $Ukey
Pop $Uval

#---------------Start New Code Added By Me-----------
MessageBox MB_OK "Usection= $Usection : Ukey= $Ukey : Uval= $Uval"

StrCmp $Usection "Settings" NoUpdateA NotSettings ;already checked the settings section, so skip here
NotSettings:
MessageBox MB_OK "NotSettings"
StrCmp $Usection "FilePaths" exit NotFilePaths ;stop when loop gets to the filepaths section
NotFilePaths:
MessageBox MB_OK "NotFilePaths"
MessageBox MB_OK "Updateversion= $Uval"
;get the install file version number for Ukey
ReadINIStr $Iversion $Ifile $Usection $Ukey
MessageBox MB_OK "Ifile= $Ifile: Usection= $Usection: Ukey= $Ukey: Iversion= $Iversion"
;compare the install version number to the update version number
StrCmp $Uversion $Iversion NoUpdateA GetUpdateA
GetUpdateA:
StrCpy $MyFileName $Ukey
Call DownloadUpdate
NoUpdateA:

#---------------End New Code Added By Me-----------------
Goto Loop
Exit:
FileClose $R2
Pop $Usection
Pop $Uval
Pop $Ukey
Pop $R3
Pop $R2
Pop $Ufile
Pop $Ifile

#launch the front end
execshell "" "R:\SANDBOX\NSIS\MAIN_APP.txt"
Quit
FunctionEnd

Function DownloadUpdate ;NEW FUNCTION ADDED BY ME
StrCpy $UPath "http://sharepoint/cross-functional/H2QCE/interior/Site%20Appearance/Forms/AllItems.aspx?RootFolder=%2fcross%2dfunctional%2fH2QCE%2finterior%2fSite%20Appearance%2fMETAC&View=%7bFB5ABE34%2d4B2C%2d475C%2d80A2%2dFC460C24D942%7d/" ;DOWNLOAD_TEST_FILE.TXT" "$5\DOWNLOAD_TEST_FILE.TXT"
ReadINIStr $Dpath $Ufile "Filepaths" $Ukey
MessageBox MB_OK "download from: $Upath$MyFileName"
MessageBox MB_OK "download to: $Dpath$MyFileName"
#InetLoad::load /POPUP "Front End Software Update" "http://sharepoint/cross-functional/H2QCE/interior/Site%20Appearance/Forms/AllItems.aspx?RootFolder=%2fcross%2dfunctional%2fH2QCE%2finterior%2fSite%20Appearance%2fMETAC&View=%7bFB5ABE34%2d4B2C%2d475C%2d80A2%2dFC460C24D942%7d/DOWNLOAD_TEST_FILE.TXT" "$5\DOWNLOAD_TEST_FILE.TXT"
InetLoad::load /POPUP "Front End Software Update" "$Upath$MyFileName" "$Dpath$MyFileName"
Pop $9 # return value = exit code, "OK" if OK
MessageBox MB_OK "Download Status: $9"
FunctionEnd

# default section start; every NSIS script has at least one section.
section "dummy"

# default section end
sectionEnd
AutoCloseWindow true