source: tol/NSIS/NSIS.template.in @ aa4a881

1941-docker-image-to-testdevel
Last change on this file since aa4a881 was aa4a881, checked in by Jorge Pérez <josp.jorge@…>, 11 years ago

refs #1827, archivos de soporte al instalador

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@6766 be4846ae-f051-483a-831f-b64e7d08527f

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