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