PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 6ms RepoModel.GetById 34ms 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
 5"Android Screenshot Library -- initializing..." | Out-Host
 6
 7try
 8{
 9	# Check whether ANDROID environmental variable is set

10	if ([String]::IsNullOrEmpty($Env:ANDROID))	{
11		"*** Android SDK not found. ***" | Out-Host
12		"Make sure ANDROID variable is pointing to Android SDK root directory." | Out-Host
13	}
14	else
15	{
16		$adb = [IO.Path]::Combine([IO.Path]::Combine($Env:ANDROID, "platform-tools"), "adb.exe")
17		
18		# Check whether device is connected and wait for one

19		$adbState = (& $adb get-state)
20		if ($adbState -ne "device") {
21			"Device not found -- connect one to continue..." | Out-Host
22			& $adb wait-for-device
23			"Device connected." | Out-Host
24		}
25		
26		# Install service

27		"Installing native service..." | Out-Host
28		& $adb push ./asl-native /data/local/asl-native
29		& $adb shell /system/bin/chmod 0777 /data/local/asl-native
30		
31		# If the service is already running, kill it

32		$ps = (& $adb shell ps) | Where-Object { $_.Contains("asl-native") }
33		if (-not [String]::IsNullOrEmpty($ps)) {
34			"Service already running -- do you want to restart it?" | Out-Host
35			$answer = Read-Host -Prompt "(Y)es/(N)o"
36			if ($answer.ToLower()[0] -ne 'y')	{ return }
37			
38			# Get PID of the service's process

39			"Terminating service..." | Out-Host
40			for ($i = 0; $i -lt $ps.Length; ++$i)
41			{
42				$psLine = $ps[$i].ToString().Split(" ", [StringSplitOptions]::RemoveEmptyEntries)
43				& $adb shell kill -9 $psLine[1]
44			}
45			"Service terminated." | Out-Host
46		}
47		
48		# Start the service

49		"Starting service..." | Out-Host
50		cmd /c start /B  $adb shell "/data/local/asl-native /data/local/asl-native.log"
51		"Service started successfully." | Out-Host
52	}
53}
54catch [Exception]
55{
56	"*** An error has occured ***" | Out-Host
57	$_ | Out-Host
58}