Debian Codegraph @

cmake/include/NSIS.template.in

raw
1 ; CPack install script designed for a nmake build
2
3 ;--------------------------------
4 ; You must define these values
5
6 !define VERSION "@CPACK_PACKAGE_VERSION@"
7 !define PATCH "@CPACK_PACKAGE_VERSION_PATCH@"
8 !define INST_DIR "@CPACK_TEMPORARY_DIRECTORY@"
9
10 !define UKP "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
11
12 ;--------------------------------
13 ;Variables
14
15 Var MUI_TEMP
16 Var STARTMENU_FOLDER
17 Var SV_ALLUSERS
18 Var START_MENU
19 Var DO_NOT_ADD_TO_PATH
20 Var ADD_TO_PATH_ALL_USERS
21 Var ADD_TO_PATH_CURRENT_USER
22 Var INSTALL_DESKTOP
23 Var IS_DEFAULT_INSTALLDIR
24 ; The already INstalled Version bits.
25 Var INVMAJOR
26 Var INVMINOR
27 Var INVPATCH
28 Var UNINSTALLER_DIR
29 ;--------------------------------
30 ;Include Modern UI
31
32 !include "MUI.nsh"
33
34 ;Default installation folder
35 InstallDir "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
36
37 ;--------------------------------
38 ;General
39
40 ;Name and file
41 Name "@CPACK_NSIS_PACKAGE_NAME@"
42 OutFile "@CPACK_TOPLEVEL_DIRECTORY@/@CPACK_OUTPUT_FILE_NAME@"
43
44 ;Set compression
45 SetCompressor @CPACK_NSIS_COMPRESSOR@
46
47 @CPACK_NSIS_DEFINES@
48
49 !include Sections.nsh
50
51 ;--- Component support macros: ---
52 ; The code for the add/remove functionality is from:
53 ; http://nsis.sourceforge.net/Add/Remove_Functionality
54 ; It has been modified slightly and extended to provide
55 ; inter-component dependencies.
56 Var AR_SecFlags
57 Var AR_RegFlags
58 @CPACK_NSIS_SECTION_SELECTED_VARS@
59
60 ; Loads the "selected" flag for the section named SecName into the
61 ; variable VarName.
62 !macro LoadSectionSelectedIntoVar SecName VarName
63 SectionGetFlags ${${SecName}} $${VarName}
64 IntOp $${VarName} $${VarName} & ${SF_SELECTED} ;Turn off all other bits
65 !macroend
66
67 ; Loads the value of a variable... can we get around this?
68 !macro LoadVar VarName
69 IntOp $R0 0 + $${VarName}
70 !macroend
71
72 ; Sets the value of a variable
73 !macro StoreVar VarName IntValue
74 IntOp $${VarName} 0 + ${IntValue}
75 !macroend
76
77 !macro InitSection SecName
78 ; This macro reads component installed flag from the registry and
79 ;changes checked state of the section on the components page.
80 ;Input: section index constant name specified in Section command.
81
82 ClearErrors
83 ;Reading component status from registry
84 ReadRegDWORD $AR_RegFlags HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" "Installed"
85 IfErrors "default_${SecName}"
86 ;Status will stay default if registry value not found
87 ;(component was never installed)
88 IntOp $AR_RegFlags $AR_RegFlags & ${SF_SELECTED} ;Turn off all other bits
89 SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading default section flags
90 IntOp $AR_SecFlags $AR_SecFlags & 0xFFFE ;Turn lowest (enabled) bit off
91 IntOp $AR_SecFlags $AR_RegFlags | $AR_SecFlags ;Change lowest bit
92
93 ; Note whether this component was installed before
94 !insertmacro StoreVar ${SecName}_was_installed $AR_RegFlags
95 IntOp $R0 $AR_RegFlags & $AR_RegFlags
96
97 ;Writing modified flags
98 SectionSetFlags ${${SecName}} $AR_SecFlags
99
100 "default_${SecName}:"
101 !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected
102 !macroend
103
104 !macro FinishSection SecName
105 ; This macro reads section flag set by user and removes the section
106 ;if it is not selected.
107 ;Then it writes component installed flag to registry
108 ;Input: section index constant name specified in Section command.
109
110 SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading section flags
111 ;Checking lowest bit:
112 IntOp $AR_SecFlags $AR_SecFlags & ${SF_SELECTED}
113 IntCmp $AR_SecFlags 1 "leave_${SecName}"
114 ;Section is not selected:
115 ;Calling Section uninstall macro and writing zero installed flag
116 !insertmacro "Remove_${${SecName}}"
117 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" \
118 "Installed" 0
119 Goto "exit_${SecName}"
120
121 "leave_${SecName}:"
122 ;Section is selected:
123 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" \
124 "Installed" 1
125
126 "exit_${SecName}:"
127 !macroend
128
129 !macro RemoveSection SecName
130 ; This macro is used to call section's Remove_... macro
131 ;from the uninstaller.
132 ;Input: section index constant name specified in Section command.
133
134 !insertmacro "Remove_${${SecName}}"
135 !macroend
136
137 ; Determine whether the selection of SecName changed
138 !macro MaybeSelectionChanged SecName
139 !insertmacro LoadVar ${SecName}_selected
140 SectionGetFlags ${${SecName}} $R1
141 IntOp $R1 $R1 & ${SF_SELECTED} ;Turn off all other bits
142
143 ; See if the status has changed:
144 IntCmp $R0 $R1 "${SecName}_unchanged"
145 !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected
146
147 IntCmp $R1 ${SF_SELECTED} "${SecName}_was_selected"
148 !insertmacro "Deselect_required_by_${SecName}"
149 goto "${SecName}_unchanged"
150
151 "${SecName}_was_selected:"
152 !insertmacro "Select_${SecName}_depends"
153
154 "${SecName}_unchanged:"
155 !macroend
156 ;--- End of Add/Remove macros ---
157
158 ;--------------------------------
159 ;Interface Settings
160
161 !define MUI_HEADERIMAGE
162 !define MUI_ABORTWARNING
163
164 ;--------------------------------
165 ; path functions
166
167 !verbose 3
168 !include "WinMessages.NSH"
169 !verbose 4
170
171 ;----------------------------------------
172 ; based upon a script of "Written by KiCHiK 2003-01-18 05:57:02"
173 ;----------------------------------------
174 !verbose 3
175 !include "WinMessages.NSH"
176 !verbose 4
177 ;====================================================
178 ; get_NT_environment
179 ; Returns: the selected environment
180 ; Output : head of the stack
181 ;====================================================
182 !macro select_NT_profile UN
183 Function ${UN}select_NT_profile
184 StrCmp $ADD_TO_PATH_ALL_USERS "1" 0 environment_single
185 DetailPrint "Selected environment for all users"
186 Push "all"
187 Return
188 environment_single:
189 DetailPrint "Selected environment for current user only."
190 Push "current"
191 Return
192 FunctionEnd
193 !macroend
194 !insertmacro select_NT_profile ""
195 !insertmacro select_NT_profile "un."
196 ;----------------------------------------------------
197 !define NT_current_env 'HKCU "Environment"'
198 !define NT_all_env 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
199
200 !ifndef WriteEnvStr_RegKey
201 !ifdef ALL_USERS
202 !define WriteEnvStr_RegKey \
203 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
204 !else
205 !define WriteEnvStr_RegKey 'HKCU "Environment"'
206 !endif
207 !endif
208
209 ; AddToPath - Adds the given dir to the search path.
210 ; Input - head of the stack
211 ; Note - Win9x systems requires reboot
212
213 Function AddToPath
214 Exch $0
215 Push $1
216 Push $2
217 Push $3
218
219 # don't add if the path doesn't exist
220 IfFileExists "$0\*.*" "" AddToPath_done
221
222 ReadEnvStr $1 PATH
223 ; if the path is too long for a NSIS variable NSIS will return a 0
224 ; length string. If we find that, then warn and skip any path
225 ; modification as it will trash the existing path.
226 StrLen $2 $1
227 IntCmp $2 0 CheckPathLength_ShowPathWarning CheckPathLength_Done CheckPathLength_Done
228 CheckPathLength_ShowPathWarning:
229 Messagebox MB_OK|MB_ICONEXCLAMATION "Warning! PATH too long installer unable to modify PATH!"
230 Goto AddToPath_done
231 CheckPathLength_Done:
232 Push "$1;"
233 Push "$0;"
234 Call StrStr
235 Pop $2
236 StrCmp $2 "" "" AddToPath_done
237 Push "$1;"
238 Push "$0\;"
239 Call StrStr
240 Pop $2
241 StrCmp $2 "" "" AddToPath_done
242 GetFullPathName /SHORT $3 $0
243 Push "$1;"
244 Push "$3;"
245 Call StrStr
246 Pop $2
247 StrCmp $2 "" "" AddToPath_done
248 Push "$1;"
249 Push "$3\;"
250 Call StrStr
251 Pop $2
252 StrCmp $2 "" "" AddToPath_done
253
254 Call IsNT
255 Pop $1
256 StrCmp $1 1 AddToPath_NT
257 ; Not on NT
258 StrCpy $1 $WINDIR 2
259 FileOpen $1 "$1\autoexec.bat" a
260 FileSeek $1 -1 END
261 FileReadByte $1 $2
262 IntCmp $2 26 0 +2 +2 # DOS EOF
263 FileSeek $1 -1 END # write over EOF
264 FileWrite $1 "$\r$\nSET PATH=%PATH%;$3$\r$\n"
265 FileClose $1
266 SetRebootFlag true
267 Goto AddToPath_done
268
269 AddToPath_NT:
270 StrCmp $ADD_TO_PATH_ALL_USERS "1" ReadAllKey
271 ReadRegStr $1 ${NT_current_env} "PATH"
272 Goto DoTrim
273 ReadAllKey:
274 ReadRegStr $1 ${NT_all_env} "PATH"
275 DoTrim:
276 StrCmp $1 "" AddToPath_NTdoIt
277 Push $1
278 Call Trim
279 Pop $1
280 StrCpy $0 "$1;$0"
281 AddToPath_NTdoIt:
282 StrCmp $ADD_TO_PATH_ALL_USERS "1" WriteAllKey
283 WriteRegExpandStr ${NT_current_env} "PATH" $0
284 Goto DoSend
285 WriteAllKey:
286 WriteRegExpandStr ${NT_all_env} "PATH" $0
287 DoSend:
288 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
289
290 AddToPath_done:
291 Pop $3
292 Pop $2
293 Pop $1
294 Pop $0
295 FunctionEnd
296
297
298 ; RemoveFromPath - Remove a given dir from the path
299 ; Input: head of the stack
300
301 Function un.RemoveFromPath
302 Exch $0
303 Push $1
304 Push $2
305 Push $3
306 Push $4
307 Push $5
308 Push $6
309
310 IntFmt $6 "%c" 26 # DOS EOF
311
312 Call un.IsNT
313 Pop $1
314 StrCmp $1 1 unRemoveFromPath_NT
315 ; Not on NT
316 StrCpy $1 $WINDIR 2
317 FileOpen $1 "$1\autoexec.bat" r
318 GetTempFileName $4
319 FileOpen $2 $4 w
320 GetFullPathName /SHORT $0 $0
321 StrCpy $0 "SET PATH=%PATH%;$0"
322 Goto unRemoveFromPath_dosLoop
323
324 unRemoveFromPath_dosLoop:
325 FileRead $1 $3
326 StrCpy $5 $3 1 -1 # read last char
327 StrCmp $5 $6 0 +2 # if DOS EOF
328 StrCpy $3 $3 -1 # remove DOS EOF so we can compare
329 StrCmp $3 "$0$\r$\n" unRemoveFromPath_dosLoopRemoveLine
330 StrCmp $3 "$0$\n" unRemoveFromPath_dosLoopRemoveLine
331 StrCmp $3 "$0" unRemoveFromPath_dosLoopRemoveLine
332 StrCmp $3 "" unRemoveFromPath_dosLoopEnd
333 FileWrite $2 $3
334 Goto unRemoveFromPath_dosLoop
335 unRemoveFromPath_dosLoopRemoveLine:
336 SetRebootFlag true
337 Goto unRemoveFromPath_dosLoop
338
339 unRemoveFromPath_dosLoopEnd:
340 FileClose $2
341 FileClose $1
342 StrCpy $1 $WINDIR 2
343 Delete "$1\autoexec.bat"
344 CopyFiles /SILENT $4 "$1\autoexec.bat"
345 Delete $4
346 Goto unRemoveFromPath_done
347
348 unRemoveFromPath_NT:
349 StrCmp $ADD_TO_PATH_ALL_USERS "1" unReadAllKey
350 ReadRegStr $1 ${NT_current_env} "PATH"
351 Goto unDoTrim
352 unReadAllKey:
353 ReadRegStr $1 ${NT_all_env} "PATH"
354 unDoTrim:
355 StrCpy $5 $1 1 -1 # copy last char
356 StrCmp $5 ";" +2 # if last char != ;
357 StrCpy $1 "$1;" # append ;
358 Push $1
359 Push "$0;"
360 Call un.StrStr ; Find `$0;` in $1
361 Pop $2 ; pos of our dir
362 StrCmp $2 "" unRemoveFromPath_done
363 ; else, it is in path
364 # $0 - path to add
365 # $1 - path var
366 StrLen $3 "$0;"
367 StrLen $4 $2
368 StrCpy $5 $1 -$4 # $5 is now the part before the path to remove
369 StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove
370 StrCpy $3 $5$6
371
372 StrCpy $5 $3 1 -1 # copy last char
373 StrCmp $5 ";" 0 +2 # if last char == ;
374 StrCpy $3 $3 -1 # remove last char
375
376 StrCmp $ADD_TO_PATH_ALL_USERS "1" unWriteAllKey
377 WriteRegExpandStr ${NT_current_env} "PATH" $3
378 Goto unDoSend
379 unWriteAllKey:
380 WriteRegExpandStr ${NT_all_env} "PATH" $3
381 unDoSend:
382 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
383
384 unRemoveFromPath_done:
385 Pop $6
386 Pop $5
387 Pop $4
388 Pop $3
389 Pop $2
390 Pop $1
391 Pop $0
392 FunctionEnd
393
394 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
395 ; Uninstall sutff
396 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
397
398 ###########################################
399 # Utility Functions #
400 ###########################################
401
402 ;====================================================
403 ; IsNT - Returns 1 if the current system is NT, 0
404 ; otherwise.
405 ; Output: head of the stack
406 ;====================================================
407 ; IsNT
408 ; no input
409 ; output, top of the stack = 1 if NT or 0 if not
410 ;
411 ; Usage:
412 ; Call IsNT
413 ; Pop $R0
414 ; ($R0 at this point is 1 or 0)
415
416 !macro IsNT un
417 Function ${un}IsNT
418 Push $0
419 ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
420 StrCmp $0 "" 0 IsNT_yes
421 ; we are not NT.
422 Pop $0
423 Push 0
424 Return
425
426 IsNT_yes:
427 ; NT!!!
428 Pop $0
429 Push 1
430 FunctionEnd
431 !macroend
432 !insertmacro IsNT ""
433 !insertmacro IsNT "un."
434
435 ; StrStr
436 ; input, top of stack = string to search for
437 ; top of stack-1 = string to search in
438 ; output, top of stack (replaces with the portion of the string remaining)
439 ; modifies no other variables.
440 ;
441 ; Usage:
442 ; Push "this is a long ass string"
443 ; Push "ass"
444 ; Call StrStr
445 ; Pop $R0
446 ; ($R0 at this point is "ass string")
447
448 !macro StrStr un
449 Function ${un}StrStr
450 Exch $R1 ; st=haystack,old$R1, $R1=needle
451 Exch ; st=old$R1,haystack
452 Exch $R2 ; st=old$R1,old$R2, $R2=haystack
453 Push $R3
454 Push $R4
455 Push $R5
456 StrLen $R3 $R1
457 StrCpy $R4 0
458 ; $R1=needle
459 ; $R2=haystack
460 ; $R3=len(needle)
461 ; $R4=cnt
462 ; $R5=tmp
463 loop:
464 StrCpy $R5 $R2 $R3 $R4
465 StrCmp $R5 $R1 done
466 StrCmp $R5 "" done
467 IntOp $R4 $R4 + 1
468 Goto loop
469 done:
470 StrCpy $R1 $R2 "" $R4
471 Pop $R5
472 Pop $R4
473 Pop $R3
474 Pop $R2
475 Exch $R1
476 FunctionEnd
477 !macroend
478 !insertmacro StrStr ""
479 !insertmacro StrStr "un."
480
481 Function Trim ; Added by Pelaca
482 Exch $R1
483 Push $R2
484 Loop:
485 StrCpy $R2 "$R1" 1 -1
486 StrCmp "$R2" " " RTrim
487 StrCmp "$R2" "$\n" RTrim
488 StrCmp "$R2" "$\r" RTrim
489 StrCmp "$R2" ";" RTrim
490 GoTo Done
491 RTrim:
492 StrCpy $R1 "$R1" -1
493 Goto Loop
494 Done:
495 Pop $R2
496 Exch $R1
497 FunctionEnd
498
499 Function ConditionalAddToRegisty
500 Pop $0
501 Pop $1
502 StrCmp "$0" "" ConditionalAddToRegisty_EmptyString
503 WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" \
504 "$1" "$0"
505 ;MessageBox MB_OK "Set Registry: '$1' to '$0'"
506 DetailPrint "Set install registry entry: '$1' to '$0'"
507 ConditionalAddToRegisty_EmptyString:
508 FunctionEnd
509
510 ;--------------------------------
511
512 !ifdef CPACK_USES_DOWNLOAD
513 Function DownloadFile
514 IfFileExists $INSTDIR\* +2
515 CreateDirectory $INSTDIR
516 Pop $0
517
518 ; Skip if already downloaded
519 IfFileExists $INSTDIR\$0 0 +2
520 Return
521
522 StrCpy $1 "@CPACK_DOWNLOAD_SITE@"
523
524 try_again:
525 NSISdl::download "$1/$0" "$INSTDIR\$0"
526
527 Pop $1
528 StrCmp $1 "success" success
529 StrCmp $1 "Cancelled" cancel
530 MessageBox MB_OK "Download failed: $1"
531 cancel:
532 Return
533 success:
534 FunctionEnd
535 !endif
536
537 ;--------------------------------
538 ; Installation types
539 @CPACK_NSIS_INSTALLATION_TYPES@
540
541 ;--------------------------------
542 ; Component sections
543 @CPACK_NSIS_COMPONENT_SECTIONS@
544
545 ;--------------------------------
546 ; Define some macro setting for the gui
547 @CPACK_NSIS_INSTALLER_MUI_ICON_CODE@
548 @CPACK_NSIS_INSTALLER_ICON_CODE@
549 @CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC@
550 @CPACK_NSIS_INSTALLER_MUI_FINISHPAGE_RUN_CODE@
551
552 ;--------------------------------
553 ;Pages
554 !insertmacro MUI_PAGE_WELCOME
555
556 !insertmacro MUI_PAGE_LICENSE "@CPACK_RESOURCE_FILE_LICENSE@"
557 Page custom InstallOptionsPage
558 !insertmacro MUI_PAGE_DIRECTORY
559
560 ;Start Menu Folder Page Configuration
561 !define MUI_STARTMENUPAGE_REGISTRY_ROOT "SHCTX"
562 !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
563 !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
564 !insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER
565
566 @CPACK_NSIS_PAGE_COMPONENTS@
567
568 !insertmacro MUI_PAGE_INSTFILES
569 !insertmacro MUI_PAGE_FINISH
570
571 !insertmacro MUI_UNPAGE_CONFIRM
572 !insertmacro MUI_UNPAGE_INSTFILES
573
574 ;--------------------------------
575 ;Languages
576
577 !insertmacro MUI_LANGUAGE "English" ;first language is the default language
578 !insertmacro MUI_LANGUAGE "Albanian"
579 !insertmacro MUI_LANGUAGE "Arabic"
580 !insertmacro MUI_LANGUAGE "Basque"
581 !insertmacro MUI_LANGUAGE "Belarusian"
582 !insertmacro MUI_LANGUAGE "Bosnian"
583 !insertmacro MUI_LANGUAGE "Breton"
584 !insertmacro MUI_LANGUAGE "Bulgarian"
585 !insertmacro MUI_LANGUAGE "Croatian"
586 !insertmacro MUI_LANGUAGE "Czech"
587 !insertmacro MUI_LANGUAGE "Danish"
588 !insertmacro MUI_LANGUAGE "Dutch"
589 !insertmacro MUI_LANGUAGE "Estonian"
590 !insertmacro MUI_LANGUAGE "Farsi"
591 !insertmacro MUI_LANGUAGE "Finnish"
592 !insertmacro MUI_LANGUAGE "French"
593 !insertmacro MUI_LANGUAGE "German"
594 !insertmacro MUI_LANGUAGE "Greek"
595 !insertmacro MUI_LANGUAGE "Hebrew"
596 !insertmacro MUI_LANGUAGE "Hungarian"
597 !insertmacro MUI_LANGUAGE "Icelandic"
598 !insertmacro MUI_LANGUAGE "Indonesian"
599 !insertmacro MUI_LANGUAGE "Irish"
600 !insertmacro MUI_LANGUAGE "Italian"
601 !insertmacro MUI_LANGUAGE "Japanese"
602 !insertmacro MUI_LANGUAGE "Korean"
603 !insertmacro MUI_LANGUAGE "Kurdish"
604 !insertmacro MUI_LANGUAGE "Latvian"
605 !insertmacro MUI_LANGUAGE "Lithuanian"
606 !insertmacro MUI_LANGUAGE "Luxembourgish"
607 !insertmacro MUI_LANGUAGE "Macedonian"
608 !insertmacro MUI_LANGUAGE "Malay"
609 !insertmacro MUI_LANGUAGE "Mongolian"
610 !insertmacro MUI_LANGUAGE "Norwegian"
611 !insertmacro MUI_LANGUAGE "Polish"
612 !insertmacro MUI_LANGUAGE "Portuguese"
613 !insertmacro MUI_LANGUAGE "PortugueseBR"
614 !insertmacro MUI_LANGUAGE "Romanian"
615 !insertmacro MUI_LANGUAGE "Russian"
616 !insertmacro MUI_LANGUAGE "Serbian"
617 !insertmacro MUI_LANGUAGE "SerbianLatin"
618 !insertmacro MUI_LANGUAGE "SimpChinese"
619 !insertmacro MUI_LANGUAGE "Slovak"
620 !insertmacro MUI_LANGUAGE "Slovenian"
621 !insertmacro MUI_LANGUAGE "Spanish"
622 !insertmacro MUI_LANGUAGE "Swedish"
623 !insertmacro MUI_LANGUAGE "Thai"
624 !insertmacro MUI_LANGUAGE "TradChinese"
625 !insertmacro MUI_LANGUAGE "Turkish"
626 !insertmacro MUI_LANGUAGE "Ukrainian"
627 !insertmacro MUI_LANGUAGE "Welsh"
628
629
630 ;--------------------------------
631 ;Reserve Files
632
633 ;These files should be inserted before other files in the data block
634 ;Keep these lines before any File command
635 ;Only for solid compression (by default, solid compression is enabled for BZIP2 and LZMA)
636
637 ReserveFile "NSIS.InstallOptions.ini"
638 !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
639
640 ;--------------------------------
641 ;Installer Sections
642
643 Section "-Core installation"
644 ;Use the entire tree produced by the INSTALL target. Keep the
645 ;list of directories here in sync with the RMDir commands below.
646 SetOutPath "$INSTDIR"
647 @CPACK_NSIS_FULL_INSTALL@
648
649 ;Store installation folder
650 WriteRegStr SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "" $INSTDIR
651 WriteRegStr SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "cmdinterpreter" "$INSTDIR\bin\wxlauncher.exe"
652
653 ;Create uninstaller
654 WriteUninstaller "$INSTDIR\Uninstall.exe"
655 Push "DisplayName"
656 Push "@CPACK_NSIS_DISPLAY_NAME@"
657 Call ConditionalAddToRegisty
658 Push "DisplayVersion"
659 Push "@CPACK_PACKAGE_VERSION@"
660 Call ConditionalAddToRegisty
661 Push "Publisher"
662 Push "@CPACK_PACKAGE_VENDOR@"
663 Call ConditionalAddToRegisty
664 Push "UninstallString"
665 Push "$INSTDIR\Uninstall.exe"
666 Call ConditionalAddToRegisty
667 Push "NoRepair"
668 Push "1"
669 Call ConditionalAddToRegisty
670
671 !ifdef CPACK_NSIS_ADD_REMOVE
672 ;Create add/remove functionality
673 Push "ModifyPath"
674 Push "$INSTDIR\AddRemove.exe"
675 Call ConditionalAddToRegisty
676 !else
677 Push "NoModify"
678 Push "1"
679 Call ConditionalAddToRegisty
680 !endif
681
682 ; Optional registration
683 Push "DisplayIcon"
684 Push "$INSTDIR\bin\wxlauncher.exe"
685 Call ConditionalAddToRegisty
686 Push "HelpLink"
687 Push "@CPACK_NSIS_HELP_LINK@"
688 Call ConditionalAddToRegisty
689 Push "URLInfoAbout"
690 Push "@CPACK_NSIS_URL_INFO_ABOUT@"
691 Call ConditionalAddToRegisty
692 Push "Contact"
693 Push "@CPACK_NSIS_CONTACT@"
694 Call ConditionalAddToRegisty
695 Push "VersionMajor"
696 Push "@CPACK_PACKAGE_VERSION_MAJOR@"
697 Call ConditionalAddToRegisty
698 Push "VersionMinor"
699 Push "@CPACK_PACKAGE_VERSION_MINOR@"
700 Call ConditionalAddToRegisty
701 Push "VersionPatch"
702 Push "@CPACK_PACKAGE_VERSION_PATCH@"
703 Call ConditionalAddToRegisty
704 Push ""
705 Push "$INSTDIR"
706 Call ConditionalAddToRegisty
707 !insertmacro MUI_INSTALLOPTIONS_READ $INSTALL_DESKTOP "NSIS.InstallOptions.ini" "Field 5" "State"
708 !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
709
710 ;Create shortcuts
711 CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER"
712 @CPACK_NSIS_CREATE_ICONS@
713 @CPACK_NSIS_CREATE_ICONS_EXTRA@
714 CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
715
716 ;Read a value from an InstallOptions INI file
717 !insertmacro MUI_INSTALLOPTIONS_READ $DO_NOT_ADD_TO_PATH "NSIS.InstallOptions.ini" "Field 2" "State"
718 !insertmacro MUI_INSTALLOPTIONS_READ $ADD_TO_PATH_ALL_USERS "NSIS.InstallOptions.ini" "Field 3" "State"
719 !insertmacro MUI_INSTALLOPTIONS_READ $ADD_TO_PATH_CURRENT_USER "NSIS.InstallOptions.ini" "Field 4" "State"
720
721 ; Write special uninstall registry entries
722 Push "StartMenu"
723 Push "$STARTMENU_FOLDER"
724 Call ConditionalAddToRegisty
725 Push "DoNotAddToPath"
726 Push "$DO_NOT_ADD_TO_PATH"
727 Call ConditionalAddToRegisty
728 Push "AddToPathAllUsers"
729 Push "$ADD_TO_PATH_ALL_USERS"
730 Call ConditionalAddToRegisty
731 Push "AddToPathCurrentUser"
732 Push "$ADD_TO_PATH_CURRENT_USER"
733 Call ConditionalAddToRegisty
734 Push "InstallToDesktop"
735 Push "$INSTALL_DESKTOP"
736 Call ConditionalAddToRegisty
737
738 !insertmacro MUI_STARTMENU_WRITE_END
739
740 @CPACK_NSIS_EXTRA_INSTALL_COMMANDS@
741
742 SectionEnd
743
744 Section "-Add to path"
745 Push $INSTDIR\bin
746 StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 doNotAddToPath
747 StrCmp $DO_NOT_ADD_TO_PATH "1" doNotAddToPath 0
748 Call AddToPath
749 doNotAddToPath:
750 SectionEnd
751
752 ;--------------------------------
753 ; Create custom pages
754 Function InstallOptionsPage
755 !insertmacro MUI_HEADER_TEXT "Install Options" "Choose options for installing @CPACK_NSIS_PACKAGE_NAME@"
756 !insertmacro MUI_INSTALLOPTIONS_DISPLAY "NSIS.InstallOptions.ini"
757
758 FunctionEnd
759
760 ;--------------------------------
761 ; determine admin versus local install
762 Function un.onInit
763
764 ClearErrors
765 UserInfo::GetName
766 IfErrors noLM
767 Pop $0
768 UserInfo::GetAccountType
769 Pop $1
770 StrCmp $1 "Admin" 0 +3
771 SetShellVarContext all
772 ;MessageBox MB_OK 'User "$0" is in the Admin group'
773 Goto done
774 StrCmp $1 "Power" 0 +3
775 SetShellVarContext all
776 ;MessageBox MB_OK 'User "$0" is in the Power Users group'
777 Goto done
778
779 noLM:
780 ;Get installation folder from registry if available
781
782 done:
783
784 FunctionEnd
785
786 ;--- Add/Remove callback functions: ---
787 !macro SectionList MacroName
788 ;This macro used to perform operation on multiple sections.
789 ;List all of your components in following manner here.
790 @CPACK_NSIS_COMPONENT_SECTION_LIST@
791 !macroend
792
793 Section -FinishComponents
794 ;Removes unselected components and writes component status to registry
795 !insertmacro SectionList "FinishSection"
796
797 !ifdef CPACK_NSIS_ADD_REMOVE
798 ; Get the name of the installer executable
799 System::Call 'kernel32::GetModuleFileNameA(i 0, t .R0, i 1024) i r1'
800 StrCpy $R3 $R0
801
802 ; Strip off the last 13 characters, to see if we have AddRemove.exe
803 StrLen $R1 $R0
804 IntOp $R1 $R0 - 13
805 StrCpy $R2 $R0 13 $R1
806 StrCmp $R2 "AddRemove.exe" addremove_installed
807
808 ; We're not running AddRemove.exe, so install it
809 CopyFiles $R3 $INSTDIR\AddRemove.exe
810
811 addremove_installed:
812 !endif
813 SectionEnd
814 ;--- End of Add/Remove callback functions ---
815
816 ;--------------------------------
817 ; Component dependencies
818 Function .onSelChange
819 !insertmacro SectionList MaybeSelectionChanged
820 FunctionEnd
821
822 ;--------------------------------
823 ;Uninstaller Section
824
825 Section "Uninstall"
826 ReadRegStr $START_MENU SHCTX \
827 "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "StartMenu"
828 ;MessageBox MB_OK "Start menu is in: $START_MENU"
829 ReadRegStr $DO_NOT_ADD_TO_PATH SHCTX \
830 "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "DoNotAddToPath"
831 ReadRegStr $ADD_TO_PATH_ALL_USERS SHCTX \
832 "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "AddToPathAllUsers"
833 ReadRegStr $ADD_TO_PATH_CURRENT_USER SHCTX \
834 "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "AddToPathCurrentUser"
835 ;MessageBox MB_OK "Add to path: $DO_NOT_ADD_TO_PATH all users: $ADD_TO_PATH_ALL_USERS"
836 ReadRegStr $INSTALL_DESKTOP SHCTX \
837 "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "InstallToDesktop"
838 ;MessageBox MB_OK "Install to desktop: $INSTALL_DESKTOP "
839
840 @CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS@
841
842 ;Remove files we installed.
843 ;Keep the list of directories here in sync with the File commands above.
844 @CPACK_NSIS_DELETE_FILES@
845 @CPACK_NSIS_DELETE_DIRECTORIES@
846
847 !ifdef CPACK_NSIS_ADD_REMOVE
848 ;Remove the add/remove program
849 Delete "$INSTDIR\AddRemove.exe"
850 !endif
851
852 ;Remove the uninstaller itself.
853 Delete "$INSTDIR\Uninstall.exe"
854 DeleteRegKey SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
855
856 ;Remove the installation directory if it is empty.
857 RMDir "$INSTDIR"
858
859 ; Remove the registry entries.
860 DeleteRegKey SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
861
862 ; Removes all optional components
863 !insertmacro SectionList "RemoveSection"
864
865 !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
866
867 Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
868 @CPACK_NSIS_DELETE_ICONS@
869 @CPACK_NSIS_DELETE_ICONS_EXTRA@
870
871 ;Delete empty start menu parent diretories
872 StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
873
874 startMenuDeleteLoop:
875 ClearErrors
876 RMDir $MUI_TEMP
877 GetFullPathName $MUI_TEMP "$MUI_TEMP\.."
878
879 IfErrors startMenuDeleteLoopDone
880
881 StrCmp "$MUI_TEMP" "$SMPROGRAMS" startMenuDeleteLoopDone startMenuDeleteLoop
882 startMenuDeleteLoopDone:
883
884 ; If the user changed the shortcut, then untinstall may not work. This should
885 ; try to fix it.
886 StrCpy $MUI_TEMP "$START_MENU"
887 Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
888 @CPACK_NSIS_DELETE_ICONS_EXTRA@
889
890 ;Delete empty start menu parent diretories
891 StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
892
893 secondStartMenuDeleteLoop:
894 ClearErrors
895 RMDir $MUI_TEMP
896 GetFullPathName $MUI_TEMP "$MUI_TEMP\.."
897
898 IfErrors secondStartMenuDeleteLoopDone
899
900 StrCmp "$MUI_TEMP" "$SMPROGRAMS" secondStartMenuDeleteLoopDone secondStartMenuDeleteLoop
901 secondStartMenuDeleteLoopDone:
902
903 DeleteRegKey /ifempty SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
904
905 Push $INSTDIR\bin
906 StrCmp $DO_NOT_ADD_TO_PATH_ "1" doNotRemoveFromPath 0
907 Call un.RemoveFromPath
908 doNotRemoveFromPath:
909 SectionEnd
910
911 ;--------------------------------
912 ; determine admin versus local install
913 ; Is install for "AllUsers" or "JustMe"?
914 ; Default to "JustMe" - set to "AllUsers" if admin or on Win9x
915 ; This function is used for the very first "custom page" of the installer.
916 ; This custom page does not show up visibly, but it executes prior to the
917 ; first visible page and sets up $INSTDIR properly...
918 ; Choose different default installation folder based on SV_ALLUSERS...
919 ; "Program Files" for AllUsers, "My Documents" for JustMe...
920
921 Function .onInit
922 ; Reads components status for registry
923 !insertmacro SectionList "InitSection"
924
925 ; check to see if /D has been used to change
926 ; the install directory by comparing it to the
927 ; install directory that is expected to be the
928 ; default
929 StrCpy $IS_DEFAULT_INSTALLDIR 0
930 StrCmp "$INSTDIR" "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@" 0 +2
931 StrCpy $IS_DEFAULT_INSTALLDIR 1
932
933 StrCpy $SV_ALLUSERS "JustMe"
934 ; if default install dir then change the default
935 ; if it is installed for JustMe
936 StrCmp "$IS_DEFAULT_INSTALLDIR" "1" 0 +2
937 StrCpy $INSTDIR "$DOCUMENTS\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
938
939 ClearErrors
940 UserInfo::GetName
941 IfErrors noLM
942 Pop $0
943 UserInfo::GetAccountType
944 Pop $1
945 StrCmp $1 "Admin" 0 +3
946 SetShellVarContext all
947 ;MessageBox MB_OK 'User "$0" is in the Admin group'
948 StrCpy $SV_ALLUSERS "AllUsers"
949 Goto done
950 StrCmp $1 "Power" 0 +3
951 SetShellVarContext all
952 ;MessageBox MB_OK 'User "$0" is in the Power Users group'
953 StrCpy $SV_ALLUSERS "AllUsers"
954 Goto done
955
956 noLM:
957 StrCpy $SV_ALLUSERS "AllUsers"
958 ;Get installation folder from registry if available
959
960 done:
961 StrCmp $SV_ALLUSERS "AllUsers" 0 +3
962 StrCmp "$IS_DEFAULT_INSTALLDIR" "1" 0 +2
963 StrCpy $INSTDIR "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
964
965 StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 noOptionsPage
966 !insertmacro MUI_INSTALLOPTIONS_EXTRACT "NSIS.InstallOptions.ini"
967
968 noOptionsPage:
969 ; check for an older version
970 ClearErrors
971 ReadRegDWORD $INVMAJOR SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "VersionMajor"
972 ReadRegDWORD $INVMINOR SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "VersionMinor"
973 ReadRegDWORD $INVPATCH SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "VersionPatch"
974
975 ; now to check with current versions
976 ; if version not equal then offer uninstall
977 ; if version is older then do uninstall
978 ; if version is newer then prompt an offer to uninstall
979 IntCmp $INVMAJOR "@CPACK_PACKAGE_VERSION_MAJOR@" 0 douninstall new_ver_inst
980 IntCmp $INVMINOR "@CPACK_PACKAGE_VERSION_MINOR@" 0 douninstall new_ver_inst
981 IntCmp $INVPATCH "@CPACK_PACKAGE_VERSION_PATCH@" 0 douninstall new_ver_inst
982
983 MessageBox MB_YESNO|MB_ICONQUESTION \
984 "You already have $INVMAJOR.$INVMINOR.$INVPATCH of @CPACK_NSIS_DISPLAY_NAME@ installed. Reinstall?" \
985 /SD IDYES IDYES douninstall
986 Abort "@CPACK_NSIS_DISPLAY_NAME@ is already installed."
987
988 new_ver_inst:
989 MessageBox MB_YESNO|MB_ICONQUESTION \
990 "Newer version $0.$1.$2 is already installed. \
991 Downgrade to \
992 @CPACK_PACKAGE_VERSION_MAJOR@.@CPACK_PACKAGE_VERSION_MINOR@.@CPACK_PACKAGE_VERSION_PATCH@?" \
993 /SD IDNO IDYES douninstall
994 Abort "Newer @CPACK_NSIS_DISPLAY_NAME@ already installed."
995
996 douninstall:
997 ReadRegStr $UNINSTALLER_DIR SHCTX \
998 "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" ""
999 IfFileExists "$UNINSTALLER_DIR\Uninstall.exe" actuallyuninstall
1000 DetailPrint "$UNINSTALLER_DIR\Uninstall.exe does not exist"
1001 goto notinstalled ; just give up
1002
1003 actuallyuninstall:
1004 DetailPrint "Uninstalling old @CPACK_NSIS_DISPLAY_NAME@"
1005 Exec '"$UNINSTALLER_DIR\Uninstall.exe" /S'
1006 unistallerexists:
1007 Sleep 100
1008 IfFileExists "$UNINSTALLER_DIR\Uninstall.exe" unistallerexists
1009 Sleep 1000
1010
1011
1012
1013 notinstalled:
1014 FunctionEnd