summaryrefslogtreecommitdiff
path: root/packaging/Win32/suite_installer.nsi
blob: 038074c02111d1bb499c49a6ed5941fa7fadfa2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
;THIS IS NOT A FINISHED SCRIPT -- DO NOT RUN

; Script generated by the HM NIS Edit Script Wizard.

; HM NIS Edit Wizard helper defines
; NE1 Defines
!define PRODUCT_NAME "NanoEngineer-1 Suite"
!define PRODUCT_VERSION "1.0.0b5"
!define PRODUCT_NICKNAME "(Alpha 10)"
!define PRODUCT_PUBLISHER "Nanorex, Inc."
!define PRODUCT_WEB_SITE "http://www.nanoengineer-1.com"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\${PRODUCT_NAME}\${PRODUCT_VERSION}"
;!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\babel.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"

;QMX Defines
!define PRODUCT_QMX_VERSION "0.5.0b1"
!define PRODUCT_QMX_NAME "QuteMolX"
!define PRODUCT_QMX_PUBLISHER "Nanorex, Inc"
!define PRODUCT_QMX_WEB_SITE "http://www.nanoengineer-1.com/QuteMolX/"
!define PRODUCT_QMX_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\${PRODUCT_NAME}\${PRODUCT_QMX_VERSION}"
!define PRODUCT_QMX_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_QMX_UNINST_ROOT_KEY "HKLM"

;GMX Defines
!define PRODUCT_GMX_VERSION "3.3.2b1"
!define PRODUCT_GMX_NAME "GROMACS_HDF5"
!define PRODUCT_GMX_PUBLISHER "Nanorex, Inc"
!define PRODUCT_GMX_WEB_SITE "http://www.nanorex.com"
!define PRODUCT_GMX_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\${PRODUCT_NAME}\${PRODUCT_GMX_VERSION}"
!define PRODUCT_GMX_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_GMX_UNINST_ROOT_KEY "HKLM"

;NV1 Defines
!define PRODUCT_NV1_VERSION "0.1.0a1"
!define PRODUCT_NV1_NAME "NanoVision-1 ${PRODUCT_NV1_VERSION}"
!define PRODUCT_NV1_PUBLISHER "Nanorex, Inc"
!define PRODUCT_NV1_WEB_SITE "http://www.nanorex.com"
!define PRODUCT_NV1_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\nv1.exe"
!define PRODUCT_NV1_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_NV1_UNINST_ROOT_KEY "HKLM"

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

; MUI 1.67 compatible ------
!include "MUI.nsh"

; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "install.ico"
!define MUI_UNICON "uninstall.ico"
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "install-header.bmp"
!define MUI_HEADERIMAGE_UNBITMAP "install-header.bmp"
!define MUI_WELCOMEFINISHPAGE_BITMAP "wizard-sidebar.bmp"
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "wizard-sidebar.bmp"

; Welcome page
!insertmacro MUI_PAGE_WELCOME
; License page
!insertmacro MUI_PAGE_LICENSE "..\..\cad\src\dist\Licenses\NanoEngineer-1_License.txt"
; Components page
!insertmacro MUI_PAGE_COMPONENTS
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!define MUI_FINISHPAGE_RUN "$INSTDIR\program\main.exe"
!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\ReadMe.html"
!insertmacro MUI_PAGE_FINISH

; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES

; Language files
!insertmacro MUI_LANGUAGE "English"

; MUI end ------

Name "${PRODUCT_NAME} ${PRODUCT_VERSION} ${PRODUCT_NICKNAME}"
OutFile "..\..\cad\src\build\NanoEngineer-1_${PRODUCT_VERSION}.exe"
;InstallDir "$PROGRAMFILES\Nanorex\NanoEngineer-1_${PRODUCT_VERSION}"
InstallDir "$PROGRAMFILES\Nanorex"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
;InstallDirRegKey HKLM "${PRODUCT_QMX_DIR_REGKEY}" ""
;InstallDirRegKey HKLM "${PRODUCT_GMX_DIR_REGKEY}" ""
;InstallDirRegKey HKLM "${PRODUCT_NV1_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show

SectionGroup /e "NanoEngineer-1 Suite Installer"
Section "NanoEngineer-1" SECNE1
  SetOutPath "$INSTDIR\NanoEngineer-1_${PRODUCT_VERSION}"
  SetOverwrite try
  File /r "..\..\cad\src\dist\*"
  
  ; hack
;  SetOutPath "$INSTDIR\NanoEngineer-1_${PRODUCT_VERSION}\program"
;  File "C:\Qt\4.2.3\bin\QtSvg4.dll"
  
