add some hacky code to allow passing sfc files with -b
[openc2e.git] / openc2e.nsi
blob71e8145714fcf36df6f5071dca0b99a460c0cfd7
1 ; Define your application name
2 !define APPNAME "openc2e"
3 !define APPNAMEANDVERSION "openc2e (development build)"
5 ; Development build revision
6 !define REVISION "1784"
8 ; Main Install settings
9 Name "${APPNAMEANDVERSION}"
10 InstallDir "$PROGRAMFILES\openc2e"
11 InstallDirRegKey HKLM "Software\${APPNAME}" ""
12 OutFile "installers\openc2e-dev${REVISION}-win32.exe"
14 ; Use compression
15 SetCompressor lzma
17 ; Modern interface settings
18 !include "MUI.nsh"
20 ; Icons
21 !define MUI_ICON "instal.ico"
22 !define MUI_UNICON "uninst.ico"
24 !define MUI_ABORTWARNING
26 ;Enable the start menu selection box
27 !define MUI_DIRECTORYPAGE
29 !insertmacro MUI_PAGE_WELCOME
30 !insertmacro MUI_PAGE_LICENSE "COPYING"
31 !insertmacro MUI_PAGE_DIRECTORY
32 !insertmacro MUI_PAGE_INSTFILES
33 !insertmacro MUI_PAGE_FINISH
35 !insertmacro MUI_UNPAGE_CONFIRM
36 !insertmacro MUI_UNPAGE_INSTFILES
38 ; Set languages (first is default language)
39 !insertmacro MUI_LANGUAGE "English"
40 !insertmacro MUI_LANGUAGE "Dutch"
41 !insertmacro MUI_LANGUAGE "French"
42 !insertmacro MUI_LANGUAGE "German"
43 !insertmacro MUI_LANGUAGE "Spanish"
44 !insertmacro MUI_RESERVEFILE_LANGDLL
46 !macro IfKeyExists ROOT MAIN_KEY KEY
47 push $R0
48 push $R1
50 !define Index 'Line${__LINE__}'
52 StrCpy $R1 "0"
54 "${Index}-Loop:"
55 ; Check for Key
56 EnumRegKey $R0 ${ROOT} "${MAIN_KEY}" "$R1"
57 StrCmp $R0 "" "${Index}-False"
58 IntOp $R1 $R1 + 1
59 StrCmp $R0 "${KEY}" "${Index}-True" "${Index}-Loop"
61 "${Index}-True:"
62 ;Return 1 if found
63 push "1"
64 goto "${Index}-End"
66 "${Index}-False:"
67 ;Return 0 if not found
68 push "0"
69 goto "${Index}-End"
71 "${Index}-End:"
72 !undef Index
73 exch 2
74 pop $R0
75 pop $R1
76 !macroend
78 !macro GetCleanDir INPUTDIR
79 ; ATTENTION: USE ON YOUR OWN RISK!
80 ; Please report bugs here: http://stefan.bertels.org/
81 !define Index_GetCleanDir 'GetCleanDir_Line${__LINE__}'
82 Push $R0
83 Push $R1
84 StrCpy $R0 "${INPUTDIR}"
85 StrCmp $R0 "" ${Index_GetCleanDir}-finish
86 StrCpy $R1 "$R0" "" -1
87 StrCmp "$R1" "\" ${Index_GetCleanDir}-finish
88 StrCpy $R0 "$R0\"
89 ${Index_GetCleanDir}-finish:
90 Pop $R1
91 Exch $R0
92 !undef Index_GetCleanDir
93 !macroend
95 !macro RemoveFilesAndSubDirs DIRECTORY
96 ; ATTENTION: USE ON YOUR OWN RISK!
97 ; Please report bugs here: http://stefan.bertels.org/
98 !define Index_RemoveFilesAndSubDirs 'RemoveFilesAndSubDirs_${__LINE__}'
100 Push $R0
101 Push $R1
102 Push $R2
104 !insertmacro GetCleanDir "${DIRECTORY}"
105 Pop $R2
106 FindFirst $R0 $R1 "$R2*.*"
107 ${Index_RemoveFilesAndSubDirs}-loop:
108 StrCmp $R1 "" ${Index_RemoveFilesAndSubDirs}-done
109 StrCmp $R1 "." ${Index_RemoveFilesAndSubDirs}-next
110 StrCmp $R1 ".." ${Index_RemoveFilesAndSubDirs}-next
111 IfFileExists "$R2$R1\*.*" ${Index_RemoveFilesAndSubDirs}-directory
112 ; file
113 Delete "$R2$R1"
114 goto ${Index_RemoveFilesAndSubDirs}-next
115 ${Index_RemoveFilesAndSubDirs}-directory:
116 ; directory
117 RMDir /r "$R2$R1"
118 ${Index_RemoveFilesAndSubDirs}-next:
119 FindNext $R0 $R1
120 Goto ${Index_RemoveFilesAndSubDirs}-loop
121 ${Index_RemoveFilesAndSubDirs}-done:
122 FindClose $R0
124 Pop $R2
125 Pop $R1
126 Pop $R0
127 !undef Index_RemoveFilesAndSubDirs
128 !macroend
130 Function CheckVCRedist
131 Push $R0
132 ClearErrors
133 ReadRegDword $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{7299052b-02a4-4627-81f2-1818da5d550d}" "Version"
135 ; if VS 2005+ redist SP1 not installed, install it
136 IfErrors 0 yay
137 StrCpy $R0 "-1"
138 Goto done
140 yay:
141 StrCpy $R0 "1"
143 done:
144 Exch $R0
145 FunctionEnd
147 Section "openc2e" Main
149 ; Set Section properties
150 SetOverwrite on
152 ; Set Section Files and Shortcuts
153 SetOutPath "$INSTDIR\"
155 IfFileExists "$INSTDIR\uninstall.exe" remold
156 Goto proceed
158 remold:
159 MessageBox MB_YESNO 'An old version of openc2e is installed. Do you wish to$\rremove it before proceeding (recommended)?' IDYES remold1
160 Goto proceed
161 remold1:
162 ExecWait '"$INSTDIR\uninstall.exe" _?=$INSTDIR /S'
164 proceed:
165 File "Release\openc2e.exe"
166 File "Release\SDL.dll"
167 ;File "Release\SDL_mixer.dll"
168 File "Release\SDL_net.dll"
169 File "Release\SDL_ttf.dll"
170 File "Release\zlib1.dll"
171 File "Release\libfreetype-6.dll"
172 File "Release\QtCore4.dll"
173 File "Release\QtGui4.dll"
174 File "Release\QtNetwork4.dll"
175 File "Release\alut.dll"
177 File "VeraSe.ttf"
179 ;OpenAL installer
180 File "Release\oalinst.exe"
182 File "tools\braininavat\Brain-in-a-vat\Release\Brain-in-a-vat.exe"
183 File "tools\debugkit\DebugKit\release\DebugKit.exe"
184 File "gamefinder.exe"
186 CreateDirectory "$SMPROGRAMS\openc2e\Tools"
187 CreateDirectory "$SMPROGRAMS\openc2e\Games"
188 CreateDirectory "$SMPROGRAMS\openc2e"
189 CreateShortCut "$SMPROGRAMS\openc2e\Tools\Brain-in-a-Vat.lnk" "$INSTDIR\Brain-in-a-vat.exe"
190 CreateShortCut "$SMPROGRAMS\openc2e\Tools\Debug Kit.lnk" "$INSTDIR\DebugKit.exe"
191 CreateShortCut "$SMPROGRAMS\openc2e\Update Game Shortcuts.lnk" "$INSTDIR\gamefinder.exe"
192 CreateShortCut "$SMPROGRAMS\openc2e\Uninstall.lnk" "$INSTDIR\uninstall.exe"
194 SectionEnd
196 Section -FinishSection
198 WriteRegStr HKLM "Software\${APPNAME}" "" "$INSTDIR"
199 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayName" "${APPNAME}"
200 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "UninstallString" "$INSTDIR\uninstall.exe"
201 WriteUninstaller "$INSTDIR\uninstall.exe"
203 ;Run the OpenAL installer silently
204 DetailPrint "Installing OpenAL sound library..."
205 ExecWait '"$INSTDIR\oalinst.exe" /s'
206 Delete "$INSTDIR\oalinst.exe"
208 DetailPrint "Checking for VC++ runtime libraries..."
209 Call CheckVCRedist
210 Pop $R0
211 StrCmp $R0 "1" foundvc
212 ReadRegDword $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{7299052b-02a4-4627-81f2-1818da5d550d}" "Version"
213 MessageBox MB_YESNO "Based on a cursory examination, you do not appear to have necessary VC++ runtime$\rlibraries installed. However, if you have Visual Studio 2005 installed, I could$\rbe wrong. Would you like to download and install these libraries? (2.5mb or so)$\rIf you do not know for sure, I'd go with 'Yes'." IDYES installvc
214 MessageBox MB_OK "Fair enough. If openc2e fails to run, make sure to acquire the Visual C++ 2005$\rruntime libraries from http://openc2e.ccdevnet.org/files/win32/vcredist_x86.exe"
215 Goto finishup
217 foundvc:
218 DetailPrint "VC++ runtime libraries found (probably.)"
219 Goto finishup
221 installvc:
222 DetailPrint "Downloading VC++ runtime library redistributable..."
223 NSISdl::download http://openc2e.ccdevnet.org/files/win32/vcredist_x86.exe $INSTDIR\vcredist_x86.exe
224 Pop $R0
225 StrCmp $R0 "success" runvcinst
226 MessageBox MB_OK|MB_ICONSTOP "The download of the VC++ runtime library installer failed: $R0 $\rSorry, but I guess you'll have to download it yourself. :($\r (http://openc2e.ccdevnet.org/files/win32/vcredist_x86.exe)"
227 Goto finishup
228 runvcinst:
229 ExecWait "$INSTDIR\vcredist_x86.exe"
230 Delete "$INSTDIR\vcredist_x86.exe"
232 finishup:
233 ;Run the shortcut-maker
234 ;MessageBox MB_YESNO 'Look for installed Creatures games now? $\rIf you choose to wait, you can run "Update Game Shortcuts" from the start menu later.' IDYES run
235 ;Goto end
236 ;run:
237 DetailPrint "Searching for installed creatures games..."
238 ExecWait '"$INSTDIR\gamefinder.exe" /S'
239 end:
240 SectionEnd
242 ; Modern install component descriptions
243 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
244 !insertmacro MUI_DESCRIPTION_TEXT ${Main} ""
245 !insertmacro MUI_FUNCTION_DESCRIPTION_END
247 ;Uninstall section
248 Section Uninstall
250 ; Remove from registry...
251 DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}"
252 DeleteRegKey HKLM "SOFTWARE\${APPNAME}"
254 ; Delete Program Files
255 !insertmacro RemoveFilesAndSubDirs "$INSTDIR\"
257 ; Delete Shortcuts
258 !insertmacro RemoveFilesAndSubDirs "$SMPROGRAMS\${APPNAME}\"
260 ; Remove remaining directories
261 RMDir "$SMPROGRAMS\openc2e\Tools"
262 RMDir "$SMPROGRAMS\openc2e\Games"
263 RMDir "$SMPROGRAMS\openc2e"
264 RMDir "$INSTDIR\"
266 SectionEnd
268 ; On initialization
269 Function .onInit
271 !insertmacro MUI_LANGDLL_DISPLAY
273 FunctionEnd
275 BrandingText "http://openc2e.ccdevnet.org"