1 | ; ****** REMEMBER TO SWITCH OFF UAC ON TARGET MACHINE!!! ********* |
---|
2 | ; |
---|
3 | ; This script will install, run and uninstall SasView |
---|
4 | ; given location of the installer. The exit code of the script |
---|
5 | ; points at failure location: |
---|
6 | ; |
---|
7 | ; 0 - OK |
---|
8 | ; 1 - Installer failure |
---|
9 | ; 2 - Problems running SasView (simple fitting) |
---|
10 | ; 3 - Uninstaller failure |
---|
11 | |
---|
12 | #include <Constants.au3> |
---|
13 | #include <FileConstants.au3> |
---|
14 | #include <MsgBoxConstants.au3> |
---|
15 | #include <WinAPIFiles.au3> |
---|
16 | |
---|
17 | ; Custom error handler |
---|
18 | ;Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") |
---|
19 | |
---|
20 | ; Modifiable globals |
---|
21 | Global $fInstallerLocation = "C:\util\setupSasView.exe" |
---|
22 | Global $lTimeout = 10 ; 10 sec timeout for waiting on windows |
---|
23 | Global $lInstallTimeout = 120 ; 2 min timeout for the installation process |
---|
24 | |
---|
25 | ; General globals |
---|
26 | Global $installerPID = 0 |
---|
27 | |
---|
28 | |
---|
29 | ;; MAIN SCRIPT |
---|
30 | Install() |
---|
31 | RunSasView() |
---|
32 | Uninstall() |
---|
33 | Exit(0) |
---|
34 | |
---|
35 | ;============================================================== |
---|
36 | Func Install() |
---|
37 | ;;;;; APPLICATION INSTALLED ;;;;;;; |
---|
38 | Local $sSetupWindow = "Setup - SasView" |
---|
39 | |
---|
40 | ; Run setup |
---|
41 | if FileExists($fInstallerLocation) Then |
---|
42 | $installerPID = Run($fInstallerLocation) |
---|
43 | Assert($installerPID, 1) |
---|
44 | Sleep(1000) |
---|
45 | Else |
---|
46 | ;$Error = ObjEvent(AutoIt.Error, "Setup file does not exist","123") |
---|
47 | Exit(1) |
---|
48 | EndIf |
---|
49 | |
---|
50 | ; License click through |
---|
51 | Local $test = WinWaitActive($sSetupWindow, "License Agreement", $lTimeout) |
---|
52 | ;ConsoleWrite("license agreement: " & $test) |
---|
53 | Assert($test, 1) |
---|
54 | sleep(1000) |
---|
55 | |
---|
56 | Send("{TAB}{up}{ENTER}") |
---|
57 | |
---|
58 | ; Location |
---|
59 | Sleep(1000) |
---|
60 | $test = WinWaitActive($sSetupWindow, "Select Destination Location", $lTimeout) |
---|
61 | Assert($test, 1) |
---|
62 | Send("{ENTER}") |
---|
63 | |
---|
64 | ; Icons, Startup entry |
---|
65 | Sleep(1000) |
---|
66 | $test = WinWaitActive($sSetupWindow, "Select Additional Tasks", $lTimeout) |
---|
67 | Assert($test, 1) |
---|
68 | Send("{ENTER}") |
---|
69 | |
---|
70 | ; Ready to install... |
---|
71 | Sleep(1000) |
---|
72 | $test = WinWaitActive($sSetupWindow, "Ready to Install", $lTimeout) |
---|
73 | Assert($test, 1) |
---|
74 | Send("{ENTER}") |
---|
75 | |
---|
76 | ; Final OK on running |
---|
77 | Sleep(5000) |
---|
78 | $test = WinWaitActive($sSetupWindow, "Completing the SasView Setup Wizard", $lInstallTimeout) |
---|
79 | Assert($test, 1) |
---|
80 | Send("{ENTER}") |
---|
81 | ;ConsoleWrite("Installed" & @CRLF) |
---|
82 | |
---|
83 | EndFunc |
---|
84 | |
---|
85 | |
---|
86 | Func RunSasView() |
---|
87 | ;;;;; APPLICATION STARTED ;;;;;;; |
---|
88 | ; Start app - DEBUG ONLY |
---|
89 | ;;Run("C:\Program Files (x86)\SasView\SasView.exe") |
---|
90 | |
---|
91 | ; Wait for the window |
---|
92 | Sleep(1000) |
---|
93 | Local $hWnd = WinWaitActive("SasView - Fitting -", "", $lTimeout) |
---|
94 | Assert($hWnd, 2) |
---|
95 | |
---|
96 | ;;;;; Load a File |
---|
97 | ; Open File Load dialog |
---|
98 | Send("!{f}{ENTER}") |
---|
99 | WinWaitActive("Choose a file", "", $lTimeout) |
---|
100 | Assert($hWnd, 2) |
---|
101 | Sleep(200) |
---|
102 | |
---|
103 | ; Focus is in file chooser - enter filename |
---|
104 | Send("C:\Program Files (x86)\SasView\test\1d_data\cyl_400_20.txt") |
---|
105 | Sleep(1000) |
---|
106 | Send("{ENTER}") |
---|
107 | |
---|
108 | ;; Send file to fitting |
---|
109 | ControlClick($hWnd, "Send To", 231) |
---|
110 | |
---|
111 | ;; Choose a model |
---|
112 | ControlCommand($hWnd, "", "ComboBox3", "SetCurrentSelection", 1) |
---|
113 | |
---|
114 | ;; Calculate the model |
---|
115 | ControlClick($hWnd, "Compute", 211) |
---|
116 | |
---|
117 | ;; Close SasView |
---|
118 | WinClose($hWnd) |
---|
119 | |
---|
120 | Local $hEnd = WinWaitActive("Confirm Exit", "", $lTimeout) |
---|
121 | Assert($hEnd, 2) |
---|
122 | ControlClick($hEnd, "", "[CLASS:Button; INSTANCE:1]") |
---|
123 | |
---|
124 | Local $sv_closed = WinWaitClose($hWnd, "", $lTimeout) |
---|
125 | Assert($sv_closed, 2) |
---|
126 | |
---|
127 | EndFunc |
---|
128 | |
---|
129 | Func Uninstall() |
---|
130 | ;;;;; UNINSTALL ;;;;;;; |
---|
131 | $installerPID = Run("C:\Program Files (x86)\SasView\unins000.exe") |
---|
132 | |
---|
133 | Local $sSetupWindow = "SasView Uninstall" |
---|
134 | |
---|
135 | Local $test = WinWaitActive($sSetupWindow, "", $lTimeout) |
---|
136 | Assert($test, 3) |
---|
137 | Send("{TAB}{ENTER}") |
---|
138 | |
---|
139 | WinActivate("SasView Uninstal") |
---|
140 | $test = WinWaitActive($sSetupWindow, "SasView was successfully removed", $lTimeout) |
---|
141 | Assert($test, 3) |
---|
142 | Send("{ENTER}") |
---|
143 | |
---|
144 | EndFunc |
---|
145 | |
---|
146 | |
---|
147 | ;;; HELPER FUNCTIONS ;;;; |
---|
148 | Func Assert($test, $lExitValue) |
---|
149 | ;;; Asserts $test to be non-zero and exit with code $lExitValue ;;; |
---|
150 | if $test == 0 Then |
---|
151 | ProcessClose($installerPID) |
---|
152 | Exit($lExitValue) |
---|
153 | EndIf |
---|
154 | EndFunc |
---|