[6bb4edd] | 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 |
---|
[1cecc91] | 8 | ; 1 - Download failure |
---|
| 9 | ; 2 - Installer failure |
---|
| 10 | ; 3 - Problems running SasView (simple fitting) |
---|
| 11 | ; 4 - Uninstaller failure |
---|
[6bb4edd] | 12 | |
---|
| 13 | #include <Constants.au3> |
---|
| 14 | #include <FileConstants.au3> |
---|
| 15 | #include <MsgBoxConstants.au3> |
---|
[1cecc91] | 16 | #include <InetConstants.au3> |
---|
[6bb4edd] | 17 | #include <WinAPIFiles.au3> |
---|
| 18 | |
---|
| 19 | ; Custom error handler |
---|
| 20 | ;Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") |
---|
| 21 | |
---|
| 22 | ; Modifiable globals |
---|
[1cecc91] | 23 | if $CmdLine[0] == 0 Then |
---|
| 24 | ; Expected command line with the build number as argument |
---|
| 25 | Exit (-1) |
---|
| 26 | EndIf |
---|
| 27 | |
---|
| 28 | Local $lBuildNumber = $CmdLine[1] |
---|
| 29 | ;Global $fInstallerLocation = "C:\util\setupSasView.exe" ; debug and testing location |
---|
| 30 | Global $fInstallerLocation = @TempDir & "\setupSasView.exe" |
---|
| 31 | Global $fRemoteInstallerLocation = "https://jenkins.esss.dk/sasview/job/SasView_Win7_Test/" & $lBuildNumber & "/artifact/sasview/dist/setupSasView.exe" |
---|
| 32 | Global $fUninstallerLocation = "C:\Program Files (x86)\SasView\unins000.exe" |
---|
[6bb4edd] | 33 | Global $lTimeout = 10 ; 10 sec timeout for waiting on windows |
---|
| 34 | Global $lInstallTimeout = 120 ; 2 min timeout for the installation process |
---|
| 35 | |
---|
| 36 | ; General globals |
---|
| 37 | Global $installerPID = 0 |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | ;; MAIN SCRIPT |
---|
[1cecc91] | 41 | Download() |
---|
[6bb4edd] | 42 | Install() |
---|
| 43 | RunSasView() |
---|
| 44 | Uninstall() |
---|
[1cecc91] | 45 | |
---|
[6bb4edd] | 46 | Exit(0) |
---|
| 47 | |
---|
| 48 | ;============================================================== |
---|
[1cecc91] | 49 | Func Download() |
---|
| 50 | ; Download the file in the background with the selected option of 'force a reload from the remote site.' |
---|
| 51 | ConsoleWrite("Downloading...." & @CRLF) |
---|
| 52 | Local $iFailFlag = 1 |
---|
| 53 | Local $hDownload = InetGet($fRemoteInstallerLocation, $fInstallerLocation, $INET_FORCERELOAD) |
---|
| 54 | |
---|
| 55 | ; Close the handle returned by InetGet. |
---|
| 56 | InetClose($hDownload) |
---|
| 57 | Assert($hDownload, $iFailFlag) |
---|
| 58 | ConsoleWrite("Installer downloaded successfully to " & $fInstallerLocation & @CRLF) |
---|
| 59 | |
---|
| 60 | EndFunc |
---|
| 61 | |
---|
[6bb4edd] | 62 | Func Install() |
---|
| 63 | ;;;;; APPLICATION INSTALLED ;;;;;;; |
---|
| 64 | Local $sSetupWindow = "Setup - SasView" |
---|
[1cecc91] | 65 | Local $iFailFlag = 2 |
---|
[6bb4edd] | 66 | ; Run setup |
---|
| 67 | if FileExists($fInstallerLocation) Then |
---|
| 68 | $installerPID = Run($fInstallerLocation) |
---|
[1cecc91] | 69 | Assert($installerPID, $iFailFlag) |
---|
[6bb4edd] | 70 | Sleep(1000) |
---|
| 71 | Else |
---|
| 72 | ;$Error = ObjEvent(AutoIt.Error, "Setup file does not exist","123") |
---|
[1cecc91] | 73 | Exit($iFailFlag) |
---|
[6bb4edd] | 74 | EndIf |
---|
| 75 | |
---|
| 76 | ; License click through |
---|
[1cecc91] | 77 | WinActivate($sSetupWindow) ; <-- REQUIRED when connecting from another host |
---|
[6bb4edd] | 78 | Local $test = WinWaitActive($sSetupWindow, "License Agreement", $lTimeout) |
---|
| 79 | ;ConsoleWrite("license agreement: " & $test) |
---|
[1cecc91] | 80 | Assert($test, $iFailFlag) |
---|
[6bb4edd] | 81 | sleep(1000) |
---|
| 82 | |
---|
| 83 | Send("{TAB}{up}{ENTER}") |
---|
| 84 | |
---|
| 85 | ; Location |
---|
| 86 | Sleep(1000) |
---|
| 87 | $test = WinWaitActive($sSetupWindow, "Select Destination Location", $lTimeout) |
---|
[1cecc91] | 88 | Assert($test, $iFailFlag) |
---|
[6bb4edd] | 89 | Send("{ENTER}") |
---|
| 90 | |
---|
| 91 | ; Icons, Startup entry |
---|
| 92 | Sleep(1000) |
---|
| 93 | $test = WinWaitActive($sSetupWindow, "Select Additional Tasks", $lTimeout) |
---|
[1cecc91] | 94 | Assert($test, $iFailFlag) |
---|
[6bb4edd] | 95 | Send("{ENTER}") |
---|
| 96 | |
---|
| 97 | ; Ready to install... |
---|
| 98 | Sleep(1000) |
---|
| 99 | $test = WinWaitActive($sSetupWindow, "Ready to Install", $lTimeout) |
---|
[1cecc91] | 100 | Assert($test, $iFailFlag) |
---|
[6bb4edd] | 101 | Send("{ENTER}") |
---|
| 102 | |
---|
| 103 | ; Final OK on running |
---|
| 104 | Sleep(5000) |
---|
| 105 | $test = WinWaitActive($sSetupWindow, "Completing the SasView Setup Wizard", $lInstallTimeout) |
---|
[1cecc91] | 106 | Assert($test, $iFailFlag) |
---|
[6bb4edd] | 107 | Send("{ENTER}") |
---|
| 108 | ;ConsoleWrite("Installed" & @CRLF) |
---|
| 109 | |
---|
| 110 | EndFunc |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | Func RunSasView() |
---|
| 114 | ;;;;; APPLICATION STARTED ;;;;;;; |
---|
| 115 | ; Start app - DEBUG ONLY |
---|
| 116 | ;;Run("C:\Program Files (x86)\SasView\SasView.exe") |
---|
[1cecc91] | 117 | Local $iFailFlag = 2 |
---|
[6bb4edd] | 118 | ; Wait for the window |
---|
| 119 | Sleep(1000) |
---|
| 120 | Local $hWnd = WinWaitActive("SasView - Fitting -", "", $lTimeout) |
---|
[1cecc91] | 121 | Assert($hWnd, $iFailFlag) |
---|
[6bb4edd] | 122 | |
---|
| 123 | ;;;;; Load a File |
---|
| 124 | ; Open File Load dialog |
---|
| 125 | Send("!{f}{ENTER}") |
---|
| 126 | WinWaitActive("Choose a file", "", $lTimeout) |
---|
[1cecc91] | 127 | Assert($hWnd, $iFailFlag) |
---|
[6bb4edd] | 128 | Sleep(200) |
---|
| 129 | |
---|
| 130 | ; Focus is in file chooser - enter filename |
---|
| 131 | Send("C:\Program Files (x86)\SasView\test\1d_data\cyl_400_20.txt") |
---|
| 132 | Sleep(1000) |
---|
| 133 | Send("{ENTER}") |
---|
| 134 | |
---|
| 135 | ;; Send file to fitting |
---|
| 136 | ControlClick($hWnd, "Send To", 231) |
---|
| 137 | |
---|
| 138 | ;; Choose a model |
---|
| 139 | ControlCommand($hWnd, "", "ComboBox3", "SetCurrentSelection", 1) |
---|
| 140 | |
---|
| 141 | ;; Calculate the model |
---|
| 142 | ControlClick($hWnd, "Compute", 211) |
---|
| 143 | |
---|
| 144 | ;; Close SasView |
---|
| 145 | WinClose($hWnd) |
---|
| 146 | |
---|
| 147 | Local $hEnd = WinWaitActive("Confirm Exit", "", $lTimeout) |
---|
[1cecc91] | 148 | Assert($hEnd, $iFailFlag) |
---|
[6bb4edd] | 149 | ControlClick($hEnd, "", "[CLASS:Button; INSTANCE:1]") |
---|
| 150 | |
---|
| 151 | Local $sv_closed = WinWaitClose($hWnd, "", $lTimeout) |
---|
[1cecc91] | 152 | Assert($sv_closed, $iFailFlag) |
---|
[6bb4edd] | 153 | |
---|
| 154 | EndFunc |
---|
| 155 | |
---|
| 156 | Func Uninstall() |
---|
| 157 | ;;;;; UNINSTALL ;;;;;;; |
---|
[1cecc91] | 158 | Local $iFailFlag = 3 |
---|
| 159 | $installerPID = Run($fUninstallerLocation) |
---|
| 160 | Assert($installerPID, $iFailFlag) |
---|
[6bb4edd] | 161 | |
---|
| 162 | Local $sSetupWindow = "SasView Uninstall" |
---|
| 163 | |
---|
| 164 | Local $test = WinWaitActive($sSetupWindow, "", $lTimeout) |
---|
[1cecc91] | 165 | Assert($test, $iFailFlag) |
---|
[6bb4edd] | 166 | Send("{TAB}{ENTER}") |
---|
| 167 | |
---|
| 168 | WinActivate("SasView Uninstal") |
---|
| 169 | $test = WinWaitActive($sSetupWindow, "SasView was successfully removed", $lTimeout) |
---|
[1cecc91] | 170 | Assert($test, $iFailFlag) |
---|
[6bb4edd] | 171 | Send("{ENTER}") |
---|
| 172 | |
---|
| 173 | EndFunc |
---|
| 174 | |
---|
| 175 | |
---|
| 176 | ;;; HELPER FUNCTIONS ;;;; |
---|
| 177 | Func Assert($test, $lExitValue) |
---|
| 178 | ;;; Asserts $test to be non-zero and exit with code $lExitValue ;;; |
---|
| 179 | if $test == 0 Then |
---|
| 180 | ProcessClose($installerPID) |
---|
| 181 | Exit($lExitValue) |
---|
| 182 | EndIf |
---|
| 183 | EndFunc |
---|