forked from zsh2401/AutumnBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicBooter.cs
122 lines (114 loc) · 3.6 KB
/
BasicBooter.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#nullable enable
using AutumnBox.Basic.ManagedAdb.CommandDriven;
using System;
using System.IO;
using System.Net;
namespace AutumnBox.Basic
{
/// <summary>
/// AutumnBox.Basic启动器
/// </summary>
public static class BasicBooter
{
/// <summary>
/// 获取一个已缓存的命令进程管理器
/// </summary>
/// <exception cref="InvalidOperationException">ADB管理器未加载</exception>
public static ICommandProcedureManager CommandProcedureManager
{
get
{
if (_adbManager == null)
{
throw new InvalidOperationException("Please load adb manager first!");
}
_cachedCpm ??= _adbManager.OpenCommandProcedureManager();
_cachedCpm.Disposed += (s, e) =>
{
_cachedCpm = null;
};
return _cachedCpm;
}
}
/// <summary>
/// 无需多言
/// </summary>
private static ICommandProcedureManager? _cachedCpm = null;
/// <summary>
/// 获取服务器终端点
/// </summary>
/// <exception cref="InvalidOperationException">操作无效</exception>
/// <exception cref="ObjectDisposedException">对象已经被释放</exception>
public static IPEndPoint ServerEndPoint
{
get
{
if (_adbManager == null) throw new InvalidOperationException("Please load adb manager first");
return _adbManager.ServerEndPoint;
}
}
/// <summary>
/// ADB可执行程序的位置
/// </summary>
/// <exception cref="InvalidOperationException">操作无效</exception>
public static FileInfo AdbExecutableFile
{
get
{
if (_adbManager == null)
{
throw new InvalidOperationException("Please load adb manager first!");
}
return _adbManager.AdbExecutableFile;
}
}
/// <summary>
/// Fastboot可执行程序的位置
/// </summary>
/// <exception cref="InvalidOperationException">操作无效</exception>
public static FileInfo FastbootExecutableFile
{
get
{
if (_adbManager == null)
{
throw new InvalidOperationException("Please load adb manager first!");
}
return _adbManager.FastbootExecutableFile;
}
}
/// <summary>
/// Fastboot可执行程序的位置
/// </summary>
public static DirectoryInfo AdbClientDirectory
{
get
{
if (_adbManager == null)
{
throw new InvalidOperationException("Please load adb manager first");
}
return _adbManager.AdbClientDirectory;
}
}
/// <summary>
/// 内部存储的adb管理器
/// </summary>
private static IAdbManager? _adbManager;
/// <summary>
/// 加载ADB管理器
/// </summary>
/// <typeparam name="TAdbManager"></typeparam>
public static void Use<TAdbManager>() where TAdbManager : IAdbManager, new()
{
_adbManager = new TAdbManager();
}
/// <summary>
/// 释放资源
/// </summary>
public static void Free()
{
_adbManager?.Dispose();
}
}
}