My favorites | Sign in
Project Home Wiki Issues Source
Checkout   Browse   Changes    
 
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
;
; AutoHotKey helper functions
;
; Copyright (C) 2009 Austin English
;
; This library is free software; you can redistribute it and/or
; modify it under the terms of the GNU Lesser General Public
; License as published by the Free Software Foundation; either
; version 2.1 of the License, or (at your option) any later version.
;
; This library is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
; Lesser General Public License for more details.
;
; You should have received a copy of the GNU Lesser General Public
; License along with this library; if not, write to the Free Software
; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA

; Should improve clicking reliability
SetControlDelay, -1

; #NoEnv ; Disables environemntal variables unless EnvGet is used. Increases performance.
; Since this file is included everywhere else, it affects all other tests.

; Most of these are archaic and unlikely to be used, e.g., %24% = Apps
; See also http://msdn.microsoft.com/en-us/library/ms933062(WinEmbedded.5).aspx
; If the n/a variables end up being needed, I'll implement later.
;
; Embedded variable - Replacement - Example
; %10 - A_WinDir - C:\Windows
; %11% - B_SystemRoot - C:\Windows\system32
; %12% - n/a - C:\Windows\system32\drivers
; %17% - n/a - C:\Windows\inf
; %18% - n/a - C:\Windows\Help
; %20% - n/a - C:\Windows\Fonts
; %21% - n/a - C:\Windows\system32\viewers
; %23% - n/a - C:\Windows\system32\spool\drivers\color
; %24% - n/a - C:\
; %25% - n/a - C:\Windows
; %30% - n/a - C:\
; %50% - n/a - C:\Windows\system
; %51% - n/a - C:\Windows\system32\spool
; %52% - n/a - C:\Windows\system32\spool\drivers\w32x86
; %53% - n/a - C:\Documents and Settings\username
; %54% - n/a - C:\
; %55% - n/a - C:\Windows\system32\spool\Prtprocs\w32x86
; %16406% - A_StartMenuCommon - C:\Documents and Settings\All Users\Start Menu
; %16407% - A_ProgramsCommon - C:\Documents and Settings\All Users\Start Menu\Programs
; %16408% - A_StartupCommon - C:\Documents and Settings\All Users\Start Menu\Programs\Startup
; %16409% - A_DesktopCommon - C:\Documents and Settings\All Users\Desktop
; %16415% - B_CommonFavs - C:\Documents and Settings\All Users\Favorites
; %16419% - A_AppDataCommon - C:\Documents and Settings\All Users\Application Data
; %16422% - A_ProgramFiles - C:\Program Files
; %16425% - n/a - C:\Windows\system32 (for RISC)
; %16426% - n/a - C:\Program Files (for RISC)
; %16427% - B_CommonFiles - C:\Program Files\Common
; %16428% - n/a - C:\Program Files\Common (for RISC)
; %16429% - B_CommonTemplates - C:\Documents and Settings\All Users\Templates
; %16430% - B_CommonDocs - C:\Documents and Settings\All Users\Documents
; %16437% - B_CommonMusic - C:\Documents and Settings\All Users\Documents\My Music
; %16438% - B_CommonPictures - C:\Documents and Settings\All Users\Documents\My Pictures

; %11%
B_SystemRoot=%A_WinDir%\system32

; %16415%
RegRead, B_CommonFavs, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders, Common Favorites

; %16427%
RegRead, B_CommonFiles, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion, CommonFilesDir

; %16429%
RegRead, B_CommonTemplates, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders, Common Templates

; %16430%
RegRead, B_CommonDocs, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders, Common Documents

; %16437%
RegRead, B_CommonMusic, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders, CommonMusic

; %16438%
RegRead, B_CommonPictures, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders, CommonPictures

; %AllUsersProfile%
EnvGet, B_AllUsersProfile, AllUsersProfile

; %SystemDrive%
EnvGet, B_SystemDrive, SystemDrive

; Even though AutoHotKey comes with a ton of builtin functions, many are omitted
; due to space/speed concerns. Others aren't popular enough.

; Check to see if a directory exists. Useful for making sure installers create empty directories.
CHECK_DIR(directory)
{
global
IfNotExist, %directory%
{
FileAppend, %directory% doesn't exist. Test failed.`n, %OUTPUT%
}
Else
{
FileGetAttrib, Attributes, %directory%
IfInString, Attributes, D
{
FileAppend, %directory% exists and is a directory. Test passed.`n, %OUTPUT%
}
Else
{
FileAppend, %directory% exists`, but isn't a directory. Test failed.`n, %OUTPUT%
}
}
}

