1; Replace text in file, see http://nsis.sourceforge.net/ReplaceInFile 2 3!macro _ReplaceInFile SOURCE_FILE SEARCH_TEXT REPLACEMENT 4 Push "${SOURCE_FILE}" 5 Push "${SEARCH_TEXT}" 6 Push "${REPLACEMENT}" 7 Call RIF 8!macroend 9 10Function RIF 11 12 ClearErrors ; want to be a newborn 13 14 Exch $0 ; REPLACEMENT 15 Exch 16 Exch $1 ; SEARCH_TEXT 17 Exch 2 18 Exch $2 ; SOURCE_FILE 19 20 Push $R0 ; SOURCE_FILE file handle 21 Push $R1 ; temporary file handle 22 Push $R2 ; unique temporary file name 23 Push $R3 ; a line to sar/save 24 Push $R4 ; shift puffer 25 26 IfFileExists $2 +1 RIF_error ; knock-knock 27 FileOpen $R0 $2 "r" ; open the door 28 29 GetTempFileName $R2 ; who's new? 30 FileOpen $R1 $R2 "w" ; the escape, please! 31 32 RIF_loop: ; round'n'round we go 33 FileRead $R0 $R3 ; read one line 34 IfErrors RIF_leaveloop ; enough is enough 35 RIF_sar: ; sar - search and replace 36 Push "$R3" ; (hair)stack 37 Push "$1" ; needle 38 Push "$0" ; blood 39 Call StrRep ; do the bartwalk 40 StrCpy $R4 "$R3" ; remember previous state 41 Pop $R3 ; gimme s.th. back in return! 42 StrCmp "$R3" "$R4" +1 RIF_sar ; loop, might change again! 43 FileWrite $R1 "$R3" ; save the newbie 44 Goto RIF_loop ; gimme more 45 46 RIF_leaveloop: ; over'n'out, Sir! 47 FileClose $R1 ; S'rry, Ma'am - clos'n now 48 FileClose $R0 ; me 2 49 50 Delete "$2.old" ; go away, Sire 51 Rename "$2" "$2.old" ; step aside, Ma'am 52 Rename "$R2" "$2" ; hi, baby! 53 54 ClearErrors ; now i AM a newborn 55 Goto RIF_out ; out'n'away 56 57 RIF_error: ; ups - s.th. went wrong... 58 SetErrors ; ...so cry, boy! 59 60 RIF_out: ; your wardrobe? 61 Pop $R4 62 Pop $R3 63 Pop $R2 64 Pop $R1 65 Pop $R0 66 Pop $2 67 Pop $0 68 Pop $1 69 70FunctionEnd 71