PageRenderTime 14ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/desktop/run.ps1

https://code.google.com/p/android-screenshot-library/
Powershell | 58 lines | 42 code | 7 blank | 9 comment | 8 complexity | 48882a945be13c7ab5da1fdcf4ddbcc7 MD5 | raw file
  1. ### Android Screenshot Library ###
  2. ##################################
  3. ### Startup script ###
  4. "Android Screenshot Library -- initializing..." | Out-Host
  5. try
  6. {
  7. # Check whether ANDROID environmental variable is set
  8. if ([String]::IsNullOrEmpty($Env:ANDROID)) {
  9. "*** Android SDK not found. ***" | Out-Host
  10. "Make sure ANDROID variable is pointing to Android SDK root directory." | Out-Host
  11. }
  12. else
  13. {
  14. $adb = [IO.Path]::Combine([IO.Path]::Combine($Env:ANDROID, "platform-tools"), "adb.exe")
  15. # Check whether device is connected and wait for one
  16. $adbState = (& $adb get-state)
  17. if ($adbState -ne "device") {
  18. "Device not found -- connect one to continue..." | Out-Host
  19. & $adb wait-for-device
  20. "Device connected." | Out-Host
  21. }
  22. # Install service
  23. "Installing native service..." | Out-Host
  24. & $adb push ./asl-native /data/local/asl-native
  25. & $adb shell /system/bin/chmod 0777 /data/local/asl-native
  26. # If the service is already running, kill it
  27. $ps = (& $adb shell ps) | Where-Object { $_.Contains("asl-native") }
  28. if (-not [String]::IsNullOrEmpty($ps)) {
  29. "Service already running -- do you want to restart it?" | Out-Host
  30. $answer = Read-Host -Prompt "(Y)es/(N)o"
  31. if ($answer.ToLower()[0] -ne 'y') { return }
  32. # Get PID of the service's process
  33. "Terminating service..." | Out-Host
  34. for ($i = 0; $i -lt $ps.Length; ++$i)
  35. {
  36. $psLine = $ps[$i].ToString().Split(" ", [StringSplitOptions]::RemoveEmptyEntries)
  37. & $adb shell kill -9 $psLine[1]
  38. }
  39. "Service terminated." | Out-Host
  40. }
  41. # Start the service
  42. "Starting service..." | Out-Host
  43. cmd /c start /B $adb shell "/data/local/asl-native /data/local/asl-native.log"
  44. "Service started successfully." | Out-Host
  45. }
  46. }
  47. catch [Exception]
  48. {
  49. "*** An error has occured ***" | Out-Host
  50. $_ | Out-Host
  51. }