; Check to see that a file exists. On success, print nothing. On failure, 'test failed' (non fatal).
; Used in place of SHA1 for things like .log or that otherwise change, but we want to make sure where installed.
CHECK_FILE(filename)
{
global
IfNotExist, %filename%
{
FileAppend, File %filename% does not exist. Test failed.`n, %OUTPUT%
}
}

; Check to see that a file does not exist. On success, print nothing. On failure, 'test failed' (non fatal).
; Used to check that files were deleted, for example in an uninstaller.
CHECK_NOT_FILE(filename)
{
global
IfExist, %filename%
{
FileAppend, File %filename% exists when it should not. Test failed.`n, %OUTPUT%
}
}

; Removes the temporary directory and all files, recursively
CLEANUP()
{
global
FileRemoveDir, %APPINSTALL_TEMP%, 1
}

; Similar to FORCE_CLOSE below, without the forced killing. Just sends the close message.
CLOSE(windowname)
{
global
PostMessage, 0x112, 0xF060,,, %windowname%
}

; This function simplifies file retrieval.
; It tests for the files' existence (skipping the download), downloads it, sha1sum's it,
; and compares it against the known good sha1sum.
;
; Usage: 'DOWNLOAD("url", "filename", "sha1sum")'
; url is the http url of the download,
; filename is the filename you want to save as,
; and sha1sum is the 40 character sha1sum. Double-quotes must be used around all strings.
;
; Supported protocols:
; HTTP, HTTPS, FTP, Gopher
;
; Precautions:
; Function needs sha1sum downloaded into %APPINSTALL% before it could be used
; further...'init_test' does this for you
DOWNLOAD(url, filename, sha1sum)
{
global
local TEMPFILE
local checksum
local sha1sumgood

IfNotExist, %filename%
{
UrlDownloadToFile, %url%, %filename%
If GetLastError
{
FileAppend, Downloading %filename% failed. Error 2. TEST SKIPPED.`n, %OUTPUT%
exit 2
}
Else
{
FileAppend, Downloading %filename% succeded.`n, %OUTPUT%
}
}
Else
{
FileAppend, %filename% already present. Not downloading.`n, %OUTPUT%
}

TEMPFILE=%APPINSTALL_TEMP%\sha1sum.txt
FileDelete, %TEMPFILE%
RunWait, %comspec% /c %APPINSTALL%\sha1sum.exe %filename% >> %TEMPFILE%
FileReadLine, checksum, %TEMPFILE%, 1
FileDelete, %TEMPFILE%

sha1sumgood = %sha1sum% %filename%

If (checksum != sha1sumgood)
{
FileAppend, %filename% checksum failed. Got %checksum%`, expected %sha1sum%. Error 3. TEST SKIPPED.`n, %OUTPUT%
exit 3
}
}

; Check for 'If GetLastError', and if it exists, print a line in the output file,
; remove the temporary directory, then exit with the assigned error code. Otherwise,
; print a message in the log that the test passed.
ERROR_TEST(fail_message, pass_message, errorcode=1)
{
global
If GetLastError
{
FileAppend, %FAIL_MESSAGE% Error %ERRORCODE%. Test failed.`n, %OUTPUT%
FileRemoveDir, %APPINSTALL_TEMP%, 1
exit %errorcode%
}
Else
{
FileAppend, %PASS_MESSAGE% Test passed.`n, %OUTPUT%
}
}

; Force a window to close. AutoHotKey comes with the 'WinClose' function, which sends WM_CLOSE and asks
; the program to close nicely. 'WinKill' is an extended version, which is supposed to send WM_CLOSE, and if it fails,
; terminates the program's process. I found it to be inconsistent, on both Windows and Wine. As a backup, the AHK FAQ
; offers a workaround, which I greatly prefer. For reference, 0x112 = WM_SYSCOMMAND, 0xF060 = SC_CLOSE. This is equivalent
; to clicking on the system menu and choosing 'Close', or roughly equivalent to 'ALT+F4'. It is much more consistent.

FORCE_CLOSE(windowname)
{
global
PostMessage, 0x112, 0xF060,,, %windowname%
; Give the app 5 seconds to close on its own, to prevent race conditions. Thanks to Focht for pointing it out.
Loop, 5
{
IfWinExist, %windowname%
{
Sleep, 1000
}
Else
{
FileAppend, %windowname% exited on its own.`n, %OUTPUT%
break ; The app exited on its own, so break loop.
}
}
IfWinExist, %windowname%
{
FileAppend, %windowname% didn't exit on its own. Terminating with extreme prejudice.`n, %OUTPUT%
WinKill, %windowname%
}
}