;  SetOutPath "$SYSDIR"
;  SetOverwrite off
;  File "glut32.dll"
;  File "gle32.dll"
  CreateDirectory "$SMPROGRAMS\Nanorex\NanoEngineer-1 ${PRODUCT_VERSION}"
  CreateShortCut "$SMPROGRAMS\Nanorex\NanoEngineer-1 ${PRODUCT_VERSION}\NanoEngineer-1.lnk" "$INSTDIR\NanoEngineer-1_${PRODUCT_VERSION}\program\main.exe"
  CreateShortCut "$DESKTOP\NanoEngineer-1.lnk" "$INSTDIR\NanoEngineer-1_${PRODUCT_VERSION}\program\main.exe"
  CreateShortCut "$SMPROGRAMS\Nanorex\NanoEngineer-1 ${PRODUCT_VERSION}\ReadMe.html.lnk" "$INSTDIR\NanoEngineer-1_${PRODUCT_VERSION}\ReadMe.html"
  SetOutPath "$INSTDIR"
SectionEnd

SectionGroup /e "QuteMolX"
Section "QuteMolX (Required)" SEC_QMX_BASE
  SetOutPath "$INSTDIR\QuteMolX"
  SetOverwrite try
  File "\QMX_Install\License.txt"
  File "\QMX_Install\ReadMe.html"
  File "\QMX_Install\build\*"
  SetOutPath "$INSTDIR\QuteMolX\image"
  File "build\image\*"
  SetOutPath "$INSTDIR\QuteMolX\presets"
  File "\QMX_Install\build\presets\*"
  SetOutPath "$INSTDIR\QuteMolX"
  CreateDirectory "$SMPROGRAMS\Nanorex\QuteMolX"
  CreateShortCut "$SMPROGRAMS\Nanorex\QuteMolX\QuteMolX.lnk" "$INSTDIR\QuteMolX\QuteMolX.exe"
  CreateShortCut "$DESKTOP\QuteMolX.lnk" "$INSTDIR\QuteMolX\QuteMolX.exe"
SectionEnd
Section /o "Source" SEC_QMX_SRC
  SetOutPath "$INSTDIR\QuteMolX\source"
  SetOverwrite try
  File /r "\QMX_Install\source\*"
  SetOutPath "$INSTDIR"
SectionEnd
SectionGroupEnd

SectionGroup /e "NanoVision-1"
Section "NanoVision-1 Base" NV1_BASE
  SetOutPath "$INSTDIR\NanoVision-1\bin"
  SetOverwrite try
  File "\NV1_Install\bin\*"
  CreateDirectory "$SMPROGRAMS\Nanorex\NanoVision-1"
  CreateShortCut "$SMPROGRAMS\Nanorex\NanoVision-1\NanoVision-1.lnk" "$INSTDIR\NanoVision-1\bin\nv1.exe"
  CreateShortCut "$DESKTOP\NanoVision-1.lnk" "$INSTDIR\NanoVision-1\bin\nv1.exe"
  SetOutPath "$INSTDIR\NanoVision-1\include"
  File /r "\NV1_Install\include\*"
  SetOutPath "$INSTDIR\NanoVision-1\lib"
  File /r "\NV1_Install\lib\*"
  SetOutPath "$INSTDIR\NanoVision-1"
  SetOverwrite  on
  File "\NV1_Install\ReadMe.html"
  File "\NV1_Install\License.txt"
  SetOutPath "$APPDATA\Nanorex\NanoVision-1"
  File "\NV1_Install\NanoVision-1.ini"
  Push "$INSTDIR\NanoVision-1\lib"
  Push "\"
  Push "/"
  Call StrRep
  Pop "$R0" ;result
  !insertmacro ReplaceInFile "$APPDATA\Nanorex\NanoVision-1\NanoVision-1.ini" "@PLUGSRCHPATH@" "$R0"
  SetOutPath "$INSTDIR"
SectionEnd

Section /o "source" NV1_SRC
  SetOutPath "$INSTDIR\NanoVision-1\source"
  File /r "\NV1_Install\src\*"
SectionEnd
SectionGroupEnd

SectionGroup /e "GROMACS"
Section "GROMACS+HDF5 (Required)" SEC_GMX_BASE
;  SetOutPath "$INSTDIR"
  SetOutPath "c:\GROMACS_HDF5"
  SetOverwrite try
  File "\GMX_Install\ReadMe.html"
  File "\GMX_Install\.\License.txt"
  SetOutPath "c:\GROMACS_HDF5\bin"
  SetOverwrite try
  File "\GMX_Install\dist\bin\*"
