The installer now automatically installs/uninstalls the game for all
[neverball] / scripts / neverball.nsi
1 #------------------------------------------------------------------------------
2
3 !include "LogicLib.nsh"
4
5 !define UNINSTALL_REG_ROOT \
6     "Software\Microsoft\Windows\CurrentVersion\Uninstall\Neverball"
7
8 #------------------------------------------------------------------------------
9
10 OutFile "../neverball-${VERSION}-setup.exe"
11 Name "Neverball ${VERSION}"
12 LicenseData "COPYING.txt"
13 InstallDir "$PROGRAMFILES\Neverball"
14
15 XPStyle on
16
17 #------------------------------------------------------------------------------
18
19 Page license
20 Page components
21 Page directory
22 Page instfiles
23
24 Function .onInit
25     Call IsUserAdmin
26     Pop $R0
27     ${If} $R0 == "true"
28         SetShellVarContext all
29     ${EndIf}
30 FunctionEnd
31
32 Section "Neverball/Neverputt"
33     SectionIn RO
34
35     SetOutPath $INSTDIR
36
37     File *.txt
38     File /oname=AUTHORS.txt doc\AUTHORS.txt
39     File /oname=MANUAL.txt doc\MANUAL.txt
40
41     File /r /x .svn /x *.map /x obj data
42     File /r locale
43
44     File neverball.exe neverputt.exe *.dll
45
46     File /oname=data\icon\neverball.ico dist\newneverball.ico
47     File /oname=data\icon\neverputt.ico dist\newneverputt.ico
48
49     WriteUninstaller $INSTDIR\uninstall.exe
50
51
52     # http://nsis.sourceforge.net/Add_uninstall_information_to_Add/Remove_Programs
53
54     WriteRegStr SHELL_CONTEXT ${UNINSTALL_REG_ROOT} \
55         "DisplayName" "Neverball ${VERSION}"
56     WriteRegStr SHELL_CONTEXT ${UNINSTALL_REG_ROOT} \
57         "DisplayVersion" "${VERSION}"
58     WriteRegStr SHELL_CONTEXT ${UNINSTALL_REG_ROOT} \
59         "DisplayIcon" "$INSTDIR\data\icon\neverball.ico"
60     WriteRegStr SHELL_CONTEXT ${UNINSTALL_REG_ROOT} \
61         "UninstallString" "$INSTDIR\uninstall.exe"
62     WriteRegStr SHELL_CONTEXT ${UNINSTALL_REG_ROOT} \
63         "URLInfoAbout" "http://www.neverball.org/"
64     WriteRegStr SHELL_CONTEXT ${UNINSTALL_REG_ROOT} \
65         "URLUpdateInfo" "http://www.neverball.org/"
66     WriteRegStr SHELL_CONTEXT ${UNINSTALL_REG_ROOT} \
67         "HelpLink" "http://www.nevercorner.net/"
68     WriteRegDWORD SHELL_CONTEXT ${UNINSTALL_REG_ROOT} \
69         "NoModify" 1
70     WriteRegDWORD SHELL_CONTEXT ${UNINSTALL_REG_ROOT} \
71         "NoRepair" 1
72 SectionEnd
73
74 Section "Mapping tools (compiler, maps, ...)"
75     SetOutPath $INSTDIR
76
77     File mapc.exe
78
79     SetOutPath "$INSTDIR\data"
80
81     File /r /x ".svn" data\*.map
82     File /r /x ".svn" data\obj
83 SectionEnd
84
85 SectionGroup "Create shortcuts"
86     Section "In Start menu"
87         # Reset to get a proper working directory for short-cuts
88         SetOutPath $INSTDIR
89     
90         CreateDirectory "$SMPROGRAMS\Games"
91     
92         CreateShortcut \
93             "$SMPROGRAMS\Games\Neverball.lnk" \
94             "$INSTDIR\neverball.exe" ""       \
95             "$INSTDIR\data\icon\neverball.ico"
96     
97         CreateShortcut \
98             "$SMPROGRAMS\Games\Neverputt.lnk" \
99             "$INSTDIR\neverputt.exe" ""       \
100             "$INSTDIR\data\icon\neverputt.ico"
101     SectionEnd
102
103     Section "On desktop"
104         # Reset to get a proper working directory for short-cuts
105         SetOutPath $INSTDIR
106     
107         CreateShortcut \
108             "$DESKTOP\Neverball.lnk"          \
109             "$INSTDIR\neverball.exe" ""       \
110             "$INSTDIR\data\icon\neverball.ico"
111     
112         CreateShortcut \
113             "$DESKTOP\Neverputt.lnk"          \
114             "$INSTDIR\neverputt.exe" ""       \
115             "$INSTDIR\data\icon\neverputt.ico"
116     SectionEnd
117 SectionGroupEnd
118
119 #------------------------------------------------------------------------------
120
121 UninstPage uninstConfirm
122 UninstPage instfiles
123
124 Function un.onInit
125     Call un.IsUserAdmin
126     Pop $R0
127     ${If} $R0 == "true"
128         SetShellVarContext all
129     ${EndIf}
130 FunctionEnd
131
132 Section "Uninstall"
133     Delete "$SMPROGRAMS\Games\Neverball.lnk"
134     Delete "$SMPROGRAMS\Games\Neverputt.lnk"
135     RMDir  "$SMPROGRAMS\Games"
136     Delete "$DESKTOP\Neverball.lnk"
137     Delete "$DESKTOP\Neverputt.lnk"
138
139     DeleteRegKey SHELL_CONTEXT ${UNINSTALL_REG_ROOT}
140
141     # FIXME:  unsafe if the directory contains other-than-installed stuff
142     RMDir /r $INSTDIR
143 SectionEnd
144
145 #------------------------------------------------------------------------------
146
147 # URL:    http://nsis.sourceforge.net/IsUserAdmin
148 # Author: Lilla (lilla@earthlink.net) 2003-06-13
149
150 !macro IsUserAdmin un
151 Function ${un}IsUserAdmin
152     Push $R0
153     Push $R1
154     Push $R2
155  
156     ClearErrors
157     UserInfo::GetName
158     IfErrors Win9x
159     Pop $R1
160     UserInfo::GetAccountType
161     Pop $R2
162  
163     StrCmp $R2 "Admin" 0 Continue
164     StrCpy $R0 "true"
165     Goto Done
166  
167     Continue:
168         StrCmp $R2 "" Win9x
169         StrCpy $R0 "false"
170         Goto Done
171  
172     Win9x:
173         StrCpy $R0 "true"
174  
175     Done:
176
177     Pop $R2
178     Pop $R1
179     Exch $R0
180 FunctionEnd
181 !macroend
182
183 !insertmacro IsUserAdmin ""
184 !insertmacro IsUserAdmin "un."
185
186 #------------------------------------------------------------------------------
187
188 # vim:sts=4:sw=4:et:nowrap: