-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nsisfile.nsi
315 lines (236 loc) · 9.66 KB
/
Nsisfile.nsi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
; Haskell Platform Installer
;--------------------------------
;Includes
!Include "EnvVarUpdate.nsh"
!Include "FileFunc.nsh"
!Include "LogicLib.nsh"
!Include "MUI2.nsh"
!Include "WordFunc.nsh"
!Include "CreateInternetShortcut.nsh"
;--------------------------------
;Defines
!Define GHC_VERSION "7.4.2"
!Define PLATFORM_VERSION "2012.4.0.0"
!Define PRODUCT_DIR_REG_KEY "Software\Haskell\Haskell Platform\${PLATFORM_VERSION}"
!Define HACKAGE_SHORTCUT_TEXT "HackageDB - Haskell Software Repository"
!Define FILES_SOURCE_PATH "files"
!Define INST_DAT "inst.dat"
!Define UNINST_DAT "uninst.dat"
;--------------------------------
;Variables
Var START_MENU_FOLDER
;--------------------------------
;General settings
;Name and file
Name "Haskell Platform ${PLATFORM_VERSION}"
OutFile "HaskellPlatform-${PLATFORM_VERSION}-setup.exe"
;Default install dir
InstallDir "$PROGRAMFILES\Haskell Platform\${PLATFORM_VERSION}"
InstallDirRegKey HKLM "${PRODUCT_DIR_REG_KEY}" ""
;Icon
!Define MUI_ICON "icons/installer.ico"
!Define MUI_UNICON "icons/installer.ico"
;Request application privileges for Windows Vista
RequestExecutionLevel highest
;Best available compression
SetCompressor /SOLID lzma
;Install types
InstType "Standard"
InstType "Portable (just unpack the files)"
;--------------------------------
;Macros
!macro CheckAdmin thing
UserInfo::GetAccountType
pop $0
${If} $0 != "admin" ;Require admin rights on NT4+
MessageBox MB_YESNO "It is recommended to run this ${thing} as administrator. Do you want to quit and restart the ${thing} manually with elevated privileges?" IDNO CheckAdminDone
SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
Quit
${EndIf}
CheckAdminDone:
!macroend
;--------------------------------
;Callbacks
Function .onInit
!insertmacro CheckAdmin "installer"
SetShellVarContext all
FunctionEnd
Function un.onInit
!insertmacro CheckAdmin "uninstaller"
SetShellVarContext all
FunctionEnd
Function .onInstSuccess
IfFileExists $SYSDIR\glut32.dll Done
MessageBox MB_YESNO "It looks like glut32.dll is not installed. You will not be able to use the GLUT library. Do you want to copy glut32.dll to the system directory?" IDNO Done
SetOutPath "$SYSDIR\."
File "${FILES_SOURCE_PATH}\etc\glut32.dll"
Done:
FunctionEnd
;--------------------------------
;Interface Settings
!define MUI_ABORTWARNING
;--------------------------------
;Pages
!Define MUI_WELCOMEFINISHPAGE_BITMAP "welcome.bmp"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "LICENSE"
!insertmacro MUI_PAGE_DIRECTORY
!Define MUI_COMPONENTSPAGE_NODESC
!insertmacro MUI_PAGE_COMPONENTS
;Start Menu Folder Page Configuration
!Define MUI_PAGE_HEADER_SUBTEXT \
"Choose a Start Menu folder for the Haskell Platform ${PLATFORM_VERSION} shortcuts."
!Define MUI_STARTMENUPAGE_TEXT_TOP \
"Select the Start Menu folder in which you would like to create Haskell Platform shortcuts. You can also enter a name to create a new folder."
!Define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKLM"
!Define MUI_STARTMENUPAGE_REGISTRY_KEY "${PRODUCT_DIR_REG_KEY}"
!Define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
!Define MUI_STARTMENUPAGE_DEFAULTFOLDER "Haskell Platform ${PLATFORM_VERSION}"
!insertmacro MUI_PAGE_STARTMENU StartMenuPage $START_MENU_FOLDER
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
;Installer Sections
Section "Base components" SecMain
SectionIn 1 2
; Make this section mandatory
SectionIn RO
!Include ${INST_DAT}
SectionEnd
SectionGroup "Update system settings" SecGr
Section "Associate with .hs/.lhs files" SecAssoc
SectionIn 1
; File associations
WriteRegStr HKCR ".hs" "" "ghc_haskell"
WriteRegStr HKCR ".lhs" "" "ghc_haskell"
WriteRegStr HKCR "ghc_haskell" "" "Haskell Source File"
WriteRegStr HKCR "ghc_haskell\DefaultIcon" "" "$INSTDIR\icons\hsicon.ico"
WriteRegStr HKCR "ghc_haskell\shell\open\command" "" '"$INSTDIR\bin\ghci.exe" "%1"'
;Remember that we registered associations
WriteRegDWORD HKLM "${PRODUCT_DIR_REG_KEY}" Assocs 0x1
SectionEnd
Section "Add versioned GHCi to right-click menu" SecGHCiVersioned
SectionIn 1
WriteRegStr HKCR "ghc_haskell\shell\Open with GHCi ${GHC_VERSION}" "" ""
WriteRegStr HKCR "ghc_haskell\shell\Open with GHCi ${GHC_VERSION}\command" "" '"$INSTDIR\bin\ghci.exe" "%1"'
;Remember that we added versioned GHCi
WriteRegDWORD HKLM "${PRODUCT_DIR_REG_KEY}" VersionedGHCi 0x1
SectionEnd
Section "Update the PATH environment variable" SecPath
SectionIn 1
; Update PATH
${EnvVarUpdate} $0 "PATH" "P" "HKLM" "$INSTDIR\bin"
${EnvVarUpdate} $0 "PATH" "P" "HKLM" "$INSTDIR\lib\extralibs\bin"
${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$INSTDIR\mingw\bin"
${EnvVarUpdate} $0 "PATH" "P" "HKLM" "$PROGRAMFILES\Haskell\bin"
SetShellVarContext current
${EnvVarUpdate} $0 "PATH" "P" "HKCU" "$APPDATA\cabal\bin"
SetShellVarContext all
SectionEnd
Section "Store GHC's location in registry" SecGHCLoc
SectionIn 1
; (copied from the GHC installer).
WriteRegStr HKCU "Software\Haskell\GHC\ghc-${GHC_VERSION}" "InstallDir" "$INSTDIR"
WriteRegStr HKCU "Software\Haskell\GHC" "InstallDir" "$INSTDIR"
SectionEnd
Section "Create uninstaller" SecAddRem
SectionIn 1
SectionIn RO
; Add uninstall information to Add/Remove Programs
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\HaskellPlatform-${PLATFORM_VERSION}" \
"DisplayName" "Haskell Platform ${PLATFORM_VERSION}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\HaskellPlatform-${PLATFORM_VERSION}" \
"UninstallString" "$\"$INSTDIR\Uninstall.exe$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\HaskellPlatform-${PLATFORM_VERSION}" \
"DisplayIcon" "$INSTDIR\icons\installer.ico"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\HaskellPlatform-${PLATFORM_VERSION}" \
"Publisher" "Haskell.org"
;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
; This is needed for uninstaller to work
WriteRegStr HKLM "${PRODUCT_DIR_REG_KEY}" "" "$INSTDIR\Uninstall.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REG_KEY}" "InstallDir" "$INSTDIR"
SectionEnd
SectionGroupEnd
Section "-StartMenu" StartMenu
SectionIn 1 2
; Add start menu shortcuts
!insertmacro MUI_STARTMENU_WRITE_BEGIN StartMenuPage
;Create shortcuts
CreateDirectory "$SMPROGRAMS\$START_MENU_FOLDER"
!insertmacro CreateInternetShortcut \
"$SMPROGRAMS\$START_MENU_FOLDER\${HACKAGE_SHORTCUT_TEXT}" \
"http://hackage.haskell.org" \
"$INSTDIR\icons\hackage.ico" "0"
CreateShortCut \
"$SMPROGRAMS\$START_MENU_FOLDER\GHC Documentation.lnk" \
"$INSTDIR\doc\html\index.html"
CreateShortCut \
"$SMPROGRAMS\$START_MENU_FOLDER\GHC Flag Reference.lnk" \
"$INSTDIR\doc\html\users_guide\flag-reference.html"
CreateShortCut \
"$SMPROGRAMS\$START_MENU_FOLDER\GHC Library Documentation.lnk" \
"$INSTDIR\doc\html\libraries\index.html"
CreateShortCut "$SMPROGRAMS\$START_MENU_FOLDER\GHCi.lnk" \
"$INSTDIR\bin\ghci.exe"
CreateShortCut "$SMPROGRAMS\$START_MENU_FOLDER\WinGHCi.lnk" \
"$INSTDIR\winghci\winghci.exe"
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
;--------------------------------
;Uninstaller Section
Section "Uninstall"
!Include ${UNINST_DAT}
Delete "$INSTDIR\Uninstall.exe"
RMDir $INSTDIR
;Since we install to '$PF\Haskell Platform\$PLATFORM_VERSION', we
;should also try to delete '$PF\Haskell Platform' if it is empty.
${GetParent} $INSTDIR $R0
RMDir $R0
; Delete start menu shortcuts
!insertmacro MUI_STARTMENU_GETFOLDER StartMenuPage $START_MENU_FOLDER
Delete "$SMPROGRAMS\$START_MENU_FOLDER\GHC Documentation.lnk"
Delete "$SMPROGRAMS\$START_MENU_FOLDER\GHC Flag Reference.lnk"
Delete "$SMPROGRAMS\$START_MENU_FOLDER\GHC Library Documentation.lnk"
Delete "$SMPROGRAMS\$START_MENU_FOLDER\GHCi.lnk"
Delete "$SMPROGRAMS\$START_MENU_FOLDER\WinGHCi.lnk"
Delete "$SMPROGRAMS\$START_MENU_FOLDER\${HACKAGE_SHORTCUT_TEXT}.url"
RMDir "$SMPROGRAMS\$START_MENU_FOLDER\"
; Delete registry keys
ReadRegDWORD $0 HKLM "${PRODUCT_DIR_REG_KEY}" VersionedGHCi
${If} $0 = 0x1
DeleteRegKey HKCR "ghc_haskell\shell\Open with GHCi ${GHC_VERSION}\command"
DeleteRegKey HKCR "ghc_haskell\shell\Open with GHCi ${GHC_VERSION}"
${EndIf}
ReadRegDWORD $0 HKLM "${PRODUCT_DIR_REG_KEY}" Assocs
${If} $0 = 0x1
DeleteRegValue HKCR ".hs" ""
DeleteRegValue HKCR ".lhs" ""
DeleteRegValue HKCR "ghc_haskell\shell\open\command" ""
DeleteRegKey HKCR "ghc_haskell\DefaultIcon"
DeleteRegKey /IfEmpty HKCR "ghc_haskell\shell\open\command"
DeleteRegKey /IfEmpty HKCR "ghc_haskell\shell\open"
DeleteRegKey /IfEmpty HKCR "ghc_haskell\shell"
DeleteRegKey /IfEmpty HKCR "ghc_haskell"
${EndIf}
DeleteRegKey HKCU "Software\Haskell\GHC\ghc-${GHC_VERSION}"
DeleteRegKey HKCU "Software\Haskell\GHC"
DeleteRegKey HKLM "${PRODUCT_DIR_REG_KEY}"
DeleteRegKey /IfEmpty HKCU Software\Haskell
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\HaskellPlatform-${PLATFORM_VERSION}"
; Update PATH
${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$INSTDIR\bin"
${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$INSTDIR\lib\extralibs\bin"
${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$INSTDIR\mingw\bin"
${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$PROGRAMFILES\Haskell\bin"
SetShellVarContext current
${un.EnvVarUpdate} $0 "PATH" "R" "HKCU" "$APPDATA\cabal\bin"
SetShellVarContext all
SectionEnd