-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathadb_io.cs
89 lines (80 loc) · 3 KB
/
adb_io.cs
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ionic.Zip;
namespace RNDN.CSharpADB {
public class CSharpADB {
//Here are ADB and Fastboot packages paths
public string adbPath;
public string fbPath;
//cmd output
public string LastStdout;
public string LastStderr;
public class InvalidFileException : Exception {
public InvalidFileException() {
}
public InvalidFileException(string message)
: base(message) {
}
public InvalidFileException(string message, Exception inner)
: base(message, inner) {
}
}
public void RunAdb(string args) {
if (adbPath == "") {
throw new InvalidFileException("ADB path is invalid.");
} else {
var processStartInfo = new ProcessStartInfo {
FileName = adbPath,
Arguments = args,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false
};
var process = Process.Start(processStartInfo);
LastStdout = process.StandardOutput.ReadToEnd();
LastStderr = process.StandardError.ReadToEnd();
process.WaitForExit();
}
}
public void RunFastboot(string args) {
if (fbPath == "") {
throw new InvalidFileException("Fastboot path is invalid.");
} else {
var processStartInfo = new ProcessStartInfo {
FileName = fbPath,
Arguments = args,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false
};
var process = Process.Start(processStartInfo);
LastStdout = process.StandardOutput.ReadToEnd();
LastStderr = process.StandardError.ReadToEnd();
process.WaitForExit();
}
}
public void Install(string apkPath, string pid) {
RunAdb("uninstall " + pid);
RunAdb("install \"" + apkPath + "\"");
}
public void DownloadFile(string localPath, string destPath) {
RunAdb("pull " + localPath + " " + destPath);
}
public void DownloadADB()
{
using (var client = new System.Net.WebClient())
{
client.DownloadFile("https://dl.google.com/android/repository/platform-tools-latest-windows.zip", "plat.zip");
using (Ionic.Zip.ZipFile zip = Ionic.Zip.ZipFile.Read("plat.zip"))
{
zip.ExtractAll(System.IO.Path.GetTempPath() + "\\unzipPlat",
Ionic.Zip.ExtractExistingFileAction.DoNotOverwrite);
}
}
}
}
}