-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSetup.ahk
365 lines (327 loc) · 16 KB
/
Setup.ahk
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
; (c) Copyright 2009-2021 AeroZoom by wandersick | https://tech.wandersick.com
;
; This is the Setup. See main script for more.
;
#SingleInstance Force
#NoTrayIcon
verAZ = 4.0 beta 2
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Missing component check
IfNotExist, %A_WorkingDir%\Data
{
Msgbox, 262192, AeroZoom, Missing essential components.`n`nPlease download the legitimate version from tech.wandersick.com.
ExitApp
}
targetDir=%localappdata%
If %1% {
Loop, %0% ; For each parameter:
{
param := %A_Index% ; Fetch the contents of the variable whose name is contained in A_Index.
If (param="/unattendAZ=1")
unattendAZ=1
Else if (param="/unattendAZ=2")
unattendAZ=2
Else if (param="/programfiles")
{
targetDir=%programfiles%
setupAllUsers=1
}
Else
{
Msgbox, 262192, AeroZoom Setup, Supported parameters:`n`n - Unattended setup : /unattendAZ=1`n - Install for all users : /programfiles`n`nFor example: Setup.exe /programfiles /unattendaz=1`n`nNote:`n - If setup finds a copy in the target location, uninstallation will be carried out instead.`n - If you install into Program Files folder, be sure you're running it with administrator rights.
ExitApp
}
}
}
; check path to AeroZoom_Task.bat
IfExist, %A_WorkingDir%\AeroZoom_Task.bat
TaskPath=%A_WorkingDir%
IfExist, %A_WorkingDir%\Data\AeroZoom_Task.bat
TaskPath=%A_WorkingDir%\Data
IfWinExist, ahk_class AutoHotkeyGUI, AeroZoom ; Check if a portable copy is running
ExistAZ=1
; Install / Unisntall
regKey=SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\AeroZoom
IfNotExist, %targetDir%\wandersick\AeroZoom\AeroZoom.exe
{
IfNotEqual, unattendAZ, 1
{
MsgBox, 262180, AeroZoom Installer , Install AeroZoom in the following location?`n`n%targetDir%\wandersick\AeroZoom`n`nNote:`n - For portable use, just run AeroZoom.exe. Setup is unneeded.`n - To install silently or to all users, run Setup.exe /? to see how.`n - To remove a copy that was installed to all users, run Setup.exe /programfiles
IfMsgBox No
{
Exitapp
}
}
Gosub, KillProcess
; Remove existing directory
FileRemoveDir, %targetDir%\wandersick\AeroZoom\Data, 1
FileRemoveDir, %targetDir%\wandersick\AeroZoom, 1
; Copy AeroZoom to %targetDir%
FileCreateDir, %targetDir%\wandersick\AeroZoom
; RunWait, 7z.exe -y x AeroZoom.7z -o"%targetDir%\wandersick\",%A_ScriptDir%
FileCopyDir, %A_WorkingDir%, %targetDir%\wandersick\AeroZoom, 1
; Create shortcut to Start Menu (Current User)
IfExist, %targetDir%\wandersick\AeroZoom\AeroZoom.exe
{
If setupAllUsers
{
FileCreateShortcut, %targetDir%\wandersick\AeroZoom\AeroZoom.exe, %A_ProgramsCommon%\AeroZoom.lnk, %targetDir%\wandersick\AeroZoom\,, AeroZoom`, the smooth wheel-zooming and snipping mouse-enhancing panel,,
FileCreateShortcut, %targetDir%\wandersick\AeroZoom\AeroZoom.exe, %A_DesktopCommon%\AeroZoom.lnk, %targetDir%\wandersick\AeroZoom\,, AeroZoom`, the smooth wheel-zooming and snipping mouse-enhancing panel,,
}
Else
{
FileCreateShortcut, %targetDir%\wandersick\AeroZoom\AeroZoom.exe, %A_Programs%\AeroZoom.lnk, %targetDir%\wandersick\AeroZoom\,, AeroZoom`, the smooth wheel-zooming and snipping mouse-enhancing panel,,
FileCreateShortcut, %targetDir%\wandersick\AeroZoom\AeroZoom.exe, %A_Desktop%\AeroZoom.lnk, %targetDir%\wandersick\AeroZoom\,, AeroZoom`, the smooth wheel-zooming and snipping mouse-enhancing panel,,
}
}
; if a shortcut is in startup, re-create it to ensure its not linked to the portable version's path
; ** this method (create shortcut) to run aerozoom at startup is now deprected because the shortcut wont seem to run when uac is on
; ** and it requires elevation unlike the 'create task' method
IfExist, %A_Startup%\*AeroZoom*.*
{
FileSetAttrib, -R, %A_Startup%\*AeroZoom*.*
FileDelete, %A_Startup%\*AeroZoom*.*
;IfExist, %targetDir%\wandersick\AeroZoom\AeroZoom.exe
; FileCreateShortcut, %targetDir%\wandersick\AeroZoom\AeroZoom.exe, %A_Startup%\AeroZoom.lnk, %targetDir%\wandersick\AeroZoom\,, AeroZoom`, the smooth wheel-zooming and snipping mouse-enhancing panel,,
}
if A_IsAdmin
{
IfExist, %A_StartupCommon%\*AeroZoom*.* ; this is unnecessary as AeroZoom wont put shortcuts in all users startup but it will be checked too
{
FileSetAttrib, -R, %A_StartupCommon%\*AeroZoom*.*
FileDelete, %A_StartupCommon%\*AeroZoom*.*
;IfExist, %targetDir%\wandersick\AeroZoom\AeroZoom.exe
; FileCreateShortcut, %targetDir%\wandersick\AeroZoom\AeroZoom.exe, %A_StartupCommon%\AeroZoom.lnk, %targetDir%\wandersick\AeroZoom\,, AeroZoom`, the smooth wheel-zooming and snipping mouse-enhancing panel,,
}
}
if A_IsAdmin
{
RunWait, "%TaskPath%\AeroZoom_Task.bat" /check,"%A_WorkingDir%\",min
if (errorlevel=4) { ; if task exists, recreate it to ensure it links to the correct aerozoom.exe
if setupAllUsers
{
RunWait, "%TaskPath%\AeroZoom_Task.bat" /cretask /programfiles,"%A_WorkingDir%\",min
} else {
RunWait, "%TaskPath%\AeroZoom_Task.bat" /cretask /localappdata,"%A_WorkingDir%\",min
}
if (errorlevel=3) {
RegWrite, REG_SZ, HKCU, Software\wandersick\AeroZoom, RunOnStartup, 1
}
}
}
; Write uninstall entry to registry
RegWrite, REG_SZ, HKEY_CURRENT_USER, %regKey%, DisplayIcon, %targetDir%\wandersick\AeroZoom\AeroZoom.exe,0
RegWrite, REG_SZ, HKEY_CURRENT_USER, %regKey%, DisplayName, AeroZoom %verAZ%
RegWrite, REG_SZ, HKEY_CURRENT_USER, %regKey%, InstallDate, %A_YYYY%%A_MM%%A_DD%
RegWrite, REG_SZ, HKEY_CURRENT_USER, %regKey%, HelpLink, http://tech.wandersick.com
RegWrite, REG_SZ, HKEY_CURRENT_USER, %regKey%, URLInfoAbout, http://tech.wandersick.com
; ******************************************************************************************
; ******************************************************************************************
; ******************************************************************************************
; ******************************************************************************************
If setupAllUsers
RegWrite, REG_SZ, HKEY_CURRENT_USER, %regKey%, UninstallString, %targetDir%\wandersick\AeroZoom\setup.exe /unattendAZ=2 /programfiles
Else
RegWrite, REG_SZ, HKEY_CURRENT_USER, %regKey%, UninstallString, %targetDir%\wandersick\AeroZoom\setup.exe /unattendAZ=2
RegWrite, REG_SZ, HKEY_CURRENT_USER, %regKey%, InstallLocation, %targetDir%\wandersick\AeroZoom
RegWrite, REG_SZ, HKEY_CURRENT_USER, %regKey%, DisplayVersion, %verAZ%
RegWrite, REG_SZ, HKEY_CURRENT_USER, %regKey%, Publisher, a wandersick
; Calc folder size
; SetBatchLines, -1 ; Make the operation run at maximum speed.
EstimatedSize = 0
Loop, %targetDir%\wandersick\AeroZoom\*.*, , 1
EstimatedSize += %A_LoopFileSize%
EstimatedSize /= 1024
RegWrite, REG_DWORD, HKEY_CURRENT_USER, %regKey%, EstimatedSize, %EstimatedSize%
IfExist, %targetDir%\wandersick\AeroZoom\AeroZoom.exe
{
IfEqual, unattendAZ, 1
{
ExitApp, 0
}
Msgbox, 262144, AeroZoom, Successfully installed.`n`nAccess the uninstaller in 'Control Panel\Programs and Features' or run Setup.exe again. ; 262144 = Always on top
} else {
IfEqual, unattendAZ, 1
{
ExitApp, 1
}
Msgbox, 262192, AeroZoom, Installation failed.`n`nPlease ensure this folder is accessible:`n`n%targetDir%\wandersick\AeroZoom
}
} else {
; if unattend switch is on, skip the check since user must be running the uninstaller from control panel
; not from AeroZoom program
IfNotEqual, unattendAZ, 1
{
MsgBox, 262180, AeroZoom Uninstaller , Uninstall AeroZoom and delete its perferences from the following location?`n`n%targetDir%\wandersick\AeroZoom
IfMsgBox No
{
Exitapp
}
}
Gosub, KillProcess
; begin uninstalling
; remove startup shortcuts
IfExist, %A_Startup%\*AeroZoom*.*
{
FileSetAttrib, -R, %A_Startup%\*AeroZoom*.*
FileDelete, %A_Startup%\*AeroZoom*.*
}
if A_IsAdmin ; unnecessary as stated above
{
IfExist, %A_StartupCommon%\*AeroZoom*.*
{
FileSetAttrib, -R, %A_StartupCommon%\*AeroZoom*.*
FileDelete, %A_StartupCommon%\*AeroZoom*.*
}
}
; remove task
if A_IsAdmin
{
RunWait, "%TaskPath%\AeroZoom_Task.bat" /deltask,"%A_WorkingDir%\",min
RunWait, "%TaskPath%\AeroZoom_Task.bat" /check,"%A_WorkingDir%\",min
if (errorlevel=5) {
RegWrite, REG_SZ, HKCU, Software\wandersick\AeroZoom, RunOnStartup, 0
}
}
; remove reg keys
RegDelete, HKEY_CURRENT_USER, %regKey%
RegDelete, HKEY_CURRENT_USER, Software\wandersick\AeroZoom
; RButton
; MButton
; X1
; X2
; Modifier
; Notepad
; ZoomPad
; ZoomIt
; lastPosX
; lastPosY and more
;FileMove, %targetDir%\wandersick\AeroZoom\Data\uninstall.bat, %temp%, 1 ; prevent deletion of this as it will be used
FileSetAttrib, -R, %A_Programs%\AeroZoom.lnk
FileDelete, %A_Programs%\AeroZoom.lnk ; normally this is the only shortcut that has to be deleted
FileSetAttrib, -R, %A_ProgramsCommon%\AeroZoom.lnk
FileDelete, %A_ProgramsCommon%\AeroZoom.lnk
FileSetAttrib, -R, %A_Desktop%\AeroZoom.lnk
FileDelete, %A_Desktop%\AeroZoom.lnk
FileSetAttrib, -R, %A_DesktopCommon%\AeroZoom.lnk
FileDelete, %A_DesktopCommon%\AeroZoom.lnk
FileSetAttrib, -R, %targetDir%\wandersick\AeroZoom\*.*
FileRemoveDir, %targetDir%\wandersick\AeroZoom\Data, 1
FileRemoveDir, %targetDir%\wandersick\AeroZoom, 1
FileCreateDir, %targetDir%\wandersick\AeroZoom\Data
;FileMove, %temp%\uninstall.bat, %targetDir%\wandersick\AeroZoom\Data\, 1 ; prevent deletion of this as it will be used to schedule deletion of this setup.exe with AT
;IfEqual, unattendAZ, 2
; Sleep, 1000
IfNotExist, %targetDir%\wandersick\AeroZoom\AeroZoom.exe ; i.e. if the removal was successful
{
;IfEqual, unattendAZ, 2 ; schedule to delete this setup.exe (and uninstall.bat) in a few mins since it cant delete itself
;{
; if A_IsAdmin
; {
; If setupAllUsers
; Run, "%comspec%" /c uninstall.bat /schedule /programfiles,%targetDir%\wandersick\AeroZoom\Data ; abort if non-admin as at.exe requires admin right
; Else
; Run, "%comspec%" /c uninstall.bat /schedule,%targetDir%\wandersick\AeroZoom\Data ; abort if non-admin as at.exe requires admin right
; }
;}
IfEqual, unattendAZ, 1
{
ExitApp, 0
}
if ExistAZ
{
Msgbox, 262208, AeroZoom, Successfully uninstalled.`n`nPlease exit or restart AeroZoom manually for completion. ; to alert users of weird behaviours if still using AeroZoom
} else {
Msgbox, 262144, AeroZoom, Successfully uninstalled.
}
} else {
IfEqual, unattendAZ, 1
{
ExitApp, 1
}
Msgbox, 262192, AeroZoom, Uninstalled partially.`n`nPlease remove this folder manually:`n`n%targetDir%\wandersick\AeroZoom
}
}
ExitApp
return
KillProcess: ; may not work for RunAsInvoker for Administrators accounts with UAC on. RunAsHighest will solve that, while letting Standard user accounts install to the correct profile.
Process, Close, magnify.exe
Process, Close, zoomit.exe
Process, Close, zoomit64.exe
Process, Close, wget.exe
Process, Close, AeroZoom.exe
Process, Close, AeroZoom_Alt.exe
Process, Close, AeroZoom_Ctrl.exe
Process, Close, AeroZoom_MouseL.exe
Process, Close, AeroZoom_MouseM.exe
Process, Close, AeroZoom_MouseR.exe
Process, Close, AeroZoom_MouseX1.exe
Process, Close, AeroZoom_MouseX2.exe
Process, Close, AeroZoom_Shift.exe
Process, Close, AeroZoom_Win.exe
Process, Close, ZoomPad.exe
return
; ------------------------------------------
; Some unorganized notes for internal use:
;
; ** Compile this with AutoHotKey Basic (as it does not need to query WMI anymore)
; ** RunAsHighest for ONLY this script and AeroZoom ahk. (All mod scripts w/o manifest)
; So this setup.exe uses the current user's profile to install (in case of AsHighest/AsInvoker, not the elevated user's (in case of AsAdmin)
; Running AeroZoom with admin rights is better under win7 (due to OS limitations). So the elevated user might share settings
; with the standard user as both would share the same registry user hive that way. (This problem assumes running from a standard user account,
; for admin accounts with/without UAC on, no problem.)
;
; For unattended install, set unattendAZ=1, see below or setup.exe /?
; (Also, a MSI may be available on the web site above)
; Uninstallation will automatically take place instead if an installed copy is found in %targetDir%
; * No need to compile this with UAC RunAsAdmin manifest or name it setup.exe as the installation does not depend on admin rights *
; * To name it setup.exe yet not get auto elevation in Standard User accounts, try asInvoker/asHighest. The latter elevates in admin
; accounts with UAC on, but the former does not (unless UAC is off, then admin rights always).
; The following switches can be set by either setup.exe /unattendAZ=1 or, in a command prompt, set unattendAZ=1
; /unattendAZ=1 : for unattended installation/uninstallation using setup.exe
; (also used by menu 'Tool > Uninstall AeroZoom from this Computer' although it wont allow uninstallation)
; to suspress all dialogs. no running executables is closed -- so that would fail if its trying to delete itself
; so it doesnt do that. in that case it would prompt user to uninstall in Program and Features (i.e. below, unattendAZ=2)
; =2 : for uninstallation in Program and Features. will present uninstallation dialogs (attended)
; to users when they uninstall using Program and Features.
; cancelled --> the most obvious different from 1 is it includes using AT.exe to schedule deletion of this setup.exe
; also it wont check for working directory
; undefined : for setup.exe to install/uninstall in attended mode. (most usual)
; /programfiles : install into Program Files for all users
; e.g. Setup.exe /unattendAZ=1 /programfiles
; OLD MSI installer making steps: (cancelled as MSI created this way does not work with UAC on)
; 1. Embed these files in a batch file for Batch To Exe Converter 1.5:
; AeroZoom_Task.bat, AeroZoom_Task_Body.xml 7z.exe, 7z.dll, AeroZoom.7z (the whole AeroZoom folder compressed), setup.exe (this ahk file after being compiled.)
; 2. Batch To Exe Converter Settings:
; Invisible application, Temporary directory (Submit current directory), Overwrite existing files
; 3. Batch file content:
; @echo off
; "setup.exe" /unattendAZ=1
; goto :EOF
; 4. AHK content: This file and uncomment the following line in around line 53
; RunWait, 7z.exe -y x AeroZoom.7z -o"%localappdata%\wandersick\",%A_ScriptDir%
; Comment the following line around line 54
; FileCopyDir, %A_WorkingDir%, %localappdata%\wandersick\AeroZoom, 1
; 5. Use Exe To Msi Converter Free (1.0) by QwertyLabs to convert.
; Specify no switch
; Other tools/versions may not work without specific settings
; For v3.1, check 'Do not Register Package (suppress Uninstall)'
; 6. Since v1 displays exe2msi and QwentyLabs as Product Name. Use Orca to correct it.
; When creating an single-file installer, remove the missing component check below
; ---------------------------------------------------------------
; NEW method simply uses AutoHotkey_L built-in FileInstall. Use no batch to exe converter.
; There're 3 setup.exe in total. One contains FileInstall command which extracts the 2nd setup.exe,
; AeroZoom.7z, 7z.exe, etc. then execute the 2nd AZ_setup.exe which extracts the 7z and install the extracted files
; (diff between 2nd and 3rd setup is step 4 above, plus the component check at the top... 2nd doesnt check it)
; The third setup.exe is in extracted folder for uninstallation. It is also for the Portable version
; of AeroZoom, where if users install the program, the subfolder gets copied to the destination
; (since there's no one single 7z archive and 7z.exe).
; The first setup.exe (named setup.exe to get auto-elevated) extracts files to temp folder
; (Before compile, put these in C:\AZ_whatever_temp_folder to include in Setup.exe)
; FileInstall, C:\AZ_whatever_temp_folder\AeroZoom_Task.bat, %A_Temp%, 1
; FileInstall, C:\AZ_whatever_temp_folder\AeroZoom_Task_Body.xml, %A_Temp%, 1
; FileInstall, C:\AZ_whatever_temp_folder\7z.exe, %A_Temp%, 1
; FileInstall, C:\AZ_whatever_temp_folder\7z.dll, %A_Temp%, 1
; FileInstall, C:\AZ_whatever_temp_folder\AeroZoom.7z, %A_Temp%, 1
; Run, "%A_Temp%\Setup_2nd.exe" /unattendAZ=1,%A_ScriptDir%
; Use Intel's tool (based on Wix) to convert exe to msi.