If someone has some suggestions for improving them that'd be great .. they were my first working pass as them so I'm sure there's probably some room for improvement.
;===================================================================
; StrStr - Find $0 in $1.
; $0 - String to find.
; $1 - String to search in.
; $2 - [out] Index of where string was found, or -1.
;===================================================================
Function StrStr
Push $3
Push $4
Push $5
StrCpy $2 -1
StrLen $4 $0
StrLen $5 $1
IntOp $3 $5 - $4
loop:
IntOp $2 $2 + 1
IntCmp $2 $3 0 0 fail
StrCpy $5 $1 $4 $2
StrCmp $0 $5 return loop
fail:
StrCpy $2 -1
return:
Pop $5
Pop $4
Pop $3
FunctionEnd
;===================================================================
; AddOUTDIRToSearchPath - Append the given directory to the
; PATH env var.
;===================================================================
Function AddOUTDIRToSearchPath
Push $0
Push $1
Push $2
StrCpy $0 $OUTDIR
ReadRegStr $1 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
StrCmp $1 "" 0 winnt
ReadRegStr $1 HKLM SOFTWARE\Microsoft\Windows\CurrentVersion VersionNumber
StrCmp $1 "" return win9x
winnt:
ReadRegStr $1 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" Path
Call StrStr
IntCmp $2 -1 0 0 return
StrCpy $1 "$1;$OUTDIR"
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" Path $1
Goto return
win9x:
ReadEnvStr $1 PATH
Call StrStr
IntCmp $2 -1 0 0 return
ClearErrors
FileOpen $1 "C:\autoexec.bat" "a"
FileSeek $1 0 SET
loop:
FileRead $1 $2
IfErrors end
StrCmp "PATH=%PATH%;$OUTDIR$\r$\n" $2 return loop
end:
FileSeek $1 0 END
FileWrite $1 "$\r$\nPATH=%PATH%;$OUTDIR$\r$\n"
FileClose $1
return:
Pop $2
Pop $1
Pop $0
FunctionEnd