-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadb.vb
111 lines (93 loc) · 3.37 KB
/
adb.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
Imports System.IO
Public Delegate Sub dlgAddCmd(m As String)
Public Delegate Sub dlgAddLog(m As String)
Public Class adb
Private Const cmdPush As String = "push ""{0}"" {1} "
Private Const cmdChmod As String = "shell chmod {0} {1}/{2}"
Private Const cmdInstall As String = "install {0}""{1}"""
Private PS As New Process
Private addCmd As dlgAddCmd
Private addLog As dlgAddLog
Public Sub New(addc As dlgAddCmd, addl As dlgAddLog)
addCmd = addc
addLog = addl
End Sub
Public Sub Start()
PS = New Process
Using PS
addCmd("adb.exe start-server")
With PS
.StartInfo.UseShellExecute = False
.StartInfo.RedirectStandardInput = False
.StartInfo.RedirectStandardOutput = True
.StartInfo.RedirectStandardError = True
.StartInfo.CreateNoWindow = True
.StartInfo.FileName = "adb.exe"
.StartInfo.Arguments = "start-server"
.Start()
For i As Integer = 1 To 2
addLog(.StandardOutput.ReadLine)
Next i
.Close()
.Dispose()
End With
End Using
End Sub
Private Function PSStart(cmd As String) As Integer
Dim ext As Integer = 0
With PS
.StartInfo.Arguments = cmd
.Start()
addCmd(cmd)
addLog(.StandardError.ReadToEnd)
addLog(.StandardOutput.ReadToEnd)
.WaitForExit()
ext = .ExitCode
.Close()
End With
Return ext
End Function
Public Sub Push(files() As String, ppath As String, Optional chmod As String = "")
PS = New Process
Using PS
With PS
.StartInfo.UseShellExecute = False
.StartInfo.RedirectStandardInput = True
.StartInfo.RedirectStandardOutput = True
.StartInfo.RedirectStandardError = True
.StartInfo.CreateNoWindow = True
.StartInfo.FileName = "adb"
For i As Integer = 0 To files.Length - 1
If PSStart(String.Format(cmdPush, files(i), ppath)) = 0 And chmod.Length > 0 Then
PSStart(String.Format(cmdChmod, chmod, ppath, Path.GetFileName(files(i))))
End If
Next i
.Dispose()
End With
End Using
End Sub
Public Sub Install(files() As String, m As String)
PS = New Process
Using PS
With PS
.StartInfo.UseShellExecute = False
.StartInfo.RedirectStandardInput = True
.StartInfo.RedirectStandardOutput = True
.StartInfo.RedirectStandardError = True
.StartInfo.CreateNoWindow = True
.StartInfo.FileName = "adb"
For i As Integer = 0 To files.Length - 1
PSStart(String.Format(cmdInstall, m, files(i)))
Next i
.Dispose()
End With
End Using
End Sub
Public Function SerchProcess() As Boolean
Dim ps As System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("adb")
If ps.Count > 0 Then
Return True
End If
Return False
End Function
End Class