ReplaceInFileWithTextReplace.nsh revision 556728d98061d2d34980374d963a59dde52e2670
5053N/A; ReplaceInFile wrapper for testreplace function
5053N/A; John T. Haller of PortableApps.com
5053N/A; BSD License
5053N/A; Requires TextReplace plugin installed in NSIS and !include "TextReplace.nsh" in main nsi
5053N/A;
5053N/A; Usage: ${ReplaceInFile} SOURCE_FILE SEARCH_TEXT REPLACEMENT
5053N/A; or use ReplaceInFileCS for case-sensitive (use when possible, it's faster)
5053N/A; No return variable. Error will be set if unable to do the replacement (invalid file, locked file, etc)
5053N/A
5053N/AFunction ReplaceInFile
5053N/A Exch $0 ;REPLACEMENT
5053N/A Exch
5053N/A Exch $1 ;SEARCH_TEXT
5053N/A Exch 2
5053N/A Exch $2 ;SOURCE_FILE
5053N/A Exch 3
5053N/A Exch $3 ;CASE_INSENSITIVE
5053N/A Push $4 ;NEW_FILE
5053N/A Push $5 ;RETURN_VALUE
5053N/A
5053N/A StrCpy $4 `$2.OldReplaceInFile`
5053N/A
5053N/A ${textreplace::ReplaceInFile} "$2" "$4" "$1" "$0" "$3 /C=0" $5
5053N/A
5053N/A IntCmp $5 0 StackCleanup ReturnError RenameToOriginal
5053N/A
5053N/A ReturnError:
5053N/A SetErrors
5053N/A Goto StackCleanup
5053N/A
5053N/A RenameToOriginal:
5053N/A Delete $2
5053N/A Rename $4 $2
5053N/A
5053N/A StackCleanup:
5053N/A Pop $5
5053N/A Pop $4
5053N/A Pop $3
5053N/A Pop $0
5053N/A Pop $1
5053N/A Pop $2
5053N/A
5053N/A ${textreplace::Unload}
5053N/AFunctionEnd
5053N/A
5053N/A!macro ReplaceInFileCS SOURCE_FILE SEARCH_TEXT REPLACEMENT
5053N/A Push `/S=1`
5053N/A Push `${SOURCE_FILE}`
5053N/A Push `${SEARCH_TEXT}`
5053N/A Push `${REPLACEMENT}`
5053N/A Call ReplaceInFile
5053N/A!macroend
5053N/A
5053N/A!macro ReplaceInFile SOURCE_FILE SEARCH_TEXT REPLACEMENT
5053N/A Push `/S=0`
5053N/A Push `${SOURCE_FILE}`
5053N/A Push `${SEARCH_TEXT}`
5053N/A Push `${REPLACEMENT}`
5053N/A Call ReplaceInFile
5053N/A!macroend
5053N/A
5053N/A!define ReplaceInFileCS '!insertmacro "ReplaceInFileCS"'
5053N/A
5053N/A!define ReplaceInFile '!insertmacro "ReplaceInFile"'