Winify – Blame information for rev 2
?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 "Winify" |
||
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://winify.grimore.org/" # "Support Information" link |
||
16 | !define UPDATEURL "http://winify.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 | |||
91 | ; Get input from user |
||
92 | Pop $explString |
||
93 | Pop $explSeparator |
||
94 | |||
95 | ; Calculates initial values |
||
96 | StrLen $explStrLen $explString |
||
97 | StrLen $explSepLen $explSeparator |
||
98 | StrCpy $explArrCount 1 |
||
99 | |||
100 | ${If} $explStrLen <= 1 ; If we got a single character |
||
101 | ${OrIf} $explSepLen > $explStrLen ; or separator is larger than the string, |
||
102 | Push $explString ; then we return initial string with no change |
||
103 | Push 1 ; and set array's length to 1 |
||
104 | Return |
||
105 | ${EndIf} |
||
106 | |||
107 | ; Set offset to the last symbol of the string |
||
108 | StrCpy $explOffset $explStrLen |
||
109 | IntOp $explOffset $explOffset - 1 |
||
110 | |||
111 | ; Clear temp string to exclude the possibility of appearance of occasional data |
||
112 | StrCpy $explTmp "" |
||
113 | StrCpy $explTmp2 "" |
||
114 | StrCpy $explTmp3 "" |
||
115 | |||
116 | ; Loop until the offset becomes negative |
||
117 | ${Do} |
||
118 | ; If offset becomes negative, it is time to leave the function |
||
119 | ${IfThen} $explOffset == -1 ${|} ${ExitDo} ${|} |
||
120 | |||
121 | ; Remove everything before and after the searched part ("TempStr") |
||
122 | StrCpy $explTmp $explString $explSepLen $explOffset |
||
123 | |||
124 | ${If} $explTmp == $explSeparator |
||
125 | ; Calculating offset to start copy from |
||
126 | IntOp $explTmp2 $explOffset + $explSepLen ; Offset equals to the current offset plus length of separator |
||
127 | StrCpy $explTmp3 $explString "" $explTmp2 |
||
128 | |||
129 | Push $explTmp3 ; Throwing array item to the stack |
||
130 | IntOp $explArrCount $explArrCount + 1 ; Increasing array's counter |
||
131 | |||
132 | StrCpy $explString $explString $explOffset 0 ; Cutting all characters beginning with the separator entry |
||
133 | StrLen $explStrLen $explString |
||
134 | ${EndIf} |
||
135 | |||
136 | ${If} $explOffset = 0 ; If the beginning of the line met and there is no separator, |
||
137 | ; copying the rest of the string |
||
138 | ${If} $explSeparator == "" ; Fix for the empty separator |
||
139 | IntOp $explArrCount $explArrCount - 1 |
||
140 | ${Else} |
||
141 | Push $explString |
||
142 | ${EndIf} |
||
143 | ${EndIf} |
||
144 | |||
145 | IntOp $explOffset $explOffset - 1 |
||
146 | ${Loop} |
||
147 | |||
148 | Push $explArrCount |
||
149 | FunctionEnd |
||
150 | |||
151 | Function GetAppVersion |
||
152 | ; Create global variables. |
||
153 | Var /GLOBAL VERSIONMAJOR |
||
154 | Var /GLOBAL VERSIONMINOR |
||
155 | Var /GLOBAL VERSIONBUILD |
||
156 | |||
157 | ; Initialize global variables. |
||
158 | StrCpy $VERSIONMAJOR 1 |
||
159 | StrCpy $VERSIONMINOR 0 |
||
160 | StrCpy $VERSIONBUILD 0 |
||
161 | |||
162 | ; Retrieve executable version. |
||
163 | ${GetFileVersion} "${APPNAME}.exe" $R0 |
||
164 | ${Explode} $0 "." $R0 |
||
165 | Pop $0 |
||
166 | Pop $VERSIONMAJOR |
||
167 | Pop $VERSIONMINOR |
||
168 | Pop $VERSIONBUILD |
||
169 | FunctionEnd |
||
170 | |||
171 | RequestExecutionLevel admin ;Require admin rights on NT6+ (When UAC is turned on) |
||
172 | |||
173 | InstallDir "$PROGRAMFILES\${COMPANYNAME}\${APPNAME}" |
||
174 | |||
175 | # rtf or txt file - remember if it is txt, it must be in the DOS text format (\r\n) |
||
176 | LicenseData "LICENSE.txt" |
||
177 | # This will be in the installer/uninstaller's title bar |
||
178 | Name "${APPNAME}" |
||
179 | Icon "${APPNAME}.ico" |
||
180 | # Set the output file. |
||
181 | outFile "${APPNAME}.exe" |
||
182 | |||
183 | !include LogicLib.nsh |
||
184 | !include nsDialogs.nsh |
||
185 | |||
186 | # Just three pages - license agreement, install location, and installation |
||
187 | page custom nsDialogsImage |
||
188 | page license |
||
189 | page directory |
||
190 | Page instfiles |
||
191 | |||
192 | !macro VerifyUserIsAdmin |
||
193 | UserInfo::GetAccountType |
||
194 | pop $0 |
||
195 | ${If} $0 != "admin" ;Require admin rights on NT4+ |
||
196 | messageBox mb_iconstop "Administrator rights required!" |
||
197 | setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED |
||
198 | quit |
||
199 | ${EndIf} |
||
200 | !macroend |
||
201 | |||
202 | function .onInit |
||
203 | InitPluginsDir |
||
204 | setShellVarContext all |
||
205 | !insertmacro VerifyUserIsAdmin |
||
206 | File /oname=$PLUGINSDIR\image.bmp "wasinstallerlogo.bmp" |
||
207 | # Get the application version. |
||
208 | Call GetAppVersion |
||
209 | functionEnd |
||
210 | |||
211 | Var Dialog |
||
212 | Var Image |
||
213 | Var ImageHandle |
||
214 | |||
215 | Function nsDialogsImage |
||
216 | nsDialogs::Create 1018 |
||
217 | Pop $Dialog |
||
218 | |||
219 | ${If} $Dialog == error |
||
220 | Abort |
||
221 | ${EndIf} |
||
222 | |||
223 | ${NSD_CreateBitmap} 0 0 100% 100% "" |
||
224 | Pop $Image |
||
225 | ${NSD_SetImage} $Image $PLUGINSDIR\image.bmp $ImageHandle |
||
226 | |||
227 | nsDialogs::Show |
||
228 | |||
229 | ${NSD_FreeImage} $ImageHandle |
||
230 | FunctionEnd |
||
231 | |||
232 | section "install" |
||
233 | # Files for the install directory - to build the installer, these should be in the same directory as the install script (this file) |
||
234 | setOutPath $INSTDIR |
||
235 | # Files added here should be removed by the uninstaller (see section "uninstall") |
||
236 | file /r "bin\Release\*.*" |
||
237 | file "${APPNAME}.ico" |
||
238 | # Add any other files for the install directory (license files, app data, etc) here |
||
239 | |||
240 | # Uninstaller - See function un.onInit and section "uninstall" for configuration |
||
241 | writeUninstaller "$INSTDIR\uninstall.exe" |
||
242 | |||
243 | # Create start-menu items |
||
244 | CreateDirectory "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}" |
||
245 | CreateShortCut "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}\uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0 |
||
246 | CreateShortCut "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}\${APPNAME}.lnk" "$INSTDIR\${APPNAME}.exe" "" "$INSTDIR\${APPNAME}.ico" |
||
247 | |||
248 | # Create desktop shortcut |
||
249 | CreateShortCut "$DESKTOP\${APPNAME}.lnk" "$INSTDIR\${APPNAME}.exe" "" |
||
250 | |||
251 | # Registry information for add/remove programs |
||
252 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayName" "${APPNAME}" |
||
253 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\"" |
||
254 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S" |
||
255 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "InstallLocation" "$\"$INSTDIR$\"" |
||
256 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayIcon" "$\"$INSTDIR\${APPNAME}.ico$\"" |
||
257 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "Publisher" "$\"${COMPANYNAME}$\"" |
||
258 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "HelpLink" "$\"${HELPURL}$\"" |
||
259 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "URLUpdateInfo" "$\"${UPDATEURL}$\"" |
||
260 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "URLInfoAbout" "$\"${ABOUTURL}$\"" |
||
261 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayVersion" "$\"$VERSIONMAJOR.$VERSIONMINOR.$VERSIONBUILD$\"" |
||
262 | WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "VersionMajor" $VERSIONMAJOR |
||
263 | WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "VersionMinor" $VERSIONMINOR |
||
264 | # There is no option for modifying or repairing the install |
||
265 | WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "NoModify" 1 |
||
266 | WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "NoRepair" 1 |
||
267 | # Set the INSTALLSIZE constant (!defined at the top of this script) so Add/Remove Programs can accurately report the size |
||
268 | #WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "EstimatedSize" ${INSTALLSIZE} |
||
269 | |||
270 | sectionEnd |
||
271 | |||
272 | # Uninstaller |
||
273 | |||
274 | function un.onInit |
||
275 | SetShellVarContext all |
||
276 | |||
277 | #Verify the uninstaller - last chance to back out |
||
278 | MessageBox MB_OKCANCEL "Permanantly remove ${APPNAME}?" IDOK next |
||
279 | Abort |
||
280 | next: |
||
281 | !insertmacro VerifyUserIsAdmin |
||
282 | functionEnd |
||
283 | |||
284 | section "uninstall" |
||
285 | |||
286 | # Remove desktop shortcut |
||
287 | delete "$DESKTOP\${APPNAME}.lnk" |
||
288 | # Remove Start Menu items |
||
289 | delete "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}\uninstall.lnk" |
||
290 | delete "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}\${APPNAME}.lnk" |
||
291 | # Try to remove the Start Menu folder for the program. |
||
292 | # NB: This will only happen if it is empty |
||
293 | rmDir "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}" |
||
294 | # Try to remove the Start Menu folder for the company. |
||
295 | rmDir "$SMPROGRAMS\${COMPANYNAME}" |
||
296 | |||
297 | # Remove files |
||
298 | rmDir /r "$INSTDIR\*.*" |
||
299 | |||
300 | # Always delete uninstaller as the last action |
||
301 | delete $INSTDIR\uninstall.exe |
||
302 | |||
303 | # Try to remove the install directory - this will only happen if it is empty |
||
304 | rmDir $INSTDIR |
||
305 | |||
306 | # Remove uninstaller information from the registry |
||
307 | DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" |
||
308 | sectionEnd |