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@CPACK_NSIS_MANIFEST_DPI_AWARE_CODE@
45@CPACK_NSIS_BRANDING_TEXT_CODE@
46
47  !include Sections.nsh
48
49;--- Component support macros: ---
50; The code for the add/remove functionality is from:
51;   http://nsis.sourceforge.net/Add/Remove_Functionality
52; It has been modified slightly and extended to provide
53; inter-component dependencies.
54Var AR_SecFlags
55Var AR_RegFlags
56@CPACK_NSIS_SECTION_SELECTED_VARS@
57
58; Loads the "selected" flag for the section named SecName into the
59; variable VarName.
60!macro LoadSectionSelectedIntoVar SecName VarName
61 SectionGetFlags ${${SecName}} $${VarName}
62 IntOp $${VarName} $${VarName} & ${SF_SELECTED}  ;Turn off all other bits
63!macroend
64
65; Loads the value of a variable... can we get around this?
66!macro LoadVar VarName
67  IntOp $R0 0 + $${VarName}
68!macroend
69
70; Sets the value of a variable
71!macro StoreVar VarName IntValue
72  IntOp $${VarName} 0 + ${IntValue}
73!macroend
74
75!macro InitSection SecName
76  ;  This macro reads component installed flag from the registry and
77  ;changes checked state of the section on the components page.
78  ;Input: section index constant name specified in Section command.
79
80  ClearErrors
81  ;Reading component status from registry
82  ReadRegDWORD $AR_RegFlags HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" "Installed"
83  IfErrors "default_${SecName}"
84    ;Status will stay default if registry value not found
85    ;(component was never installed)
86  IntOp $AR_RegFlags $AR_RegFlags & ${SF_SELECTED} ;Turn off all other bits
87  SectionGetFlags ${${SecName}} $AR_SecFlags  ;Reading default section flags
88  IntOp $AR_SecFlags $AR_SecFlags & 0xFFFE  ;Turn lowest (enabled) bit off
89  IntOp $AR_SecFlags $AR_RegFlags | $AR_SecFlags      ;Change lowest bit
90
91  ; Note whether this component was installed before
92  !insertmacro StoreVar ${SecName}_was_installed $AR_RegFlags
93  IntOp $R0 $AR_RegFlags & $AR_RegFlags
94
95  ;Writing modified flags
96  SectionSetFlags ${${SecName}} $AR_SecFlags
97
98 "default_${SecName}:"
99 !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected
100!macroend
101
102!macro FinishSection SecName
103  ;  This macro reads section flag set by user and removes the section
104  ;if it is not selected.
105  ;Then it writes component installed flag to registry
106  ;Input: section index constant name specified in Section command.
107
108  SectionGetFlags ${${SecName}} $AR_SecFlags  ;Reading section flags
109  ;Checking lowest bit:
110  IntOp $AR_SecFlags $AR_SecFlags & ${SF_SELECTED}
111  IntCmp $AR_SecFlags 1 "leave_${SecName}"
112    ;Section is not selected:
113    ;Calling Section uninstall macro and writing zero installed flag
114    !insertmacro "Remove_${${SecName}}"
115    WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" \
116  "Installed" 0
117    Goto "exit_${SecName}"
118
119 "leave_${SecName}:"
120    ;Section is selected:
121    WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@\Components\${SecName}" \
122  "Installed" 1
123
124 "exit_${SecName}:"
125!macroend
126
127!macro RemoveSection_CPack SecName
128  ;  This macro is used to call section's Remove_... macro
129  ;from the uninstaller.
130  ;Input: section index constant name specified in Section command.
131
132  !insertmacro "Remove_${${SecName}}"
133!macroend
134
135; Determine whether the selection of SecName changed
136!macro MaybeSelectionChanged SecName
137  !insertmacro LoadVar ${SecName}_selected
138  SectionGetFlags ${${SecName}} $R1
139  IntOp $R1 $R1 & ${SF_SELECTED} ;Turn off all other bits
140
141  ; See if the status has changed:
142  IntCmp $R0 $R1 "${SecName}_unchanged"
143  !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected
144
145  IntCmp $R1 ${SF_SELECTED} "${SecName}_was_selected"
146  !insertmacro "Deselect_required_by_${SecName}"
147  goto "${SecName}_unchanged"
148
149  "${SecName}_was_selected:"
150  !insertmacro "Select_${SecName}_depends"
151
152  "${SecName}_unchanged:"
153!macroend
154;--- End of Add/Remove macros ---
155
156;--------------------------------
157;Interface Settings
158
159  !define MUI_HEADERIMAGE
160  !define MUI_ABORTWARNING
161
162;----------------------------------------
163; based upon a script of "Written by KiCHiK 2003-01-18 05:57:02"
164;----------------------------------------
165!verbose 3
166!include "WinMessages.NSH"
167!verbose 4
168;====================================================
169; get_NT_environment
170;     Returns: the selected environment
171;     Output : head of the stack
172;====================================================
173!macro select_NT_profile UN
174Function ${UN}select_NT_profile
175   StrCmp $ADD_TO_PATH_ALL_USERS "1" 0 environment_single
176      DetailPrint "Selected environment for all users"
177      Push "all"
178      Return
179   environment_single:
180      DetailPrint "Selected environment for current user only."
181      Push "current"
182      Return
183FunctionEnd
184!macroend
185!insertmacro select_NT_profile ""
186!insertmacro select_NT_profile "un."
187;----------------------------------------------------
188!define NT_current_env 'HKCU "Environment"'
189!define NT_all_env     'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
190
191!ifndef WriteEnvStr_RegKey
192  !ifdef ALL_USERS
193    !define WriteEnvStr_RegKey \
194       'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
195  !else
196    !define WriteEnvStr_RegKey 'HKCU "Environment"'
197  !endif
198!endif
199
200; AddToPath - Adds the given dir to the search path.
201;        Input - head of the stack
202;        Note - Win9x systems requires reboot
203
204Function AddToPath
205  Exch $0
206  Push $1
207  Push $2
208  Push $3
209
210  # don't add if the path doesn't exist
211  IfFileExists "$0\*.*" "" AddToPath_done
212
213  ReadEnvStr $1 PATH
214  ; if the path is too long for a NSIS variable NSIS will return a 0
215  ; length string.  If we find that, then warn and skip any path
216  ; modification as it will trash the existing path.
217  StrLen $2 $1
218  IntCmp $2 0 CheckPathLength_ShowPathWarning CheckPathLength_Done CheckPathLength_Done
219    CheckPathLength_ShowPathWarning:
220    Messagebox MB_OK|MB_ICONEXCLAMATION "Warning! PATH too long installer unable to modify PATH!"
221    Goto AddToPath_done
222  CheckPathLength_Done:
223  Push "$1;"
224  Push "$0;"
225  Call StrStr
226  Pop $2
227  StrCmp $2 "" "" AddToPath_done
228  Push "$1;"
229  Push "$0\;"
230  Call StrStr
231  Pop $2
232  StrCmp $2 "" "" AddToPath_done
233  GetFullPathName /SHORT $3 $0
234  Push "$1;"
235  Push "$3;"
236  Call StrStr
237  Pop $2
238  StrCmp $2 "" "" AddToPath_done
239  Push "$1;"
240  Push "$3\;"
241  Call StrStr
242  Pop $2
243  StrCmp $2 "" "" AddToPath_done
244
245  Call IsNT
246  Pop $1
247  StrCmp $1 1 AddToPath_NT
248    ; Not on NT
249    StrCpy $1 $WINDIR 2
250    FileOpen $1 "$1\autoexec.bat" a
251    FileSeek $1 -1 END
252    FileReadByte $1 $2
253    IntCmp $2 26 0 +2 +2 # DOS EOF
254      FileSeek $1 -1 END # write over EOF
255    FileWrite $1 "$\r$\nSET PATH=%PATH%;$3$\r$\n"
256    FileClose $1
257    SetRebootFlag true
258    Goto AddToPath_done
259
260  AddToPath_NT:
261    StrCmp $ADD_TO_PATH_ALL_USERS "1" ReadAllKey
262      ReadRegStr $1 ${NT_current_env} "PATH"
263      Goto DoTrim
264    ReadAllKey:
265      ReadRegStr $1 ${NT_all_env} "PATH"
266    DoTrim:
267    StrCmp $1 "" AddToPath_NTdoIt
268      Push $1
269      Call Trim
270      Pop $1
271      StrCpy $0 "$1;$0"
272    AddToPath_NTdoIt:
273      StrCmp $ADD_TO_PATH_ALL_USERS "1" WriteAllKey
274        WriteRegExpandStr ${NT_current_env} "PATH" $0
275        Goto DoSend
276      WriteAllKey:
277        WriteRegExpandStr ${NT_all_env} "PATH" $0
278      DoSend:
279      SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
280
281  AddToPath_done:
282    Pop $3
283    Pop $2
284    Pop $1
285    Pop $0
286FunctionEnd
287
288
289; RemoveFromPath - Remove a given dir from the path
290;     Input: head of the stack
291
292Function un.RemoveFromPath
293  Exch $0
294  Push $1
295  Push $2
296  Push $3
297  Push $4
298  Push $5
299  Push $6
300
301  IntFmt $6 "%c" 26 # DOS EOF
302
303  Call un.IsNT
304  Pop $1
305  StrCmp $1 1 unRemoveFromPath_NT
306    ; Not on NT
307    StrCpy $1 $WINDIR 2
308    FileOpen $1 "$1\autoexec.bat" r
309    GetTempFileName $4
310    FileOpen $2 $4 w
311    GetFullPathName /SHORT $0 $0
312    StrCpy $0 "SET PATH=%PATH%;$0"
313    Goto unRemoveFromPath_dosLoop
314
315    unRemoveFromPath_dosLoop:
316      FileRead $1 $3
317      StrCpy $5 $3 1 -1 # read last char
318      StrCmp $5 $6 0 +2 # if DOS EOF
319        StrCpy $3 $3 -1 # remove DOS EOF so we can compare
320      StrCmp $3 "$0$\r$\n" unRemoveFromPath_dosLoopRemoveLine
321      StrCmp $3 "$0$\n" unRemoveFromPath_dosLoopRemoveLine
322      StrCmp $3 "$0" unRemoveFromPath_dosLoopRemoveLine
323      StrCmp $3 "" unRemoveFromPath_dosLoopEnd
324      FileWrite $2 $3
325      Goto unRemoveFromPath_dosLoop
326      unRemoveFromPath_dosLoopRemoveLine:
327        SetRebootFlag true
328        Goto unRemoveFromPath_dosLoop
329
330    unRemoveFromPath_dosLoopEnd:
331      FileClose $2
332      FileClose $1
333      StrCpy $1 $WINDIR 2
334      Delete "$1\autoexec.bat"
335      CopyFiles /SILENT $4 "$1\autoexec.bat"
336      Delete $4
337      Goto unRemoveFromPath_done
338
339  unRemoveFromPath_NT:
340    StrCmp $ADD_TO_PATH_ALL_USERS "1" unReadAllKey
341      ReadRegStr $1 ${NT_current_env} "PATH"
342      Goto unDoTrim
343    unReadAllKey:
344      ReadRegStr $1 ${NT_all_env} "PATH"
345    unDoTrim:
346    StrCpy $5 $1 1 -1 # copy last char
347    StrCmp $5 ";" +2 # if last char != ;
348      StrCpy $1 "$1;" # append ;
349    Push $1
350    Push "$0;"
351    Call un.StrStr ; Find `$0;` in $1
352    Pop $2 ; pos of our dir
353    StrCmp $2 "" unRemoveFromPath_done
354      ; else, it is in path
355      # $0 - path to add
356      # $1 - path var
357      StrLen $3 "$0;"
358      StrLen $4 $2
359      StrCpy $5 $1 -$4 # $5 is now the part before the path to remove
360      StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove
361      StrCpy $3 $5$6
362
363      StrCpy $5 $3 1 -1 # copy last char
364      StrCmp $5 ";" 0 +2 # if last char == ;
365        StrCpy $3 $3 -1 # remove last char
366
367      StrCmp $ADD_TO_PATH_ALL_USERS "1" unWriteAllKey
368        WriteRegExpandStr ${NT_current_env} "PATH" $3
369        Goto unDoSend
370      unWriteAllKey:
371        WriteRegExpandStr ${NT_all_env} "PATH" $3
372      unDoSend:
373      SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
374
375  unRemoveFromPath_done:
376    Pop $6
377    Pop $5
378    Pop $4
379    Pop $3
380    Pop $2
381    Pop $1
382    Pop $0
383FunctionEnd
384
385;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
386; Uninstall sutff
387;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
388
389###########################################
390#            Utility Functions            #
391###########################################
392
393;====================================================
394; IsNT - Returns 1 if the current system is NT, 0
395;        otherwise.
396;     Output: head of the stack
397;====================================================
398; IsNT
399; no input
400; output, top of the stack = 1 if NT or 0 if not
401;
402; Usage:
403;   Call IsNT
404;   Pop $R0
405;  ($R0 at this point is 1 or 0)
406
407!macro IsNT un
408Function ${un}IsNT
409  Push $0
410  ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
411  StrCmp $0 "" 0 IsNT_yes
412  ; we are not NT.
413  Pop $0
414  Push 0
415  Return
416
417  IsNT_yes:
418    ; NT!!!
419    Pop $0
420    Push 1
421FunctionEnd
422!macroend
423!insertmacro IsNT ""
424!insertmacro IsNT "un."
425
426; StrStr
427; input, top of stack = string to search for
428;        top of stack-1 = string to search in
429; output, top of stack (replaces with the portion of the string remaining)
430; modifies no other variables.
431;
432; Usage:
433;   Push "this is a long ass string"
434;   Push "ass"
435;   Call StrStr
436;   Pop $R0
437;  ($R0 at this point is "ass string")
438
439!macro StrStr un
440Function ${un}StrStr
441Exch $R1 ; st=haystack,old$R1, $R1=needle
442  Exch    ; st=old$R1,haystack
443  Exch $R2 ; st=old$R1,old$R2, $R2=haystack
444  Push $R3
445  Push $R4
446  Push $R5
447  StrLen $R3 $R1
448  StrCpy $R4 0
449  ; $R1=needle
450  ; $R2=haystack
451  ; $R3=len(needle)
452  ; $R4=cnt
453  ; $R5=tmp
454  loop:
455    StrCpy $R5 $R2 $R3 $R4
456    StrCmp $R5 $R1 done
457    StrCmp $R5 "" done
458    IntOp $R4 $R4 + 1
459    Goto loop
460done:
461  StrCpy $R1 $R2 "" $R4
462  Pop $R5
463  Pop $R4
464  Pop $R3
465  Pop $R2
466  Exch $R1
467FunctionEnd
468!macroend
469!insertmacro StrStr ""
470!insertmacro StrStr "un."
471
472Function Trim ; Added by Pelaca
473	Exch $R1
474	Push $R2
475Loop:
476	StrCpy $R2 "$R1" 1 -1
477	StrCmp "$R2" " " RTrim
478	StrCmp "$R2" "$\n" RTrim
479	StrCmp "$R2" "$\r" RTrim
480	StrCmp "$R2" ";" RTrim
481	GoTo Done
482RTrim:
483	StrCpy $R1 "$R1" -1
484	Goto Loop
485Done:
486	Pop $R2
487	Exch $R1
488FunctionEnd
489
490Function ConditionalAddToRegisty
491  Pop $0
492  Pop $1
493  StrCmp "$0" "" ConditionalAddToRegisty_EmptyString
494    WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" \
495    "$1" "$0"
496    ;MessageBox MB_OK "Set Registry: '$1' to '$0'"
497    DetailPrint "Set install registry entry: '$1' to '$0'"
498  ConditionalAddToRegisty_EmptyString:
499FunctionEnd
500
501;--------------------------------
502
503!ifdef CPACK_USES_DOWNLOAD
504Function DownloadFile
505    IfFileExists $INSTDIR\* +2
506    CreateDirectory $INSTDIR
507    Pop $0
508
509    ; Skip if already downloaded
510    IfFileExists $INSTDIR\$0 0 +2
511    Return
512
513    StrCpy $1 "@CPACK_DOWNLOAD_SITE@"
514
515  try_again:
516    NSISdl::download "$1/$0" "$INSTDIR\$0"
517
518    Pop $1
519    StrCmp $1 "success" success
520    StrCmp $1 "Cancelled" cancel
521    MessageBox MB_OK "Download failed: $1"
522  cancel:
523    Return
524  success:
525FunctionEnd
526!endif
527
528;--------------------------------
529; Define some macro setting for the gui
530@CPACK_NSIS_INSTALLER_MUI_ICON_CODE@
531@CPACK_NSIS_INSTALLER_ICON_CODE@
532@CPACK_NSIS_INSTALLER_MUI_WELCOMEFINISH_CODE@
533@CPACK_NSIS_INSTALLER_MUI_UNWELCOMEFINISH_CODE@
534@CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC@
535@CPACK_NSIS_INSTALLER_MUI_FINISHPAGE_RUN_CODE@
536
537;--------------------------------
538;Pages
539  @CPACK_NSIS_INSTALLER_WELCOME_TITLE_CODE@
540  @CPACK_NSIS_INSTALLER_WELCOME_TITLE_3LINES_CODE@
541  !insertmacro MUI_PAGE_WELCOME
542
543  @CPACK_NSIS_LICENSE_PAGE@
544  Page custom InstallOptionsPage
545  !insertmacro MUI_PAGE_DIRECTORY
546
547  ;Start Menu Folder Page Configuration
548  !define MUI_STARTMENUPAGE_REGISTRY_ROOT "SHCTX"
549  !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
550  !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
551  !insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER
552
553  @CPACK_NSIS_PAGE_COMPONENTS@
554
555  !insertmacro MUI_PAGE_INSTFILES
556  @CPACK_NSIS_INSTALLER_FINISH_TITLE_CODE@
557  @CPACK_NSIS_INSTALLER_FINISH_TITLE_3LINES_CODE@
558  !insertmacro MUI_PAGE_FINISH
559
560  !insertmacro MUI_UNPAGE_CONFIRM
561  !insertmacro MUI_UNPAGE_INSTFILES
562
563;--------------------------------
564;Languages
565
566  !insertmacro MUI_LANGUAGE "English" ;first language is the default language
567  !insertmacro MUI_LANGUAGE "Afrikaans"
568  !insertmacro MUI_LANGUAGE "Albanian"
569  !insertmacro MUI_LANGUAGE "Arabic"
570  !insertmacro MUI_LANGUAGE "Asturian"
571  !insertmacro MUI_LANGUAGE "Basque"
572  !insertmacro MUI_LANGUAGE "Belarusian"
573  !insertmacro MUI_LANGUAGE "Bosnian"
574  !insertmacro MUI_LANGUAGE "Breton"
575  !insertmacro MUI_LANGUAGE "Bulgarian"
576  !insertmacro MUI_LANGUAGE "Catalan"
577  !insertmacro MUI_LANGUAGE "Corsican"
578  !insertmacro MUI_LANGUAGE "Croatian"
579  !insertmacro MUI_LANGUAGE "Czech"
580  !insertmacro MUI_LANGUAGE "Danish"
581  !insertmacro MUI_LANGUAGE "Dutch"
582  !insertmacro MUI_LANGUAGE "Esperanto"
583  !insertmacro MUI_LANGUAGE "Estonian"
584  !insertmacro MUI_LANGUAGE "Farsi"
585  !insertmacro MUI_LANGUAGE "Finnish"
586  !insertmacro MUI_LANGUAGE "French"
587  !insertmacro MUI_LANGUAGE "Galician"
588  !insertmacro MUI_LANGUAGE "German"
589  !insertmacro MUI_LANGUAGE "Greek"
590  !insertmacro MUI_LANGUAGE "Hebrew"
591  !insertmacro MUI_LANGUAGE "Hungarian"
592  !insertmacro MUI_LANGUAGE "Icelandic"
593  !insertmacro MUI_LANGUAGE "Indonesian"
594  !insertmacro MUI_LANGUAGE "Irish"
595  !insertmacro MUI_LANGUAGE "Italian"
596  !insertmacro MUI_LANGUAGE "Japanese"
597  !insertmacro MUI_LANGUAGE "Korean"
598  !insertmacro MUI_LANGUAGE "Kurdish"
599  !insertmacro MUI_LANGUAGE "Latvian"
600  !insertmacro MUI_LANGUAGE "Lithuanian"
601  !insertmacro MUI_LANGUAGE "Luxembourgish"
602  !insertmacro MUI_LANGUAGE "Macedonian"
603  !insertmacro MUI_LANGUAGE "Malay"
604  !insertmacro MUI_LANGUAGE "Mongolian"
605  !insertmacro MUI_LANGUAGE "Norwegian"
606  !insertmacro MUI_LANGUAGE "NorwegianNynorsk"
607  !insertmacro MUI_LANGUAGE "Pashto"
608  !insertmacro MUI_LANGUAGE "Polish"
609  !insertmacro MUI_LANGUAGE "Portuguese"
610  !insertmacro MUI_LANGUAGE "PortugueseBR"
611  !insertmacro MUI_LANGUAGE "Romanian"
612  !insertmacro MUI_LANGUAGE "Russian"
613  !insertmacro MUI_LANGUAGE "ScotsGaelic"
614  !insertmacro MUI_LANGUAGE "Serbian"
615  !insertmacro MUI_LANGUAGE "SerbianLatin"
616  !insertmacro MUI_LANGUAGE "SimpChinese"
617  !insertmacro MUI_LANGUAGE "Slovak"
618  !insertmacro MUI_LANGUAGE "Slovenian"
619  !insertmacro MUI_LANGUAGE "Spanish"
620  !insertmacro MUI_LANGUAGE "SpanishInternational"
621  !insertmacro MUI_LANGUAGE "Swedish"
622  !insertmacro MUI_LANGUAGE "Tatar"
623  !insertmacro MUI_LANGUAGE "Thai"
624  !insertmacro MUI_LANGUAGE "TradChinese"
625  !insertmacro MUI_LANGUAGE "Turkish"
626  !insertmacro MUI_LANGUAGE "Ukrainian"
627  !insertmacro MUI_LANGUAGE "Uzbek"
628  !insertmacro MUI_LANGUAGE "Vietnamese"
629  !insertmacro MUI_LANGUAGE "Welsh"
630
631;--------------------------------
632;Reserve Files
633
634  ;These files should be inserted before other files in the data block
635  ;Keep these lines before any File command
636  ;Only for solid compression (by default, solid compression is enabled for BZIP2 and LZMA)
637
638  ReserveFile "NSIS.InstallOptions.ini"
639  !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
640
641  ; for UserInfo::GetName and UserInfo::GetAccountType
642  ReserveFile /plugin 'UserInfo.dll'
643
644;--------------------------------
645; Installation types
646@CPACK_NSIS_INSTALLATION_TYPES@
647
648;--------------------------------
649; Component sections
650@CPACK_NSIS_COMPONENT_SECTIONS@
651
652;--------------------------------
653;Installer Sections
654
655Section "-Core installation"
656  ;Use the entire tree produced by the INSTALL target.  Keep the
657  ;list of directories here in sync with the RMDir commands below.
658  SetOutPath "$INSTDIR"
659  @CPACK_NSIS_EXTRA_PREINSTALL_COMMANDS@
660  @CPACK_NSIS_FULL_INSTALL@
661
662  ;Store installation folder
663  WriteRegStr SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "" $INSTDIR
664
665  ;Create uninstaller
666  WriteUninstaller "$INSTDIR\@[email protected]"
667  Push "DisplayName"
668  Push "@CPACK_NSIS_DISPLAY_NAME@"
669  Call ConditionalAddToRegisty
670  Push "DisplayVersion"
671  Push "@CPACK_PACKAGE_VERSION@"
672  Call ConditionalAddToRegisty
673  Push "Publisher"
674  Push "@CPACK_PACKAGE_VENDOR@"
675  Call ConditionalAddToRegisty
676  Push "UninstallString"
677  Push "$\"$INSTDIR\@[email protected]$\""
678  Call ConditionalAddToRegisty
679  Push "NoRepair"
680  Push "1"
681  Call ConditionalAddToRegisty
682
683  !ifdef CPACK_NSIS_ADD_REMOVE
684  ;Create add/remove functionality
685  Push "ModifyPath"
686  Push "$INSTDIR\AddRemove.exe"
687  Call ConditionalAddToRegisty
688  !else
689  Push "NoModify"
690  Push "1"
691  Call ConditionalAddToRegisty
692  !endif
693
694  ; Optional registration
695  Push "DisplayIcon"
696  Push "$INSTDIR\@CPACK_NSIS_INSTALLED_ICON_NAME@"
697  Call ConditionalAddToRegisty
698  Push "HelpLink"
699  Push "@CPACK_NSIS_HELP_LINK@"
700  Call ConditionalAddToRegisty
701  Push "URLInfoAbout"
702  Push "@CPACK_NSIS_URL_INFO_ABOUT@"
703  Call ConditionalAddToRegisty
704  Push "Contact"
705  Push "@CPACK_NSIS_CONTACT@"
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\@[email protected]"
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
742SectionEnd
743
744Section "-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:
750SectionEnd
751
752;--------------------------------
753; Create custom pages
754Function 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
758FunctionEnd
759
760;--------------------------------
761; determine admin versus local install
762Function 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
784FunctionEnd
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
793Section -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
813SectionEnd
814;--- End of Add/Remove callback functions ---
815
816;--------------------------------
817; Component dependencies
818Function .onSelChange
819  !insertmacro SectionList MaybeSelectionChanged
820FunctionEnd
821
822;--------------------------------
823;Uninstaller Section
824
825Section "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\@[email protected]"
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_CPack"
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 directories
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 directories
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:
909SectionEnd
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
921Function .onInit
922  StrCmp "@CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL@" "ON" 0 inst
923
924  ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "UninstallString"
925  StrCmp $0 "" inst
926
927  MessageBox MB_YESNOCANCEL|MB_ICONEXCLAMATION \
928  "@CPACK_NSIS_PACKAGE_NAME@ is already installed. $\n$\nDo you want to uninstall the old version before installing the new one?" \
929  /SD IDYES IDYES uninst IDNO inst
930  Abort
931
932;Run the uninstaller
933uninst:
934  ClearErrors
935  StrLen $2 "\@[email protected]"
936  StrCpy $3 $0 -$2 # remove "\@[email protected]" from UninstallString to get path
937  ExecWait '"$0" /S _?=$3' ;Do not copy the uninstaller to a temp file
938
939  IfErrors uninst_failed inst
940uninst_failed:
941  MessageBox MB_OK|MB_ICONSTOP "Uninstall failed."
942  Abort
943
944
945inst:
946  ; Reads components status for registry
947  !insertmacro SectionList "InitSection"
948
949  ; check to see if /D has been used to change
950  ; the install directory by comparing it to the
951  ; install directory that is expected to be the
952  ; default
953  StrCpy $IS_DEFAULT_INSTALLDIR 0
954  StrCmp "$INSTDIR" "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@" 0 +2
955    StrCpy $IS_DEFAULT_INSTALLDIR 1
956
957  StrCpy $SV_ALLUSERS "JustMe"
958  ; if default install dir then change the default
959  ; if it is installed for JustMe
960  StrCmp "$IS_DEFAULT_INSTALLDIR" "1" 0 +2
961    StrCpy $INSTDIR "$DOCUMENTS\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
962
963  ClearErrors
964  UserInfo::GetName
965  IfErrors noLM
966  Pop $0
967  UserInfo::GetAccountType
968  Pop $1
969  StrCmp $1 "Admin" 0 +4
970    SetShellVarContext all
971    ;MessageBox MB_OK 'User "$0" is in the Admin group'
972    StrCpy $SV_ALLUSERS "AllUsers"
973    Goto done
974  StrCmp $1 "Power" 0 +4
975    SetShellVarContext all
976    ;MessageBox MB_OK 'User "$0" is in the Power Users group'
977    StrCpy $SV_ALLUSERS "AllUsers"
978    Goto done
979
980  noLM:
981    StrCpy $SV_ALLUSERS "AllUsers"
982    ;Get installation folder from registry if available
983
984  done:
985  StrCmp $SV_ALLUSERS "AllUsers" 0 +3
986    StrCmp "$IS_DEFAULT_INSTALLDIR" "1" 0 +2
987      StrCpy $INSTDIR "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
988
989  StrCmp "@CPACK_NSIS_MODIFY_PATH@" "ON" 0 noOptionsPage
990    !insertmacro MUI_INSTALLOPTIONS_EXTRACT "NSIS.InstallOptions.ini"
991
992  noOptionsPage:
993FunctionEnd
994