Ticket #1447: Bad.au3

File Bad.au3, 4.6 KB (added by disaak, 14 years ago)

AutoIt script

Line 
1#Include <File.au3>
2AdlibRegister( "Unexpected" )
3$mytop = @DesktopHeight - 50 - 60
4$myleft = (@DesktopWidth / 2) - 150
5
6SplashTextOn ( "Mercury MasterLink Automatic Installation", "Please do not touch the mouse or keyboard until the installation is complete.", 400, 60 ,  $myleft, $mytop, -1, "", 10 )
7
8global $OUTPUT
9global $logfullpath
10
11
12$OUTPUT = 0
13
14if $CmdLine[0] >= 1 then
15        $OUTPUT = 1
16
17        $logfullpath = $CmdLine[1]
18       
19        $array = StringSplit($CmdLine[1], "\\")
20        $logname = $array[$array[0]]
21        $logpath = stringleft($logfullpath, stringlen($logfullpath) - stringlen($logname) - 1)
22       
23        ; if ($logpath = "") then only a log name was supplied not the log path
24        if ($logpath = "") or (fileexists($logpath)) then
25                fileopen($logfullpath, 2)
26                fileclose($logfullpath)
27        else
28                msgbox(1,"","Log path not found")
29                exit(2)
30        endif
31endif
32
33if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Running MtrLnk32.Exe")
34run("MtrLnk32.Exe")
35
36
37; if I remove this
38if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for License Agreement window")
39WaitForWindow("License Agreement", "")
40send("{ENTER}")
41; add
42        ; if winexists("License Agreement", "") then
43        ;       winactivate("License Agreement", "")
44        ;       send("{ENTER}")
45        ; EndIf
46; to the Unexpected() function, the windows is found and dealt with but
47; then it times out on the next window.
48
49
50
51if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for Welcome window")
52WaitForWindow("MasterLink32", "This installation program will install")
53send("!n")
54
55if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for Registration window")
56WaitForWindow("MasterLink32", "Please enter the name and company")
57send("...")
58send("{TAB}")
59send("...")
60Send("{TAB}")
61Send("ML459")
62send("!n")
63
64if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for Registration Confirmation window")
65WaitForWindow("MasterLink32", "Please verify")
66send("!n")
67
68if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for Select Destination window")
69WaitForWindow("MasterLink32", "Select Destination")
70send("!r")
71
72if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for Enter Destination window")
73WaitForWindow("Select Destination", "")
74send("C:\Programs\Mercury32")
75send("{ENTER}")
76
77sleep(5000)
78send("!n")
79
80sleep(10000)
81if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for Database window")
82WaitForWindow("MasterLink32", "unable to locate a database")
83send("!r")
84
85if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for Enter Destination window")
86WaitForWindow("Select Destination", "")
87send("C:\Programs\Mercury32\Data")
88send("{ENTER}")
89
90sleep(5000)
91controlcommand("MasterLink32", "unable to locate a database", "[CLASS:Button; INSTANCE:6]", "Check", "")
92send("!n")
93
94if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for Select ProgMan window")
95WaitForWindow("MasterLink32", "Select ProgMan")
96send("!n")
97
98if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for Ready to Install window")
99WaitForWindow("MasterLink32", "Ready to Install")
100send("!n")
101
102if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for Installation Completed window")
103WaitForWindow("MasterLink32", "Installation Completed")
104send("!f")
105
106WinActivate("", "AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Mercury32")
107WinClose("Mercury32", "AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Mercury32")
108
109WinActivate("", "AppData\Roaming\Microsoft\Windows\Start Menu\Programs")
110WinClose("Mercury32", "AppData\Roaming\Microsoft\Windows\Start Menu\Programs")
111
112unexpected()
113
114if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Installation Complete. Return code = 0")
115Exit(0)
116
117Func unexpected()
118
119if winexists("Install", "already exists") then
120        winactivate("Install", "already exists")
121        send("{ENTER}")
122EndIf
123
124if winexists("MasterLink32", "Setup found a Mercury32 database") then
125        winactivate("MasterLink32", "Setup found a Mercury32 database")
126        send("!n")
127endif
128
129EndFunc
130
131
132Func Assert($n)
133        If $n = 0 Then
134                if $OUTPUT = 1 then
135                        _FileWriteLog($logfullpath, "Window not found")
136                        _FileWriteLog($logfullpath, "Found window: (" & WinGetTitle("[ACTIVE]", "") & ")")
137                        _FileWriteLog($logfullpath, "Window text:" & WinGetText("[ACTIVE]", ""))
138                        _FileWriteLog($logfullpath, "Installation failed. Return code = 1")
139                endif
140                Exit(1)
141        endif
142EndFunc
143
144; Wait for a window to exist, activate it, and wait for it to become active.
145; If timeout expires while waiting, exit with a nonzero exit status.
146Func WaitForWindow($title, $text="", $timeout=60)
147    Assert(WinWait($title, $text, $timeout))
148    WinActivate($title, $text)
149EndFunc
150