SectionEnd
Section /o "Headers & Libraries" SEC_GMX_LIBHDR
  SetOutPath "c:\GROMACS_HDF5\include\gromacs"
  File "\GMX_Install\dist\include\gromacs\*"
  SetOutPath "c:\GROMACS_HDF5\include\gromacs\types"
  File "\GMX_Install\dist\include\gromacs\types\*"
  SetOutPath "c:\GROMACS_HDF5\include\gromacs"
  File "\GMX_Install\dist\include\gromacs\*"
  SetOutPath "c:\GROMACS_HDF5\lib"
  File "\GMX_Install\dist\lib\*"
SectionEnd
Section "Documentation" SEC_GMX_DOC
  SetOverwrite try
  SetOutPath "c:\GROMACS_HDF5\share\gromacs\html"
  File "\GMX_Install\dist\share\gromacs\html\*"
  SetOutPath "c:\GROMACS_HDF5\share\gromacs\html\images"
  File "\GMX_Install\dist\share\gromacs\html\images\*"
  SetOutPath "c:\GROMACS_HDF5\share\gromacs\html\online"
  File "\GMX_Install\dist\share\gromacs\html\online\*"
  SetOutPath "c:\GROMACS_HDF5\share\gromacs\template"
  File "\GMX_Install\dist\share\gromacs\template\*"
  SetOutPath "c:\GROMACS_HDF5\share\gromacs\top"
  File "\GMX_Install\dist\share\gromacs\top\*"
SectionEnd
Section "Tutorials" SEC_GMX_TUTOR
  SetOverwrite try
  SetOutPath "c:\GROMACS_HDF5\share\gromacs\tutor"
  File "\GMX_Install\dist\share\gromacs\tutor\*"
  SetOutPath "c:\GROMACS_HDF5\share\gromacs\tutor\gmxdemo"
  File "\GMX_Install\dist\share\gromacs\tutor\gmxdemo\*"
  SetOutPath "c:\GROMACS_HDF5\share\gromacs\tutor\methanol"
  File "\GMX_Install\dist\share\gromacs\tutor\methanol\*"
  SetOutPath "c:\GROMACS_HDF5\share\gromacs\tutor\mixed"
  File "\GMX_Install\dist\share\gromacs\tutor\mixed\*"
  SetOutPath "c:\GROMACS_HDF5\share\gromacs\tutor\nmr1"
  File "\GMX_Install\dist\share\gromacs\tutor\nmr1\*"
  SetOutPath "c:\GROMACS_HDF5\share\gromacs\tutor\nmr2"
  File "\GMX_Install\dist\share\gromacs\tutor\nmr2\*"
  SetOutPath "c:\GROMACS_HDF5\share\gromacs\tutor\speptide"
  File "\GMX_Install\dist\share\gromacs\tutor\speptide\*"
  SetOutPath "c:\GROMACS_HDF5\share\gromacs\tutor\water"
  File "\GMX_Install\dist\share\gromacs\tutor\water\*"
SectionEnd
Section /o "Source" SEC_GMX_SRC
  SetOverwrite try
  SetOutPath "c:\GROMACS_HDF5\source"
  file /r "\GMX_Install\dist\src\gromacs-3.3.2\*"
SectionEnd
SectionGroupEnd

SectionGroup /e "MCPP"
Section "MCPP (Required)" SEC_MCPP
  SetOutPath "c:\GROMACS_HDF5\MCPP\bin"
  File "\GMX_Install\mcpp\bin\mcpp.exe"
  SetOutPath "c:\GROMACS_HDF5\MCPP"
  File "\GMX_Install\mcpp\LICENSE"
  File "\GMX_Install\mcpp\mcpp-manual-jp.html"
  File "\GMX_Install\mcpp\mcpp-manual.html"
  File "\GMX_Install\mcpp\NEWS"
  File "\GMX_Install\mcpp\README"
SectionEnd
Section /o "Source" SEC_MCPP_SRC
  SetOutPath "c:\GROMACS_HDF5MCPP\source"
  File /r "\GMX_Install\mcpp\source\*"
SectionEnd
SectionGroupEnd

SectionGroupEnd

