Widow – Blame information for rev 3
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
2 | office | 1 | # This installs two files, app.exe and logo.ico, creates a start menu shortcut, builds an uninstaller, and |
2 | # adds uninstall information to the registry for Add/Remove Programs |
||
3 | |||
4 | # To get started, put this script into a folder with the two files (app.exe, logo.ico, and license.rtf - |
||
5 | # You'll have to create these yourself) and run makensis on it |
||
6 | |||
7 | # If you change the names "app.exe", "logo.ico", or "license.rtf" you should do a search and replace - they |
||
8 | # show up in a few places. |
||
9 | # All the other settings can be tweaked by editing the !defines at the top of this script |
||
10 | !define APPNAME "Widow" |
||
11 | !define COMPANYNAME "Wizardry and Steamworks" |
||
12 | !define DESCRIPTION "Control computer power state after an user-configurable timeout." |
||
13 | # These will be displayed by the "Click here for support information" link in "Add/Remove Programs" |
||
14 | # It is possible to use "mailto:" links in here to open the email client |
||
15 | !define HELPURL "http://widow.grimore.org/" # "Support Information" link |
||
16 | !define UPDATEURL "http://widow.grimore.org/download/" # "Product Updates" link |
||
17 | !define ABOUTURL "http://grimore.org/" # "Publisher" link |
||
18 | # This is the size (in kB) of all the files copied into "Program Files" |
||
19 | #!define INSTALLSIZE 7233 |
||
20 | |||
21 | #### General Use Functions |
||
22 | |||
23 | ## Get version of an exe file. |
||
24 | Function GetFileVersion |
||
25 | !define GetFileVersion `!insertmacro GetFileVersionCall` |
||
26 | |||
27 | !macro GetFileVersionCall _FILE _RESULT |
||
28 | Push `${_FILE}` |
||
29 | Call GetFileVersion |
||
30 | Pop ${_RESULT} |
||
31 | !macroend |
||
32 | |||
33 | Exch $0 |
||
34 | Push $1 |
||
35 | Push $2 |
||
36 | Push $3 |
||
37 | Push $4 |
||
38 | Push $5 |
||
39 | Push $6 |
||
40 | ClearErrors |
||
41 | |||
42 | GetDllVersion '$0' $1 $2 |
||
43 | IfErrors error |
||
44 | IntOp $3 $1 >> 16 |
||
45 | IntOp $3 $3 & 0x0000FFFF |
||
46 | IntOp $4 $1 & 0x0000FFFF |
||
47 | IntOp $5 $2 >> 16 |
||
48 | IntOp $5 $5 & 0x0000FFFF |
||
49 | IntOp $6 $2 & 0x0000FFFF |
||
50 | StrCpy $0 '$3.$4.$5.$6' |
||
51 | goto end |
||
52 | |||
53 | error: |
||
54 | SetErrors |
||
55 | StrCpy $0 '' |
||
56 | |||
57 | end: |
||
58 | Pop $6 |
||
59 | Pop $5 |
||
60 | Pop $4 |
||
61 | Pop $3 |
||
62 | Pop $2 |
||
63 | Pop $1 |
||
64 | Exch $0 |
||
65 | FunctionEnd |
||
66 | |||
67 | ## Explode |
||
68 | !include "LogicLib.nsh" |
||
69 | !define Explode "!insertmacro Explode" |
||
70 | |||
71 | Function Explode |
||
72 | |||
73 | !macro Explode Length Separator String |
||
74 | Push `${Separator}` |
||
75 | Push `${String}` |
||
76 | Call Explode |
||
77 | Pop `${Length}` |
||
78 | !macroend |
||
79 | |||
80 | ; Initialize variables |
||
81 | Var /GLOBAL explString |
||
82 | Var /GLOBAL explSeparator |
||
83 | Var /GLOBAL explStrLen |
||
84 | Var /GLOBAL explSepLen |
||
85 | Var /GLOBAL explOffset |
||
86 | Var /GLOBAL explTmp |
||
87 | Var /GLOBAL explTmp2 |
||
88 | Var /GLOBAL explTmp3 |
||
89 | Var /GLOBAL explArrCount |
||
90 | Var /GLOBAL DirectXSetupError |
||
91 | |||
92 | ; Get input from user |
||
93 | Pop $explString |
||
94 | Pop $explSeparator |
||
95 | |||
96 | ; Calculates initial values |
||
97 | StrLen $explStrLen $explString |
||
98 | StrLen $explSepLen $explSeparator |
||
99 | StrCpy $explArrCount 1 |
||
100 | |||
101 | ${If} $explStrLen <= 1 ; If we got a single character |
||
102 | ${OrIf} $explSepLen > $explStrLen ; or separator is larger than the string, |
||
103 | Push $explString ; then we return initial string with no change |
||
104 | Push 1 ; and set array's length to 1 |
||
105 | Return |
||
106 | ${EndIf} |
||
107 | |||
108 | ; Set offset to the last symbol of the string |
||
109 | StrCpy $explOffset $explStrLen |
||
110 | IntOp $explOffset $explOffset - 1 |
||
111 | |||
112 | ; Clear temp string to exclude the possibility of appearance of occasional data |
||
113 | StrCpy $explTmp "" |
||
114 | StrCpy $explTmp2 "" |
||
115 | StrCpy $explTmp3 "" |
||
116 | |||
117 | ; Loop until the offset becomes negative |
||
118 | ${Do} |
||
119 | ; If offset becomes negative, it is time to leave the function |
||
120 | ${IfThen} $explOffset == -1 ${|} ${ExitDo} ${|} |
||
121 | |||
122 | ; Remove everything before and after the searched part ("TempStr") |
||
123 | StrCpy $explTmp $explString $explSepLen $explOffset |
||
124 | |||
125 | ${If} $explTmp == $explSeparator |
||
126 | ; Calculating offset to start copy from |
||
127 | IntOp $explTmp2 $explOffset + $explSepLen ; Offset equals to the current offset plus length of separator |
||
128 | StrCpy $explTmp3 $explString "" $explTmp2 |
||
129 | |||
130 | Push $explTmp3 ; Throwing array item to the stack |
||
131 | IntOp $explArrCount $explArrCount + 1 ; Increasing array's counter |
||
132 | |||
133 | StrCpy $explString $explString $explOffset 0 ; Cutting all characters beginning with the separator entry |
||
134 | StrLen $explStrLen $explString |
||
135 | ${EndIf} |
||
136 | |||
137 | ${If} $explOffset = 0 ; If the beginning of the line met and there is no separator, |
||
138 | ; copying the rest of the string |
||
139 | ${If} $explSeparator == "" ; Fix for the empty separator |
||
140 | IntOp $explArrCount $explArrCount - 1 |
||
141 | ${Else} |
||
142 | Push $explString |
||
143 | ${EndIf} |
||
144 | ${EndIf} |
||
145 | |||
146 | IntOp $explOffset $explOffset - 1 |
||
147 | ${Loop} |
||
148 | |||
149 | Push $explArrCount |
||
150 | FunctionEnd |
||
151 | |||
152 | Function GetAppVersion |
||
153 | ; Create global variables. |
||
154 | Var /GLOBAL VERSIONMAJOR |
||
155 | Var /GLOBAL VERSIONMINOR |
||
156 | Var /GLOBAL VERSIONBUILD |
||
157 | |||
158 | ; Initialize global variables. |
||
159 | StrCpy $VERSIONMAJOR 1 |
||
160 | StrCpy $VERSIONMINOR 0 |
||
161 | StrCpy $VERSIONBUILD 0 |
||
162 | |||
163 | ; Retrieve executable version. |
||
164 | ${GetFileVersion} "${APPNAME}.exe" $R0 |
||
165 | ${Explode} $0 "." $R0 |
||
166 | Pop $0 |
||
167 | Pop $VERSIONMAJOR |
||
168 | Pop $VERSIONMINOR |
||
169 | Pop $VERSIONBUILD |
||
170 | FunctionEnd |
||
171 | |||
172 | RequestExecutionLevel admin ;Require admin rights on NT6+ (When UAC is turned on) |
||
173 | |||
174 | InstallDir "$PROGRAMFILES\${COMPANYNAME}\${APPNAME}" |
||
175 | |||
176 | # rtf or txt file - remember if it is txt, it must be in the DOS text format (\r\n) |
||
177 | LicenseData "LICENSE.txt" |
||
178 | # This will be in the installer/uninstaller's title bar |
||
179 | Name "${APPNAME}" |
||
180 | Icon "${APPNAME}.ico" |
||
181 | # Set the output file. |
||
182 | outFile "${APPNAME}.exe" |
||
183 | |||
184 | !include LogicLib.nsh |
||
185 | !include nsDialogs.nsh |
||
186 | |||
187 | # Just three pages - license agreement, install location, and installation |
||
188 | page custom nsDialogsImage |
||
189 | page license |
||
190 | page directory |
||
191 | Page instfiles |
||
192 | |||
193 | !macro VerifyUserIsAdmin |
||
194 | UserInfo::GetAccountType |
||
195 | pop $0 |
||
196 | ${If} $0 != "admin" ;Require admin rights on NT4+ |
||
197 | messageBox mb_iconstop "Administrator rights required!" |
||
198 | setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED |
||
199 | quit |
||
200 | ${EndIf} |
||
201 | !macroend |
||
202 | |||
203 | function .onInit |
||
204 | InitPluginsDir |
||
205 | setShellVarContext all |
||
206 | !insertmacro VerifyUserIsAdmin |
||
207 | File /oname=$PLUGINSDIR\image.bmp "wasinstallerlogo.bmp" |
||
208 | # Get the application version. |
||
209 | Call GetAppVersion |
||
210 | functionEnd |
||
211 | |||
212 | Var Dialog |
||
213 | Var Image |
||
214 | Var ImageHandle |
||
215 | |||
216 | Function nsDialogsImage |
||
217 | nsDialogs::Create 1018 |
||
218 | Pop $Dialog |
||
219 | |||
220 | ${If} $Dialog == error |
||
221 | Abort |
||
222 | ${EndIf} |
||
223 | |||
224 | ${NSD_CreateBitmap} 0 0 100% 100% "" |
||
225 | Pop $Image |
||
226 | ${NSD_SetImage} $Image $PLUGINSDIR\image.bmp $ImageHandle |
||
227 | |||
228 | nsDialogs::Show |
||
229 | |||
230 | ${NSD_FreeImage} $ImageHandle |
||
231 | FunctionEnd |
||
232 | |||
233 | section "install" |
||
234 | # Files for the install directory - to build the installer, these should be in the same directory as the install script (this file) |
||
235 | setOutPath $INSTDIR |
||
236 | # Files added here should be removed by the uninstaller (see section "uninstall") |
||
237 | file /r "bin\Release\*.*" |
||
238 | file "${APPNAME}.ico" |
||
239 | # Add any other files for the install directory (license files, app data, etc) here |
||
240 | |||
241 | # Uninstaller - See function un.onInit and section "uninstall" for configuration |
||
242 | writeUninstaller "$INSTDIR\uninstall.exe" |
||
243 | |||
244 | # Create start-menu items |
||
245 | CreateDirectory "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}" |
||
246 | CreateShortCut "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}\uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0 |
||
247 | CreateShortCut "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}\${APPNAME}.lnk" "$INSTDIR\${APPNAME}.exe" "" "$INSTDIR\${APPNAME}.ico" |
||
248 | |||
249 | # Create desktop shortcut |
||
250 | CreateShortCut "$DESKTOP\${APPNAME}.lnk" "$INSTDIR\${APPNAME}.exe" "" |
||
251 | |||
252 | # Registry information for add/remove programs |
||
253 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayName" "${APPNAME}" |
||
254 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\"" |
||
255 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S" |
||
256 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "InstallLocation" "$\"$INSTDIR$\"" |
||
257 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayIcon" "$\"$INSTDIR\${APPNAME}.ico$\"" |
||
258 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "Publisher" "$\"${COMPANYNAME}$\"" |
||
259 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "HelpLink" "$\"${HELPURL}$\"" |
||
260 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "URLUpdateInfo" "$\"${UPDATEURL}$\"" |
||
261 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "URLInfoAbout" "$\"${ABOUTURL}$\"" |
||
262 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayVersion" "$\"$VERSIONMAJOR.$VERSIONMINOR.$VERSIONBUILD$\"" |
||
263 | WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "VersionMajor" $VERSIONMAJOR |
||
264 | WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "VersionMinor" $VERSIONMINOR |
||
265 | # There is no option for modifying or repairing the install |
||
266 | WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "NoModify" 1 |
||
267 | WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "NoRepair" 1 |
||
268 | # Set the INSTALLSIZE constant (!defined at the top of this script) so Add/Remove Programs can accurately report the size |
||
269 | #WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "EstimatedSize" ${INSTALLSIZE} |
||
270 | |||
271 | DetailPrint "Running DirectX Setup..." |
||
272 | ExecWait '"$EXEDIR\DirectX\DXSETUP.exe" /silent' $DirectXSetupError |
||
273 | DetailPrint "Finished DirectX Setup" |
||
274 | sectionEnd |
||
275 | |||
276 | # Uninstaller |
||
277 | |||
278 | function un.onInit |
||
279 | SetShellVarContext all |
||
280 | |||
281 | #Verify the uninstaller - last chance to back out |
||
282 | MessageBox MB_OKCANCEL "Permanantly remove ${APPNAME}?" IDOK next |
||
283 | Abort |
||
284 | next: |
||
285 | !insertmacro VerifyUserIsAdmin |
||
286 | functionEnd |
||
287 | |||
288 | section "uninstall" |
||
289 | |||
290 | # Remove desktop shortcut |
||
291 | delete "$DESKTOP\${APPNAME}.lnk" |
||
292 | # Remove Start Menu items |
||
293 | delete "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}\uninstall.lnk" |
||
294 | delete "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}\${APPNAME}.lnk" |
||
295 | # Try to remove the Start Menu folder for the program. |
||
296 | # NB: This will only happen if it is empty |
||
297 | rmDir "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}" |
||
298 | # Try to remove the Start Menu folder for the company. |
||
299 | rmDir "$SMPROGRAMS\${COMPANYNAME}" |
||
300 | |||
301 | # Remove files |
||
302 | rmDir /r "$INSTDIR\*.*" |
||
303 | |||
304 | # Always delete uninstaller as the last action |
||
305 | delete $INSTDIR\uninstall.exe |
||
306 | |||
307 | # Try to remove the install directory - this will only happen if it is empty |
||
308 | rmDir $INSTDIR |
||
309 | |||
310 | # Remove uninstaller information from the registry |
||
311 | DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" |
||
312 | sectionEnd |