1# installer for GNU CLISP
2# using Nullsoft Install System
3# (C) 2007 Elliott Slaughter
4#
5# this source code is a part of CLISP,
6# and is released under the GPL v2
7# (or newer, as the user sees fit).
8#
9# usage: place script and additional files
10# (is_user_admin and add_to_path) to directory
11# where clisp distro is stored, then compile
12# with NSIS (latest version used was 2.31).
13#
14# note: this script globs all files in the current
15# directory, ignoring files that match "install*"
16
17# check that this is being compiled by long-strings version of NSIS.
18# this is needed to avoid a bug where users' PATHs get clobbered.
19
20    !if ${NSIS_MAX_STRLEN} < 8192
21    !error "\
22Please use a large-strings build of NSIS. This is really important! Bugs will \
23appear in the installer if you don't do this! Get the build from: \
24http://nsis.sourceforge.net/Special_Builds"
25    !endif
26
27# general
28
29    !include MUI.nsh
30
31    # compression method
32    SetCompressor /SOLID LZMA
33    SetCompressorDictSize 16 # MB
34
35    # http://nsis.sourceforge.net/IsUserAdmin
36    !include "is_user_admin.nsh"
37
38    # name and file
39    !define VERSION "@VERSION@"
40    !define NAME "@NAME@"
41    !define FULL_MODULES "@MODULES@"
42    !define BASE_MODULES "@BASE_MODULES@"
43
44    # http://nsis.sourceforge.net/Path_Manipulation
45    !include "env_var_update.nsh"
46
47    # name and output of file
48    Name "${NAME} ${VERSION}"
49    OutFile "clisp-${VERSION}-win32-install.exe"
50
51    # default installation folder
52    InstallDir "$PROGRAMFILES\clisp-${VERSION}"
53
54    # get installation folder from registry if available
55    InstallDirRegKey HKCU "Software\${NAME} ${VERSION}" ""
56
57    # execute with highest level of permissions available to the user
58    RequestExecutionLevel highest
59
60# variables
61
62    Var LinkingSet
63    Var LinkingCmd
64    Var UserSetting
65    Var STARTMENU_FOLDER
66    Var STARTMENU_TEMP
67
68# interface configuration
69
70    !define MUI_ABORTWARNING
71
72# installation types
73InstType "Typical"
74
75# page definitions and settings
76
77    #installer pages
78
79    !define MUI_COMPONENTSPAGE_SMALLDESC
80
81    !insertmacro MUI_PAGE_WELCOME
82    !insertmacro MUI_PAGE_LICENSE "COPYRIGHT.rtf"
83    !insertmacro MUI_PAGE_COMPONENTS
84    !insertmacro MUI_PAGE_DIRECTORY
85
86    !define MUI_STARTMENUPAGE_DEFAULTFOLDER "${NAME} ${VERSION}"
87    !define MUI_STARTMENUPAGE_REGISTRY_ROOT HKCU
88    !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\${NAME} ${VERSION}"
89    !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
90    !insertmacro MUI_PAGE_STARTMENU StartMenu $STARTMENU_FOLDER
91
92    !insertmacro MUI_PAGE_INSTFILES
93
94    # uninstaller pages
95    !insertmacro MUI_UNPAGE_CONFIRM
96    !insertmacro MUI_UNPAGE_INSTFILES
97
98# language files
99
100    !insertmacro MUI_LANGUAGE "English"
101
102# installer sections
103
104# install for all users or just current user?
105SectionGroup /e "!Install For"
106
107    Section "All Users" SecAllUsers
108
109        # set shell var context to all
110        SetShellVarContext all
111
112        # save in registry
113        WriteRegStr HKCU "Software\${NAME} ${VERSION}" "Shell Var Context" "all"
114
115        # save env var context in registry
116        WriteRegStr HKCU "Software\${NAME} ${VERSION}" "Environment Context" "all"
117    SectionEnd
118
119    Section "Just Me" SecCurUser
120    SectionIn 1
121        # set shell var context to current
122        SetShellVarContext current
123
124        # save in registry
125        WriteRegStr HKCU "Software\${NAME} ${VERSION}" "Shell Var Context" "current"
126
127        # save env var context in registry
128        WriteRegStr HKCU "Software\${NAME} ${VERSION}" "Environment Context" "current"
129    SectionEnd
130
131SectionGroupEnd
132
133SectionGroup /e "!${NAME} Core"
134
135    Section "${NAME} ${VERSION}" SecCore
136    SectionIn 1 RO
137
138        SetOutPath $INSTDIR
139
140        # create files
141        File /r /x "*.nsi" /x "*.nsh" /x "text_to_rtf.*" /x "COPYRIGHT.rtf" /x "install*.*" ".\"
142
143        # set linking set to base
144        StrCpy $LinkingCmd "base"
145
146        # store installation folder in registry
147        WriteRegStr HKCU "Software\${NAME} ${VERSION}" "" $INSTDIR
148
149        # create uninstaller
150        WriteUninstaller "uninstall.exe"
151    SectionEnd
152
153    Section "Base Linking Set" SecBase
154
155        # set linking set to base
156        StrCpy $LinkingCmd "base"
157    SectionEnd
158
159    Section "Full Linking Set" SecFull
160    SectionIn 1
161
162        # set linking set to base
163        StrCpy $LinkingCmd "full"
164    SectionEnd
165
166    Section "-Add/Remove Programs"
167
168        # add uninstaller to add/remove programs
169        StrCmp $UserSetting ${SecAllUsers} WriteRegStr_all
170            WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}" \
171                "DisplayName" "${NAME} ${VERSION}"
172            WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}" \
173                "DisplayIcon" "$INSTDIR\clisp.exe,0"
174            WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}" \
175                "DisplayVersion" "${VERSION}"
176            WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}" \
177                "InstallLocation" "$INSTDIR"
178            WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}" \
179                "UninstallString" "$INSTDIR\uninstall.exe"
180            WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}" \
181                "URLInfoAbout" "http://clisp.cons.org/"
182            WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}" \
183                "URLUpdateInfo" "http://clisp.cons.org/"
184            WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}" \
185                "HelpLink" "http://clisp.cons.org/"
186            WriteRegDWord HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}" \
187                "NoModify" 1
188            WriteRegDWord HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}" \
189                "NoRepair" 1
190        Goto WriteRegStr_done
191        WriteRegStr_all:
192            WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}" \
193                "DisplayName" "${NAME} ${VERSION}"
194            WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}" \
195                "DisplayIcon" "$INSTDIR\clisp.exe,0"
196            WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}" \
197                "DisplayVersion" "${VERSION}"
198            WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}" \
199                "InstallLocation" "$INSTDIR"
200            WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}" \
201                "UninstallString" "$INSTDIR\uninstall.exe"
202            WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}" \
203                "URLInfoAbout" "http://clisp.cons.org/"
204            WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}" \
205                "URLUpdateInfo" "http://clisp.cons.org/"
206            WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}" \
207                "HelpLink" "http://clisp.cons.org/"
208            WriteRegDWord HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}" \
209                "NoModify" 1
210            WriteRegDWord HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}" \
211                "NoRepair" 1
212        WriteRegStr_done:
213    SectionEnd
214
215    Section "-Start Menu"
216
217        # add start menu shortcuts
218        !insertmacro MUI_STARTMENU_WRITE_BEGIN StartMenu
219            CreateDirectory $SMPROGRAMS\$STARTMENU_FOLDER
220            CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\${NAME} ${VERSION}.lnk" "$INSTDIR\clisp.exe" "-K $LinkingCmd"
221            CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall ${NAME} ${VERSION}.lnk" $INSTDIR\uninstall.exe
222        !insertmacro MUI_STARTMENU_WRITE_END
223    SectionEnd
224
225    Section "Desktop Shortcut" SecDesktop
226    SectionIn 1
227
228        # create shortcut
229        createShortCut "$DESKTOP\${NAME} ${VERSION}.lnk" "$INSTDIR\clisp.exe" "-K $LinkingCmd"
230
231        # record installation of desktop shortcut in registry
232        WriteRegStr HKCU "Software\${NAME} ${VERSION}" "Desktop Shortcut" "true"
233    SectionEnd
234
235    Section "File Associations" SecAssoc
236    SectionIn 1
237
238        # add file associations to registry
239        WriteRegStr HKCR ".lisp" "" "lispfile"
240        WriteRegStr HKCR ".lsp" "" "lispfile"
241        WriteRegStr HKCR ".cl" "" "lispfile"
242        WriteRegStr HKCR ".fas" "" "fasfile"
243        WriteRegStr HKCR ".mem" "" "memfile"
244
245        WriteRegStr HKCR "lispfile" "" "Lisp source file"
246        WriteRegDWord HKCR "lispfile" "EditFlags" 0
247        WriteRegStr HKCR "lispfile\DefaultIcon" "" "%SystemRoot%\system32\SHELL32.dll,41"
248        WriteRegStr HKCR "lispfile\Shell\Compile_with_CLISP" "" "Compile with CLISP"
249        WriteRegStr HKCR "lispfile\Shell\Compile_with_CLISP\command" "" '"$INSTDIR\clisp.exe" -K $LinkingCmd -c "%1"'
250
251        WriteRegStr HKCR "fasfile" "" "CLISP compiled file"
252        WriteRegDWord HKCR "fasfile" "EditFlags" 0
253        WriteRegStr HKCR "fasfile\DefaultIcon" "" "%SystemRoot%\system32\SHELL32.dll,21"
254        WriteRegStr HKCR "fasfile\Shell\Execute_with_CLISP" "" "Execute with CLISP"
255        WriteRegStr HKCR "fasfile\Shell\Execute_with_CLISP\command" "" '"$INSTDIR\clisp.exe" -K $LinkingCmd "%1"'
256        WriteRegStr HKCR "fasfile\Shell\Load_into_CLISP" "" "Load into CLISP"
257        WriteRegStr HKCR "fasfile\Shell\Load_into_CLISP\command" "" '"$INSTDIR\clisp.exe" -K $LinkingCmd -i "%1"'
258
259        WriteRegStr HKCR "memfile" "" "CLISP memory image"
260        WriteRegDWord HKCR "memfile" "EditFlags" 0
261        WriteRegStr HKCR "memfile\DefaultIcon" "" "%SystemRoot%\system32\SHELL32.dll,21"
262        WriteRegStr HKCR "memfile\Shell\Run_with_CLISP" "" "Run with CLISP"
263        WriteRegStr HKCR "memfile\Shell\Run_with_CLISP\command" "" '"$INSTDIR\clisp.exe" -K $LinkingCmd -M "%1"'
264
265        # record installation of desktop shortcut in registry
266        WriteRegStr HKCU "Software\${NAME} ${VERSION}" "File Associations" "true"
267    SectionEnd
268
269    Section "PATH Variable" SecPath
270    SectionIn 1
271
272        # add to PATH Variable
273        StrCmp $UserSetting ${SecAllUsers} AddToPath_all
274            ${EnvVarUpdate} $0 "PATH" "A" "HKCU" "$INSTDIR"
275        Goto AddToPath_done
276        AddToPath_all:
277            ${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$INSTDIR"
278        AddToPath_done:
279
280        # record installation of PATH setting in registry
281        WriteRegStr HKCU "Software\${NAME} ${VERSION}" "PATH" "true"
282    SectionEnd
283SectionGroupEnd
284
285# component descriptions
286
287    # language strings
288    LangString DESC_SecAllUsers ${LANG_ENGLISH} "Install ${NAME} ${VERSION} for all users. (Requires administrative privileges.)"
289    LangString DESC_SecCurUser ${LANG_ENGLISH} "Install ${NAME} ${VERSION} for current user only."
290    LangString DESC_SecCore ${LANG_ENGLISH} "${NAME} ${VERSION}, an ANSI Common Lisp implementation."
291    LangString DESC_SecBase ${LANG_ENGLISH} "Enable basic linking set. (Includes ${BASE_MODULES}.)"
292    LangString DESC_SecFull ${LANG_ENGLISH} "Enable full linking set. (Includes ${BASE_MODULES} ${FULL_MODULES}.)"
293    LangString DESC_SecDesktop ${LANG_ENGLISH} "Create a desktop shortcut for ${NAME}."
294    LangString DESC_SecAssoc ${LANG_ENGLISH} "Associate ${NAME} with files of types .lisp, .lsp, .cl, .fas, and .mem."
295    LangString DESC_SecPath ${LANG_ENGLISH} "Add ${NAME} directory to PATH environment variable."
296
297    # assign language strings to sections
298    !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
299        !insertmacro MUI_DESCRIPTION_TEXT ${SecAllUsers} $(DESC_SecAllUsers)
300        !insertmacro MUI_DESCRIPTION_TEXT ${SecCurUser} $(DESC_SecCurUser)
301        !insertmacro MUI_DESCRIPTION_TEXT ${SecCore} $(DESC_SecCore)
302        !insertmacro MUI_DESCRIPTION_TEXT ${SecBase} $(DESC_SecBase)
303        !insertmacro MUI_DESCRIPTION_TEXT ${SecFull} $(DESC_SecFull)
304        !insertmacro MUI_DESCRIPTION_TEXT ${SecDesktop} $(DESC_SecDesktop)
305        !insertmacro MUI_DESCRIPTION_TEXT ${SecAssoc} $(DESC_SecAssoc)
306        !insertmacro MUI_DESCRIPTION_TEXT ${SecPath} $(DESC_SecPath)
307    !insertmacro MUI_FUNCTION_DESCRIPTION_END
308
309# installer functions
310
311Function .onInit
312
313    StrCpy $UserSetting ${SecCurUser}
314    StrCpy $LinkingSet ${SecFull}
315
316    # if the user does *not* have administrator privileges,
317    # then make section SecAllUsers readonly
318    Call IsUserAdmin
319    Pop $0
320    StrCmp $0 "true" onInit_cont 0
321        # Set the fifth bit to set the read only flag.
322        !define READ_ONLY 0x00000010
323        SectionGetFlags ${SecAllUsers} $0
324        IntOp $0 $0 | ${READ_ONLY}
325        SectionSetFlags ${SecAllUsers} $0
326        !undef READ_ONLY
327    onInit_cont:
328
329FunctionEnd
330
331Function .onSelChange
332
333    !insertmacro StartRadioButtons $UserSetting
334        !insertmacro RadioButton ${SecAllUsers}
335        !insertmacro RadioButton ${SecCurUser}
336    !insertmacro EndRadioButtons
337
338    !insertmacro StartRadioButtons $LinkingSet
339        !insertmacro RadioButton ${SecBase}
340        !insertmacro RadioButton ${SecFull}
341    !insertmacro EndRadioButtons
342
343FunctionEnd
344
345# uninstaller sections
346
347Var un.UserSetting
348
349Section "un.Install For"
350
351    # get state of SetShellVarContext
352    ReadRegStr $R0 HKCU "Software\${NAME} ${VERSION}" "Shell Var Context"
353    StrCmp $R0 "all" SetShellUserContext_all
354        StrCpy $un.UserSetting "current"
355        Goto SetShellUserContext_done
356    SetShellUserContext_all:
357        StrCpy $un.UserSetting "all"
358        SetShellVarContext all
359    SetShellUserContext_done:
360
361SectionEnd
362
363Section "Uninstall"
364
365    Delete $INSTDIR\uninstall.exe
366
367    # delete files
368    RMDir /r $INSTDIR
369
370    # delete uninstaller from add/remove programs
371    ReadRegStr $R0 HKCU "SOFTWARE\${NAME} ${VERSION}" "Environment Context"
372    StrCmp $R0 "all" DeleteRegStr_all
373        DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}"
374    Goto DeleteRegStr_done
375    DeleteRegStr_all:
376        DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} ${VERSION}"
377    DeleteRegStr_done:
378
379    # delete desktop shortcut if it was created by the installer
380    ReadRegStr $R0 HKCU "Software\${NAME} ${VERSION}" "Desktop Shortcut"
381    StrCmp $R0 "true" deleteDesktopShortcut
382        Goto doneDeletingDesktopShortcut
383    deleteDesktopShortcut:
384        Delete "$DESKTOP\${NAME} ${VERSION}.lnk"
385    doneDeletingDesktopShortcut:
386
387    # delete file associations if they were created by the installer
388    ReadRegStr $R0 HKCU "Software\${NAME} ${VERSION}" "File Associations"
389    StrCmp $R0 "true" DeleteFileAssociations
390        Goto DeleteFileAssociations_done
391    DeleteFileAssociations:
392        DeleteRegKey HKCR ".lisp"
393        DeleteRegKey HKCR ".lsp"
394        DeleteRegKey HKCR ".cl"
395        DeleteRegKey HKCR ".fas"
396        DeleteRegKey HKCR ".mem"
397        DeleteRegKey HKCR "lispfile"
398        DeleteRegKey HKCR "fasfile"
399        DeleteRegKey HKCR "memfile"
400    DeleteFileAssociations_done:
401
402    # remove PATH Variable
403    ReadRegStr $R0 HKCU "Software\${NAME} ${VERSION}" "PATH"
404    StrCmp $R0 "true" DeletePathEntry
405        Goto DeletePathEntry_done
406    DeletePathEntry:
407        StrCmp $un.UserSetting "all" AddToPath_all
408            ${un.EnvVarUpdate} $0 "PATH" "R" "HKCU" "$INSTDIR"
409        Goto AddToPath_done
410        AddToPath_all:
411            ${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$INSTDIR"
412        AddToPath_done:
413    DeletePathEntry_done:
414
415    # delete contents of start menu folder
416    !insertmacro MUI_STARTMENU_GETFOLDER StartMenu $STARTMENU_TEMP
417
418    Delete "$SMPROGRAMS\$STARTMENU_TEMP\${NAME} ${VERSION}.lnk"
419    Delete "$SMPROGRAMS\$STARTMENU_TEMP\Uninstall ${NAME} ${VERSION}.lnk"
420
421    # delete empty start menu parent diretories
422    StrCpy $STARTMENU_TEMP "$SMPROGRAMS\$STARTMENU_TEMP"
423
424    startMenuDeleteLoop:
425        ClearErrors
426        RMDir $STARTMENU_TEMP
427        GetFullPathName $STARTMENU_TEMP "$STARTMENU_TEMP\.."
428
429        IfErrors startMenuDeleteLoopDone
430
431        StrCmp $STARTMENU_TEMP $SMPROGRAMS startMenuDeleteLoopDone startMenuDeleteLoop
432    startMenuDeleteLoopDone:
433
434    DeleteRegKey /ifempty HKCU "Software\${NAME} ${VERSION}"
435SectionEnd
436