; Used to print a message to the result log. Newlines are done automatically by printf.
; Usage printf("This is a line in the debug log.")
PRINTF(string)
{
global
FileAppend, %string%`n, %OUTPUT%
}

; If NOSHA1 is set to non-zero, disable sha1's, instead, just return success.
EnvGet, NOSHA1, NOSHA1

; Sha1sum a file, and compare it to a known good sha1sum. Similar to the download
; function above, but should be used for files not specifically downloaded, e.g.,
; to sha1sum a file from a zip directory after extraction.
; Feed it a filename and sha1sum, it will compare them, print good or bad, and if bad,
; delete the file. Be sure to quote strings!
SHA1(sha1sum, filename)
{
global
if NOSHA1
{
return
}
else
{
TEMPFILE=%APPINSTALL_TEMP%\sha1sum.txt
FileDelete, %TEMPFILE%
RunWait, %comspec% /c %APPINSTALL%\sha1sum.exe "%filename%" >> %TEMPFILE%
FileReadLine, checksum, %TEMPFILE%, 1
FileDelete, %TEMPFILE%
sha1sumgood = %sha1sum% %filename%
If (checksum != sha1sumgood)
{
FileAppend, %filename% checksum failed. Got %checksum%`, expected %sha1sumgood%. Error 3. Test failed.`n, %OUTPUT%
FileDelete, %filename%
FileAppend, SHA1 exits run. TEST ABORTED.`n, %OUTPUT%
exit 3
}
}
}

TEST_COMPLETED()
{
global
FileAppend,TEST COMPLETE.`n, %OUTPUT%
CLEANUP()
exit 0
}

; Print a string at the beginning of a test section which describes the following test.
TESTNAME(string)
{
global
FileAppend,`nTEST SECTION: %string%`n`n, %OUTPUT%
}

; Similar to CHECK_FILE() above, but uses TODO_FIXED/TODO_FAILED. Also, requires a bug number.
; You did file a bug for the incomplete installation, didn't you ;-)?
TODO_CHECK_FILE(filename, bug)
{
global
IfExist, %filename%
{
FileAppend, File %filename% exists. Bug %bug% TODO_FIXED.`n, %OUTPUT%
}
Else
{
FileAppend, File %filename% does not exist. Bug %bug% TODO_FAILED.`n, %OUTPUT%
}
}

