|
| 1 | +Clear-Host |
| 2 | + |
| 3 | +Write-Host "" |
| 4 | +Write-Host "Instructions:`n" |
| 5 | +Get-Content -Path "src\instructions.txt" |
| 6 | +Write-Host "" |
| 7 | + |
| 8 | +$paired = $false |
| 9 | +$connected = $false |
| 10 | + |
| 11 | +$response = Read-Host "Is the device already paired? (Y/N)" |
| 12 | +$response = $response.ToLower() |
| 13 | +if ($response -ne 'y') { |
| 14 | + # Pair device |
| 15 | + $host_ip = Read-Host "Device IP address" |
| 16 | + $pairing_port = Read-Host "Wireless pairing port" |
| 17 | + $pairing_code = Read-Host "Pairing code" |
| 18 | + |
| 19 | + Write-Host "Pairing device..." |
| 20 | + $pairOutput = & .\tools\adb pair "$host_ip`:$pairing_port" $pairing_code 2>&1 |
| 21 | + if ($pairOutput -imatch "Successfully paired") { |
| 22 | + Write-Host "" |
| 23 | + Write-Host "Pairing successful." |
| 24 | + Write-Host "" |
| 25 | + $paired = $true |
| 26 | + } else { |
| 27 | + Write-Host "" |
| 28 | + Write-Host "Pairing failed - please check the IP, port, and pairing code." |
| 29 | + Write-Host "" |
| 30 | + Pause |
| 31 | + exit |
| 32 | + } |
| 33 | +} else { |
| 34 | + $host_ip = Read-Host "Device host address" |
| 35 | +} |
| 36 | + |
| 37 | +# Connect to device |
| 38 | +$debug_port = Read-Host "Wireless debugging port" |
| 39 | +$s = "$host_ip`:$debug_port" |
| 40 | + |
| 41 | +Write-Host "Connecting to device..." |
| 42 | +$connectOutput = & .\tools\adb connect $s 2>&1 |
| 43 | +if ($connectOutput -imatch "connected to") { |
| 44 | + Write-Host "" |
| 45 | + Write-Host "Connected successfully." |
| 46 | + Write-Host "" |
| 47 | + $connected = $true |
| 48 | +} else { |
| 49 | + Write-Host "" |
| 50 | + Write-Host "Failed to connect to the device at $s" |
| 51 | + Write-Host "Please check the IP, port, and whether the device is online and authorized." |
| 52 | + Write-Host "" |
| 53 | + Pause |
| 54 | + exit |
| 55 | +} |
| 56 | + |
| 57 | +# Install APK |
| 58 | +Write-Host "`Installing the app..." |
| 59 | +$installOutput = & .\tools\adb -s $s install -r "apk\ims.apk" 2>&1 |
| 60 | +$installSucceeded = $false |
| 61 | +$updateIncompatible = $false |
| 62 | + |
| 63 | +foreach ($line in $installOutput) { |
| 64 | + if ($line -imatch "Success") { |
| 65 | + $installSucceeded = $true |
| 66 | + } |
| 67 | + if ($line -imatch "INSTALL_FAILED_UPDATE_INCOMPATIBLE") { |
| 68 | + $updateIncompatible = $true |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +if (-not $installSucceeded) { |
| 73 | + if ($updateIncompatible) { |
| 74 | + & .\tools\adb -s $s uninstall com.imsproject.watch | Out-Null |
| 75 | + $reinstallOutput = & .\tools\adb -s $s install "apk\ims.apk" 2>&1 |
| 76 | + |
| 77 | + $installSucceeded = $reinstallOutput -imatch "Success" |
| 78 | + if (-not $installSucceeded) { |
| 79 | + Write-Host "App install failed. Output:" |
| 80 | + $reinstallOutput | ForEach-Object { Write-Host $_ } |
| 81 | + Pause |
| 82 | + exit |
| 83 | + } |
| 84 | + } else { |
| 85 | + Write-Host "App install failed. Output:" |
| 86 | + $installOutput | ForEach-Object { Write-Host $_ } |
| 87 | + Pause |
| 88 | + exit |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +Write-Host "`nApp installed successfully." |
| 93 | +Write-Host "" |
| 94 | +Pause |
0 commit comments