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 | ; Modifiable globals |
---|
18 | Global $fInstallerLocation = @TempDir & "\setupSasView.exe" |
---|
19 | if $CmdLine[0] > 0 Then |
---|
20 | ; If argument present - use it as local download path |
---|
21 | $fInstallerLocation = $CmdLine[1] |
---|
22 | EndIf |
---|
23 | |
---|
24 | Global $fUninstallerLocation = "C:\Program Files (x86)\SasView\unins000.exe" |
---|
25 | Global $lTimeout = 10 ; 10 sec timeout for waiting on windows |
---|
26 | Global $lInstallTimeout = 120 ; 2 min timeout for the installation process |
---|
27 | |
---|
28 | ; General globals |
---|
29 | Global $installerPID = 0 |
---|
30 | |
---|
31 | ;; MAIN SCRIPT |
---|
32 | Install() |
---|
33 | RunSasView() |
---|
34 | Uninstall() |
---|
35 | Exit(0) |
---|
36 | |
---|
37 | ;============================================================== |
---|
38 | |
---|
39 | Func Install() |
---|
40 | ;;;;; APPLICATION INSTALLED ;;;;;;; |
---|
41 | Local $sSetupWindow = "Setup - SasView" |
---|
42 | Local $iFailFlag = 1 |
---|
43 | ; Run setup |
---|
44 | if FileExists($fInstallerLocation) Then |
---|
45 | $installerPID = Run($fInstallerLocation) |
---|
46 | Assert($installerPID, $iFailFlag) |
---|
47 | Sleep(1000) |
---|
48 | Else |
---|
49 | ;$Error = ObjEvent(AutoIt.Error, "Setup file does not exist","123") |
---|
50 | Exit($iFailFlag) |
---|
51 | EndIf |
---|
52 | |
---|
53 | ; License click through |
---|
54 | WinActivate($sSetupWindow) |
---|
55 | Local $test = WinWaitActive($sSetupWindow, "License Agreement", $lTimeout) |
---|
56 | ;ConsoleWrite("license agreement: " & $test) |
---|
57 | Assert($test, $iFailFlag) |
---|
58 | sleep(1000) |
---|
59 | |
---|
60 | Send("{TAB}{up}{ENTER}") |
---|
61 | |
---|
62 | ; Location |
---|
63 | Sleep(1000) |
---|
64 | $test = WinWaitActive($sSetupWindow, "Select Destination Location", $lTimeout) |
---|
65 | Assert($test, $iFailFlag) |
---|
66 | Send("{ENTER}") |
---|
67 | |
---|
68 | ; Icons, Startup entry |
---|
69 | Sleep(1000) |
---|
70 | $test = WinWaitActive($sSetupWindow, "Select Additional Tasks", $lTimeout) |
---|
71 | Assert($test, $iFailFlag) |
---|
72 | Send("{ENTER}") |
---|
73 | |
---|
74 | ; Ready to install... |
---|
75 | Sleep(1000) |
---|
76 | $test = WinWaitActive($sSetupWindow, "Ready to Install", $lTimeout) |
---|
77 | Assert($test, $iFailFlag) |
---|
78 | Send("{ENTER}") |
---|
79 | |
---|
80 | ; Final OK on running |
---|
81 | Sleep(5000) |
---|
82 | $test = WinWaitActive($sSetupWindow, "Completing the SasView Setup Wizard", $lInstallTimeout) |
---|
83 | Assert($test, $iFailFlag) |
---|
84 | Send("{ENTER}") |
---|
85 | ;ConsoleWrite("Installed" & @CRLF) |
---|
86 | |
---|
87 | EndFunc |
---|
88 | |
---|
89 | |
---|
90 | Func RunSasView() |
---|
91 | ;;;;; APPLICATION STARTED ;;;;;;; |
---|
92 | ; Start app - DEBUG ONLY |
---|
93 | ;;Run("C:\Program Files (x86)\SasView\SasView.exe") |
---|
94 | Run("C:\util\SasView\SasView.exe") |
---|
95 | local $sActiveWindow = "SasView - Fitting -" |
---|
96 | Local $iFailFlag = 2 |
---|
97 | ; Wait for the window |
---|
98 | Sleep(1000) |
---|
99 | Local $hWnd = WinWaitActive($sActiveWindow, "", $lTimeout) |
---|
100 | Assert($hWnd, $iFailFlag) |
---|
101 | |
---|
102 | ;;;;; Load a File |
---|
103 | ; Open File Load dialog |
---|
104 | Send("!{f}{ENTER}") |
---|
105 | WinWaitActive("Choose a file", "", $lTimeout) |
---|
106 | Assert($hWnd, $iFailFlag) |
---|
107 | Sleep(200) |
---|
108 | |
---|
109 | ; Focus is in file chooser - enter filename |
---|
110 | Send("C:\Program Files (x86)\SasView\test\1d_data\cyl_400_20.txt") |
---|
111 | Sleep(1000) |
---|
112 | Send("{ENTER}") |
---|
113 | |
---|
114 | ;; Send file to fitting |
---|
115 | ControlClick($hWnd, "Send To", 231) |
---|
116 | |
---|
117 | ;; Choose a python model |
---|
118 | ControlCommand($hWnd, "", "ComboBox3", "SetCurrentSelection", 1) |
---|
119 | ;; Calculate the model |
---|
120 | ControlClick($hWnd, "Compute", 211) |
---|
121 | ;; Assure we got the charts |
---|
122 | Local $hPlot = WinWait($sActiveWindow, "Graph2", $lTimeout) |
---|
123 | Assert($hPlot, $iFailFlag) |
---|
124 | $hPlot = WinWait($sActiveWindow, "Graph3", $lTimeout) |
---|
125 | Assert($hPlot, $iFailFlag) |
---|
126 | |
---|
127 | sleep(1000) |
---|
128 | ;; Calculate a compiled model |
---|
129 | ControlClick($hWnd, "Send To", 231) |
---|
130 | |
---|
131 | ;; Choose Shapes/Cylinder |
---|
132 | ControlCommand($hWnd, "", "ComboBox2", "SetCurrentSelection", 1) |
---|
133 | ControlCommand($hWnd, "", "ComboBox3", "SetCurrentSelection", 11) |
---|
134 | ;; Calculate the model |
---|
135 | ControlClick($hWnd, "Compute", 211) |
---|
136 | |
---|
137 | ;; Assure we got another chart |
---|
138 | $hPlot = WinWait($sActiveWindow, "Graph4", $lTimeout) |
---|
139 | Assert($hPlot, $iFailFlag) |
---|
140 | |
---|
141 | ;; Close SasView |
---|
142 | WinClose($hWnd) |
---|
143 | |
---|
144 | Local $hEnd = WinWaitActive("Confirm Exit", "", $lTimeout) |
---|
145 | Assert($hEnd, $iFailFlag) |
---|
146 | ControlClick($hEnd, "", "[CLASS:Button; INSTANCE:1]") |
---|
147 | |
---|
148 | Local $sv_closed = WinWaitClose($hWnd, "", $lTimeout) |
---|
149 | Assert($sv_closed, $iFailFlag) |
---|
150 | |
---|
151 | EndFunc |
---|
152 | |
---|
153 | Func Uninstall() |
---|
154 | ;;;;; UNINSTALL ;;;;;;; |
---|
155 | Local $iFailFlag = 3 |
---|
156 | $installerPID = Run($fUninstallerLocation) |
---|
157 | Assert($installerPID, $iFailFlag) |
---|
158 | |
---|
159 | Local $sSetupWindow = "SasView Uninstall" |
---|
160 | |
---|
161 | Local $test = WinWaitActive($sSetupWindow, "", $lTimeout) |
---|
162 | Assert($test, $iFailFlag) |
---|
163 | Send("{TAB}{ENTER}") |
---|
164 | |
---|
165 | WinActivate("SasView Uninstal") |
---|
166 | $test = WinWaitActive($sSetupWindow, "SasView was successfully removed", $lTimeout) |
---|
167 | Assert($test, $iFailFlag) |
---|
168 | Send("{ENTER}") |
---|
169 | |
---|
170 | EndFunc |
---|
171 | |
---|
172 | |
---|
173 | ;;; HELPER FUNCTIONS ;;;; |
---|
174 | Func Assert($test, $lExitValue) |
---|
175 | ;;; Asserts $test to be non-zero and exit with code $lExitValue ;;; |
---|
176 | if $test == 0 Then |
---|
177 | ProcessClose($installerPID) |
---|
178 | Exit($lExitValue) |
---|
179 | EndIf |
---|
180 | EndFunc |
---|