[4fc7293] | 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 |
---|
[90d389d] | 8 | ; 1 - Installer failure |
---|
| 9 | ; 2 - Problems running SasView (simple fitting) |
---|
| 10 | ; 3 - Uninstaller failure |
---|
[4fc7293] | 11 | |
---|
| 12 | #include <Constants.au3> |
---|
| 13 | #include <FileConstants.au3> |
---|
| 14 | #include <MsgBoxConstants.au3> |
---|
| 15 | #include <WinAPIFiles.au3> |
---|
| 16 | |
---|
| 17 | ; Modifiable globals |
---|
[90d389d] | 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] |
---|
[2a08cb6] | 22 | EndIf |
---|
| 23 | |
---|
| 24 | Global $fUninstallerLocation = "C:\Program Files (x86)\SasView\unins000.exe" |
---|
[4fc7293] | 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 | ;============================================================== |
---|
[2a08cb6] | 38 | |
---|
[4fc7293] | 39 | Func Install() |
---|
| 40 | ;;;;; APPLICATION INSTALLED ;;;;;;; |
---|
| 41 | Local $sSetupWindow = "Setup - SasView" |
---|
[90d389d] | 42 | Local $iFailFlag = 1 |
---|
[4fc7293] | 43 | ; Run setup |
---|
| 44 | if FileExists($fInstallerLocation) Then |
---|
| 45 | $installerPID = Run($fInstallerLocation) |
---|
[2a08cb6] | 46 | Assert($installerPID, $iFailFlag) |
---|
[4fc7293] | 47 | Sleep(1000) |
---|
| 48 | Else |
---|
| 49 | ;$Error = ObjEvent(AutoIt.Error, "Setup file does not exist","123") |
---|
[2a08cb6] | 50 | Exit($iFailFlag) |
---|
[4fc7293] | 51 | EndIf |
---|
| 52 | |
---|
| 53 | ; License click through |
---|
[90d389d] | 54 | WinActivate($sSetupWindow) |
---|
[4fc7293] | 55 | Local $test = WinWaitActive($sSetupWindow, "License Agreement", $lTimeout) |
---|
| 56 | ;ConsoleWrite("license agreement: " & $test) |
---|
[2a08cb6] | 57 | Assert($test, $iFailFlag) |
---|
[4fc7293] | 58 | sleep(1000) |
---|
| 59 | |
---|
| 60 | Send("{TAB}{up}{ENTER}") |
---|
| 61 | |
---|
| 62 | ; Location |
---|
| 63 | Sleep(1000) |
---|
| 64 | $test = WinWaitActive($sSetupWindow, "Select Destination Location", $lTimeout) |
---|
[2a08cb6] | 65 | Assert($test, $iFailFlag) |
---|
[4fc7293] | 66 | Send("{ENTER}") |
---|
| 67 | |
---|
| 68 | ; Icons, Startup entry |
---|
| 69 | Sleep(1000) |
---|
| 70 | $test = WinWaitActive($sSetupWindow, "Select Additional Tasks", $lTimeout) |
---|
[2a08cb6] | 71 | Assert($test, $iFailFlag) |
---|
[4fc7293] | 72 | Send("{ENTER}") |
---|
| 73 | |
---|
| 74 | ; Ready to install... |
---|
| 75 | Sleep(1000) |
---|
| 76 | $test = WinWaitActive($sSetupWindow, "Ready to Install", $lTimeout) |
---|
[2a08cb6] | 77 | Assert($test, $iFailFlag) |
---|
[4fc7293] | 78 | Send("{ENTER}") |
---|
| 79 | |
---|
| 80 | ; Final OK on running |
---|
| 81 | Sleep(5000) |
---|
| 82 | $test = WinWaitActive($sSetupWindow, "Completing the SasView Setup Wizard", $lInstallTimeout) |
---|
[2a08cb6] | 83 | Assert($test, $iFailFlag) |
---|
[4fc7293] | 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") |
---|
[2a08cb6] | 94 | Local $iFailFlag = 2 |
---|
[4fc7293] | 95 | ; Wait for the window |
---|
| 96 | Sleep(1000) |
---|
| 97 | Local $hWnd = WinWaitActive("SasView - Fitting -", "", $lTimeout) |
---|
[2a08cb6] | 98 | Assert($hWnd, $iFailFlag) |
---|
[4fc7293] | 99 | |
---|
| 100 | ;;;;; Load a File |
---|
| 101 | ; Open File Load dialog |
---|
| 102 | Send("!{f}{ENTER}") |
---|
| 103 | WinWaitActive("Choose a file", "", $lTimeout) |
---|
[2a08cb6] | 104 | Assert($hWnd, $iFailFlag) |
---|
[4fc7293] | 105 | Sleep(200) |
---|
| 106 | |
---|
| 107 | ; Focus is in file chooser - enter filename |
---|
| 108 | Send("C:\Program Files (x86)\SasView\test\1d_data\cyl_400_20.txt") |
---|
| 109 | Sleep(1000) |
---|
| 110 | Send("{ENTER}") |
---|
| 111 | |
---|
| 112 | ;; Send file to fitting |
---|
| 113 | ControlClick($hWnd, "Send To", 231) |
---|
| 114 | |
---|
| 115 | ;; Choose a model |
---|
| 116 | ControlCommand($hWnd, "", "ComboBox3", "SetCurrentSelection", 1) |
---|
| 117 | |
---|
| 118 | ;; Calculate the model |
---|
| 119 | ControlClick($hWnd, "Compute", 211) |
---|
| 120 | |
---|
| 121 | ;; Close SasView |
---|
| 122 | WinClose($hWnd) |
---|
| 123 | |
---|
| 124 | Local $hEnd = WinWaitActive("Confirm Exit", "", $lTimeout) |
---|
[2a08cb6] | 125 | Assert($hEnd, $iFailFlag) |
---|
[4fc7293] | 126 | ControlClick($hEnd, "", "[CLASS:Button; INSTANCE:1]") |
---|
| 127 | |
---|
| 128 | Local $sv_closed = WinWaitClose($hWnd, "", $lTimeout) |
---|
[2a08cb6] | 129 | Assert($sv_closed, $iFailFlag) |
---|
[4fc7293] | 130 | |
---|
| 131 | EndFunc |
---|
| 132 | |
---|
| 133 | Func Uninstall() |
---|
| 134 | ;;;;; UNINSTALL ;;;;;;; |
---|
[2a08cb6] | 135 | Local $iFailFlag = 3 |
---|
| 136 | $installerPID = Run($fUninstallerLocation) |
---|
| 137 | Assert($installerPID, $iFailFlag) |
---|
[4fc7293] | 138 | |
---|
| 139 | Local $sSetupWindow = "SasView Uninstall" |
---|
| 140 | |
---|
| 141 | Local $test = WinWaitActive($sSetupWindow, "", $lTimeout) |
---|
[2a08cb6] | 142 | Assert($test, $iFailFlag) |
---|
[4fc7293] | 143 | Send("{TAB}{ENTER}") |
---|
| 144 | |
---|
| 145 | WinActivate("SasView Uninstal") |
---|
| 146 | $test = WinWaitActive($sSetupWindow, "SasView was successfully removed", $lTimeout) |
---|
[2a08cb6] | 147 | Assert($test, $iFailFlag) |
---|
[4fc7293] | 148 | Send("{ENTER}") |
---|
| 149 | |
---|
| 150 | EndFunc |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | ;;; HELPER FUNCTIONS ;;;; |
---|
| 154 | Func Assert($test, $lExitValue) |
---|
| 155 | ;;; Asserts $test to be non-zero and exit with code $lExitValue ;;; |
---|
| 156 | if $test == 0 Then |
---|
| 157 | ProcessClose($installerPID) |
---|
| 158 | Exit($lExitValue) |
---|
| 159 | EndIf |
---|
| 160 | EndFunc |
---|