Repository navigation
Expand file tree
/
Copy pathPayloadFile.cs
More file actions
58 lines (53 loc) · 2.02 KB
/
Copy pathPayloadFile.cs
File metadata and controls
58 lines (53 loc) · 2.02 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
using System.IO;
namespace FastbootFlasher;
internal static class PayloadFile
{
public static List<ListViewItem> ParsePayloadFile(string filePath)
{
var entries = new List<ListViewItem>();
var partitions = PayloadBin.ParsePayloadBin(filePath);
for (int index = 0; index < partitions.Count; index++)
{
Partition partition = partitions[index];
entries.Add(new ListViewItem
{
Num = index,
Part = partition.Name,
Size = partition.Size,
Addr = string.Empty,
Source = filePath
});
}
return entries;
}
public static async Task ExtractPartition(string filePath, int index)
{
var partitions = PayloadBin.ParsePayloadBin(filePath);
Partition partition = partitions[index];
var progress = new Progress<double>(value => MainWindow.pb.Value = value);
bool success = await PayloadBin.ExtractPartitionImage(partition.Name, filePath, progress);
if (!success) throw new InvalidDataException($"提取 payload 分区 {partition.Name} 失败。");
}
}
internal sealed class MetadataInfo
{
public string ProductName { get; set; } = string.Empty;
public string AndroidVersion { get; set; } = string.Empty;
public string SecurityPatch { get; set; } = string.Empty;
public string VersionName { get; set; } = string.Empty;
public MetadataInfo(string metadataPath)
{
foreach (string line in File.ReadLines(metadataPath))
{
string[] parts = line.Split('=', 2);
if (parts.Length != 2) continue;
switch (parts[0].Trim())
{
case "product_name": ProductName = parts[1].Trim(); break;
case "android_version": AndroidVersion = parts[1].Trim(); break;
case "security_patch": SecurityPatch = parts[1].Trim(); break;
case "version_name": VersionName = parts[1].Trim(); break;
}
}
}
}