Section -AdditionalIcons
  SetOutPath $INSTDIR
  CreateShortCut "$SMPROGRAMS\Nanorex\NanoEngineer-1 ${PRODUCT_VERSION}\partlib.lnk" "$INSTDIR\NanoEngineer-1_${PRODUCT_VERSION}\partlib"
  CreateShortCut "$SMPROGRAMS\Nanorex\NanoEngineer-1 ${PRODUCT_VERSION}\Licenses.lnk" "$INSTDIR\NanoEngineer-1_${PRODUCT_VERSION}\Licenses"
  CreateShortCut "$SMPROGRAMS\Nanorex\NanoEngineer-1 ${PRODUCT_VERSION}\Uninstall.lnk" "$INSTDIR\uninst.exe"
  WriteIniStr "$INSTDIR\NanoVision-1\${PRODUCT_NV1_NAME}-${PRODUCT_NV1_VERSION.url" "InternetShortcut" "URL" "${PRODUCT_NV1_WEB_SITE}"
  CreateShortCut "$SMPROGRAMS\Nanorex\NanoVision-1\Website.lnk" "$INSTDIR\NanoVision-1\${PRODUCT_NV1_NAME}.url"
  WriteIniStr "$INSTDIR\QuteMolX\${PRODUCT_QMX_NAME}-${PRODUCT_QMX_VERSION.url" "InternetShortcut" "URL" "${PRODUCT_QMX_WEB_SITE}"
  CreateShortCut "$SMPROGRAMS\Nanorex\QuteMolX\Website.lnk" "$INSTDIR\QuteMolX\${PRODUCT_QMX_NAME}.url"
SectionEnd

Section -Post
  WriteUninstaller "$INSTDIR\uninst.exe"
  WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\program\main.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\program\main.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd


Function un.onUninstSuccess
  HideWindow
  MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer."
FunctionEnd

Function un.onInit
  MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2
  Abort
FunctionEnd

Section Uninstall
  Delete "$INSTDIR\*"
  RMDir /r "$INSTDIR\src"
  RMDir /r "$INSTDIR\program"
  RMDir /r "$INSTDIR\plugins"
  RMDir /r "$INSTDIR\partlib"
  RMDir /r "$INSTDIR\Licenses"
  RMDir /r "$INSTDIR\doc"
  RMDir /r "$INSTDIR\bin"
  RMDir /r "$INSTDIR"
  RMDir /r "C:\GROMACS_HDF5"

  Delete "$DESKTOP\NanoEngineer-1.lnk"
  Delete "$DESKTOP\NanoVision-1.lnk"
  Delete "$DESKTOP\QuteMolX.lnk"

  RMDir /r "$SMPROGRAMS\NanoEngineer-1 ${PRODUCT_VERSION}"
  RMDir /r "$SMPROGRAMS\Nanorex"

  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
  SetAutoClose true

SectionEnd

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function RIF
  ClearErrors  ; wanna 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!
    Delete "$2.old"                 ; Nano-Hive addition

    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

Function StrReplace
  Exch $0 ;this will replace wrong characters
  Exch
  Exch $1 ;needs to be replaced
  Exch
  Exch 2
  Exch $2 ;the orginal string
  Push $3 ;counter
  Push $4 ;temp character
  Push $5 ;temp string
  Push $6 ;length of string that need to be replaced
  Push $7 ;length of string that will replace
  Push $R0 ;tempstring
  Push $R1 ;tempstring
  Push $R2 ;tempstring
  StrCpy $3 "-1"
  StrCpy $5 ""
  StrLen $6 $1
  StrLen $7 $0
  Loop:
  IntOp $3 $3 + 1
  StrCpy $4 $2 $6 $3
  StrCmp $4 "" ExitLoop
  StrCmp $4 $1 Replace
  Goto Loop
  Replace:
  StrCpy $R0 $2 $3
  IntOp $R2 $3 + $6
  StrCpy $R1 $2 "" $R2
  StrCpy $2 $R0$0$R1
  IntOp $3 $3 + $7
  Goto Loop
  ExitLoop:
  StrCpy $0 $2
  Pop $R2
  Pop $R1
  Pop $R0
  Pop $7
  Pop $6
  Pop $5
  Pop $4
  Pop $3
  Pop $2
  Pop $1
  Exch $0
FunctionEnd

Function StrRep
  Exch $R4 ; $R4 = Replacement String
  Exch
  Exch $R3 ; $R3 = String to replace (needle)
  Exch 2
  Exch $R1 ; $R1 = String to do replacement in (haystack)
  Push $R2 ; Replaced haystack
  Push $R5 ; Len (needle)
  Push $R6 ; len (haystack)
  Push $R7 ; Scratch reg
  StrCpy $R2 ""
  StrLen $R5 $R3
  StrLen $R6 $R1
loop:
  StrCpy $R7 $R1 $R5
  StrCmp $R7 $R3 found
  StrCpy $R7 $R1 1 ; - optimization can be removed if U know len needle=1
  StrCpy $R2 "$R2$R7"
  StrCpy $R1 $R1 $R6 1
  StrCmp $R1 "" done loop
found:
  StrCpy $R2 "$R2$R4"
  StrCpy $R1 $R1 $R6 $R5
  StrCmp $R1 "" done loop
done:
  StrCpy $R3 $R2
  Pop $R7
  Pop $R6
  Pop $R5
  Pop $R2
  Pop $R1
  Pop $R4
  Exch $R3
FunctionEnd