; Copyleft (c) n/a-n/a Azure Zanculmarktum

!include WordFunc.nsh
!insertmacro WordReplace

Function UpdateLocations
	Exch $0 # SLASH
	Exch
	Exch $1 # SOURCE_FILE
	Exch 2
	Push $2
	Push $3
	Push $4
	Push $5

	${WordReplace} "$LASTDIR" "\" "$0" "+" $2
	${WordReplace} "$EXEDIR" "\" "$0" "+" $3

	StrCmp $LASTDIR "" +11
	StrCmp $LASTDIR $EXEDIR +10
		textreplace::_ReplaceInFile /NOUNLOAD "$1" "$1.NewFile" "$2" "$3" ""
		Pop $4
		IntCmp $4 "0" +6 +4 ""
			Delete "$1"
			Rename "$1.NewFile" "$1"
			Goto +4
			SetErrors
			Goto +2
			Delete "$1.NewFile"

	StrCmp $LASTDRIVE "" +11
	StrCmp $LASTDRIVE $ROOTDIR +10
		textreplace::_ReplaceInFile /NOUNLOAD "$1" "$1.NewFile" "$LASTDRIVE$0" "$ROOTDIR$0" ""
		Pop $5
		IntCmp $5 "0" +6 +4 ""
			Delete "$1"
			Rename "$1.NewFile" "$1"
			Goto +4
			SetErrors
			Goto +2
			Delete "$1.NewFile"

	textreplace::_Unload

	Pop $5
	Pop $4
	Pop $3
	Pop $2
	Pop $1
	Pop $0
FunctionEnd

!macro UpdateLocations SOURCE_FILE SLASH
	Push `${SOURCE_FILE}`
	Push `${SLASH}`
	Call UpdateLocations
!macroend

!define UpdateLocations "!insertmacro UpdateLocations"