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