-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathDAW.Adb.Parser.pas
More file actions
96 lines (84 loc) · 2.33 KB
/
DAW.Adb.Parser.pas
File metadata and controls
96 lines (84 loc) · 2.33 KB
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
unit DAW.Adb.Parser;
interface
uses
DAW.Model.Device.New;
type
TdawAdbParser = class
private
function parseDeviceName(const ALine: string): string;
public
function parseGetDevicesOutput(const AAdbDevicesOutput: string)
: TArray<TdawDevice>;
function parseGetDeviceIp(const AIpInfo: string): string;
function parseAdbServiceTcpPort(getPropOutput: string): string;
end;
implementation
uses
DAW.Tools,
System.SysUtils,
System.Generics.Collections;
{ TdawAdbParser }
function TdawAdbParser.parseAdbServiceTcpPort(getPropOutput: string): string;
begin
raise Exception.Create(getPropOutput);
end;
function TdawAdbParser.parseDeviceName(const ALine: string): string;
const
MODEL_INDICATOR = 'model:';
DEVICE_INDICATOR = 'device:';
var
LData: TArray<string>;
begin
LData := TDawTools.GetInTag(ALine, MODEL_INDICATOR, DEVICE_INDICATOR);
if Length(LData) > 0 then
Result := LData[0];
end;
function TdawAdbParser.parseGetDeviceIp(const AIpInfo: string): string;
const
START_DEVICE_IP_INDICATOR = 'inet ';
END_DEVICE_IP_INDICATOR = '/';
var
LData: TArray<string>;
begin
LData := TDawTools.GetInTag(AIpInfo, START_DEVICE_IP_INDICATOR,
END_DEVICE_IP_INDICATOR);
if Length(LData) > 0 then
Result := LData[0];
end;
function TdawAdbParser.parseGetDevicesOutput(const AAdbDevicesOutput: string)
: TArray<TdawDevice>;
var
LDevices: TList<TdawDevice>;
splittedOutput: TArray<string>;
i: integer;
line: string;
deviceLine: TArray<string>;
id: string;
name: string;
Device: TdawDevice;
begin
// 'List of devices attached'#$D#$A'0123456789ABCDEF device product:havoc_santoni model:Redmi_4X device:santoni transport_id:1'#$D#$A#$D#$A
Result := nil;
if AAdbDevicesOutput.contains('daemon') then
Exit(nil);
splittedOutput := AAdbDevicesOutput.Split([#$D#$A],
TStringSplitOptions.ExcludeEmpty);
if Length(splittedOutput) <= 1 then
Exit(nil);
LDevices := TList<TdawDevice>.Create();
try
for i := 1 to High(splittedOutput) do
begin
line := splittedOutput[i];
deviceLine := line.Split([' '], TStringSplitOptions.ExcludeEmpty);
id := deviceLine[0].Split([':'])[0];
name := parseDeviceName(line);
Device := TdawDevice.Create(name, id);
LDevices.add(Device);
end;
Result := LDevices.ToArray;
finally
LDevices.Free;
end;
end;
end.