; Similar to the SHA1 function above, but for todo's. Takes the 'bad'/expected sha1um,
; as well as the good sha1sum, and the file to test. Sha1sum's the file, and if
; it matches the 'bad'/expected sha1sum, consider it a TODO_FAILED. If it matches
; the good sha1sum, consider it a TODO_FIXED. If it matches neither, consider it
; a test failure and exit.
TODO_SHA1(badsha1, todosha1, filename)
{
global
TEMPFILE=%APPINSTALL_TEMP%\sha1sum.txt
FileDelete, %TEMPFILE%
IfNotExist, %APPINSTALL%\sha1sum.exe
{
FileAppend, Dependency sha1sum.exe not found but needed for download verification. Error 6. Test failed.`n, %OUTPUT%
FileAppend, TODO_SHA1 exits run. TEST ABORTED.`n, %OUTPUT%
exit 6
}
RunWait, %comspec% /c %APPINSTALL%\sha1sum.exe "%filename%" >> %TEMPFILE%
FileReadLine, checksum, %TEMPFILE%, 1
FileDelete, %TEMPFILE%
badsha1sum = %badsha1% %filename%
todosha1sum = %todosha1% %filename%
If (checksum = badsha1sum)
{
FileAppend, %filename% checksum failed. This was expected. TODO_FAILED.`n, %OUTPUT%
}
else if (checksum = todosha1sum)
{
FileAppend, %filename% checksum passed. This was not expected. TODO_FIXED.`n, %OUTPUT%
}
Else
{
FileAppend, %filename% checksum failed. Got %checksum%`, expected %badsha1um% or %todosha1sum%. Error 3. Test failed.`n, %OUTPUT%
FileDelete, %filename%
FileAppend, TODO_SHA1 exits run. TEST ABORTED.`n, %OUTPUT%
exit 3
}
}

; Similar to WINDOW_WAIT below, except, instead of erroring out if the window doesn't appear, consider it a test failure.
; Should be used for windows that appear on Windows, but not on Wine, e.g., the Import Wizard for Mozilla Firefox
TODO_WINDOW_WAIT(windowname, bug, windowtext="", wintimeout=60)
{
global
WinWait, %windowname%, %windowtext%, %wintimeout%
if ErrorLevel
{
FileAppend, %windowname% didn't appear. Bug %bug% TODO_FAILED.`n, %OUTPUT%
}
Else
{
FileAppend, %windowname% appeared. Bug %bug% TODO_FIXED.`n, %OUTPUT%
IfWinNotActive, %windowname%, %windowtext%
{
WinActivate, %windowname%, %windowtext%
}
}
}

; Crash handler for programs that crash on wine (but not windows). Give it the program name (as a string!),
; and the bug number (no quotes needed), and optionally a timeout period to wait (60 second default).
; The function waits (until the timeout) for the gui debugger to pop up. If it does, it clicks 'Ok' and exits
; the test (since the program fatally crashed). If not, it outputs a message to the log files letting you know
; that the bug is likely fixed.
WAIT_CRASH_FATAL(program, bug, timeout=60)
{
global

WinWait, Program Error, The program %program% has encountered a serious problem and needs to close, %timeout%
if ErrorLevel
{
FileAppend, %program% didn't crash. Bug %bug% TODO_FIXED.`n, %OUTPUT%
}
else
{
IfWinNotActive, Program Error, The program %program% has encountered a serious problem and needs to close
{
WinActivate, Program Error, The program %program% has encountered a serious problem and needs to close
}
FileAppend, %program% crashed. Bug %bug% TODO_FAILED.`n, %OUTPUT%
ControlClick, Button1, Program Error
; Test isn't really complete, but it's expected to exit here. So just pretend it's complete.
TEST_COMPLETED()
exit 0
}
}

; Test to see that a window doesn't exist. If it exists, issue a test failed and abort the test. Otherwise, report success.
WIN_EXIST_TEST(windowname, windowtext="")
{
global
IfWinExist, %windowname%, %windowtext%
{
FileAppend, %windowname% didn't exit for some reason. Test failed.`n, %OUTPUT%
}
IfWinNotExist, %windowname%, %windowtext%
{
FileAppend, %windowname% exited successfully. Test passed.`n, %OUTPUT%
}
}

; Some applications don't take focus when started, or have a delay. Work around this.
; Windowname is required, but you can optionally supply a string of text in the window,
; or override the time to wait for the window to show before reporting failure (default, 60s).
WINDOW_WAIT(windowname, windowtext="", wintimeout=60)
{
global
WinWait, %windowname%, %windowtext%, %wintimeout%
if ErrorLevel
{
FileAppend, Launching %windowname%`, %windowtext% failed. Test failed.`n, %OUTPUT%
FileAppend, WINDOW_WAIT exits run. TEST ABORTED.`n, %OUTPUT%
exit 1
}
IfWinNotActive, %windowname%, %windowtext%
{
WinActivate, %windowname%, %windowtext%
}
}

; Similar to WINDOW_WAIT() above, but loops a few times for stubborn installers
; that don't always accept a click like they should (Adobe Photoshop, I'm looking at you!)
; Also requires a button to click, for obvious reasons.
; Wintimeout is the time for the original window to appear. Loops is how many attempts to click.
WINDOW_CLICK_LOOP(windowname, button, windowtext="", loops=10, wintimeout=60)
{
global

WinWait, %windowname%, %windowtext%, %wintimeout%
if ErrorLevel
{
FileAppend, Launching %windowname%`, %windowtext% failed. Test failed.`n, %OUTPUT%
FileAppend, WINDOW_WAIT exits run. TEST ABORTED.`n, %OUTPUT%
exit 1
}
IfWinNotActive, %windowname%, %windowtext%
{
WinActivate, %windowname%, %windowtext%
}

Loop, %loops%
{
IfWinExist, %windowname%, %windowtext%
{
FileAppend, Trying to click '%button%' again...`n, %OUTPUT%
ControlClick, %button%, %windowname%, %windowtext%
}
Else
{
FileAppend, '%button%' finally worked.`n, %OUTPUT%
break
}
sleep 1000
}

}

Change log

r1042 by austinenglish on Mar 27, 2010   Diff
appinstall: kick up default timeout for
window helper functions, slow applications
don't like it.
Go to: 
Project members, sign in to write a code review

Older revisions

r881 by austinenglish on Dec 13, 2009   Diff
winetricks: add directx-beta verb
(winver=XP, not 2k). Fixes winezeug
71.
r705 by austinenglish on Oct 2, 2009   Diff
appinstall: AHK now supports ftp and
gopher, so wget isn't needed. Also,
skip tests if download fails
r670 by austinenglish on Sep 8, 2009   Diff
appinstall: make SetControlDelay, -1
the default
All revisions of this file

File info

Size: 17314 bytes, 480 lines
Powered by Google Project Hosting