Skip to content
⌘ NSIS Forum Archive

Error: resolving install function "StrReplace" in function "RIF"

4 posts

coderwolf#

Error: resolving install function "StrReplace" in function "RIF"

I am getting an error finding the strReplace function. I dont know how to fix this error, could someone let me know where the problem is coming from and assist me in fixing the problem.

My files are as follows:
strrep.nsh

;sourced from http://nsis.sourceforge.net/StrRep
!define StrRep "!insertmacro StrRep"
!macro StrRep output string old new
Push `${string}`
Push `${old}`
Push `${new}`
!ifdef __UNINSTALL__
Call un.StrRep
!else
Call StrRep
!endif
Pop ${output}
!macroend

!macro Func_StrRep un
Function ${un}StrRep
Exch $R2 ;new
Exch 1
Exch $R1 ;old
Exch 2
Exch $R0 ;string
Push $R3
Push $R4
Push $R5
Push $R6
Push $R7
Push $R8
Push $R9

StrCpy $R3 0
StrLen $R4 $R1
StrLen $R6 $R0
StrLen $R9 $R2
loop:
StrCpy $R5 $R0 $R4 $R3
StrCmp $R5 $R1 found
StrCmp $R3 $R6 done
IntOp $R3 $R3 + 1 ;move offset by 1 to check the next character
Goto loop
found:
StrCpy $R5 $R0 $R3
IntOp $R8 $R3 + $R4
StrCpy $R7 $R0 "" $R8
StrCpy $R0 $R5$R2$R7
StrLen $R6 $R0
IntOp $R3 $R3 + $R9 ;move offset by length of the replacement string
Goto loop
done:

Pop $R9
Pop $R8
Pop $R7
Pop $R6
Pop $R5
Pop $R4
Pop $R3
Push $R0
Push $R1
Pop $R0
Pop $R1
Pop $R0
Pop $R2
Exch $R1
FunctionEnd
!macroend
!insertmacro Func_StrRep ""
!insertmacro Func_StrRep "un."
ReplaceInFile.nsh

!include "strrep.nsh"
;sourced from http://nsis.sourceforge.net/ReplaceInFile

!macro _ReplaceInFile SOURCE_FILE SEARCH_TEXT REPLACEMENT
Push "${SOURCE_FILE}"
Push "${SEARCH_TEXT}"
Push "${REPLACEMENT}"
Call RIF
!macroend

Function RIF

ClearErrors ; want to be a newborn

Exch $0 ; REPLACEMENT
Exch
Exch $1 ; SEARCH_TEXT
Exch 2
Exch $2 ; SOURCE_FILE

Push $R0 ; SOURCE_FILE file handle
Push $R1 ; temporary file handle
Push $R2 ; unique temporary file name
Push $R3 ; a line to sar/save
Push $R4 ; shift puffer

IfFileExists $2 +1 RIF_error ; knock-knock
FileOpen $R0 $2 "r" ; open the door

GetTempFileName $R2 ; who's new?
FileOpen $R1 $R2 "w" ; the escape, please!

RIF_loop: ; round'n'round we go
FileRead $R0 $R3 ; read one line
IfErrors RIF_leaveloop ; enough is enough
RIF_sar: ; sar - search and replace
Push "$R3" ; (hair)stack
Push "$1" ; needle
Push "$0" ; blood
Call StrReplace ; do the bartwalk
StrCpy $R4 "$R3" ; remember previous state
Pop $R3 ; gimme s.th. back in return!
StrCmp "$R3" "$R4" +1 RIF_sar ; loop, might change again!
FileWrite $R1 "$R3" ; save the newbie
Goto RIF_loop ; gimme more

RIF_leaveloop: ; over'n'out, Sir!
FileClose $R1 ; S'rry, Ma'am - clos'n now
FileClose $R0 ; me 2

Delete "$2.old" ; go away, Sire
Rename "$2" "$2.old" ; step aside, Ma'am
Rename "$R2" "$2" ; hi, baby!

ClearErrors ; now i AM a newborn
Goto RIF_out ; out'n'away

RIF_error: ; ups - s.th. went wrong...
SetErrors ; ...so cry, boy!

RIF_out: ; your wardrobe?
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Pop $R0
Pop $2
Pop $0
Pop $1

FunctionEnd
RIPtest.nsi


;This Script will replace text in a desktop file.

;!include "$Documents\NSISInclude\strrep.nsh"
;!include "$Documents\NSISInclude\ReplaceInFile.nsh"
;!include "strrep.nsh"
!include "ReplaceInFile.nsh"

Name RIP

OutFile "RIP.exe"

; The default installation directory
InstallDir $PROGRAMFILES\

InstType "Full"
InstType "DB"

Section /o "Install DB" DB
SetOutPath "$INSTDIR\temp"
SectionIn 1 2
SectionEnd

Function .onInit
!insertmacro _ReplaceInFile "$Desktop\log.txt" "RPL_Home" "$InstallDir"
FunctionEnd
Also, when I tried putting the nsh files in (kind of) my own includes area, which I had hoped to be located in a My documents" folder NSIS was saying it could not find the files. How can I do that in an include? You can see where I tried in the commented out code of RIPtest.nsi.
Anders#
Read the bottom of the ReplaceInFile page on the wiki.

$Documents is a run-time variable, use something like $%userprofile%\documents\foo.nsh...
coderwolf#
Are all the variables in the constant section of the documentation run-time only? Thanks for showing how to handle environment vars!

Also, are comments ignored in the resulting exe, or compiled into the string list?
Anders#
Originally Posted by coderwolf View Post
Are all the variables in the constant section of the documentation run-time only?
Most of them are. Does it really matter?

Originally Posted by coderwolf View Post
Also, are comments ignored in the resulting exe, or compiled into the string list?
Comments are removed in the preprocessor complier step IIRC...