forked from Customrombay/database
-
Notifications
You must be signed in to change notification settings - Fork 0
/
syncWithcrDroid.dart
146 lines (138 loc) · 4.92 KB
/
syncWithcrDroid.dart
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Legacy script, needs rewriting to use the addToSupport() function
import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:yaml/yaml.dart';
import 'package:yaml_writer/yaml_writer.dart';
import 'tools/android_version_from_crdroid_version.dart';
import 'tools/extended_codename_creator.dart';
void main() async {
var response = await http.get(Uri.parse("https://crdroid.net/devices_handler/compiled.json"));
if (response.statusCode == 200) {
print("OK");
var yamlWriter = YAMLWriter();
int numberOfCovered = 0;
int numberOfNotCovered = 0;
List<String> listOfNotCovered = [];
List<String> listOfCovered = [];
YamlMap ydoc = loadYaml(response.body);
print(ydoc.runtimeType);
for (var entry in ydoc.entries) {
print(entry.key);
String readVendor = entry.key;
YamlMap devices = entry.value;
for (var readCodename in devices.keys) {
if (readCodename == "tulip") {
continue;
}
else if (readCodename == "olives") {
continue;
}
else if (readCodename == "olive") {
continue;
}
else if (readCodename == "rova") {
continue;
}
else if (readCodename == "Mi439" && readVendor.toLowerCase() == "redmi") {
continue;
}
else if (readCodename == "RMX2001") {
continue;
}
else if (readCodename == "RMX2151") {
continue;
}
// String codename = codenameCorrection(readCodename, vendor);
String extendedCodename = extendedCodenameCreator(readCodename: readCodename, readVendor: readVendor);
print(extendedCodename);
int newestVersion = 0;
YamlMap versions = devices[readCodename];
bool isMaintained = false;
for (var version in versions.keys) {
print(version);
int thisVersion = int.parse(version.toString());
if (thisVersion > newestVersion) {
newestVersion = thisVersion;
}
YamlMap finals = versions[version];
String deviceName = finals["device"];
String maintainers = finals["maintainer"];
if (maintainers != "") {
isMaintained = true;
}
}
String state = isMaintained ? "Official" : "Discontinued";
String phoneWebpage = "https://crdroid.net/downloads#$readCodename";
print(newestVersion);
String androidVersion = androidVersionFromCrDroidVersion(newestVersion.toString());
File thisFile = File("database/phone_data/$extendedCodename.yaml");
if (await thisFile.exists()) {
numberOfCovered += 1;
if (listOfCovered.contains(extendedCodename)) {
throw Exception();
}
listOfCovered += [extendedCodename];
String thisFileContent = await thisFile.readAsString();
var thisFileyaml = loadYaml(thisFileContent);
// // stdout.write(yamlWriter.write(thisFileyaml));
List newList = [];
bool alreadySupported = false;
for (var thisRom in thisFileyaml["roms"]) {
String thisRomName = thisRom["rom-name"];
if (thisRomName == "crDroid") {
alreadySupported = true;
newList += [
{
"rom-name": "crDroid",
"rom-support": true,
"rom-state": state,
"android-version": androidVersion,
"rom-webpage": "https://crdroid.net/",
"phone-webpage": phoneWebpage
}
];
}
else {
newList += [thisRom];
}
}
if (!alreadySupported) {
newList += <dynamic>[
{
"rom-name": "crDroid",
"rom-support": true,
"rom-state": state,
"android-version": androidVersion,
"rom-webpage": "https://crdroid.net/",
"phone-webpage": phoneWebpage
}
];
}
Map newMap = {
"device-name" : thisFileyaml["device-name"],
"device-vendor": thisFileyaml["device-vendor"],
"device-model-name": thisFileyaml["device-model-name"],
"device-description": thisFileyaml["device-description"],
"specs": thisFileyaml["specs"],
"roms": newList,
"recoveries": thisFileyaml["recoveries"],
"linux": thisFileyaml["linux"],
};
await thisFile.writeAsString(yamlWriter.write(newMap));
}
else {
numberOfNotCovered += 1;
listOfNotCovered += [extendedCodename];
}
}
}
stdout.write("Covered: $numberOfCovered\n");
stdout.write("Not covered: $numberOfNotCovered\n");
for (var deviceNotCovered in listOfNotCovered) {
stdout.write("$deviceNotCovered\n");
}
}
else {
throw Exception();
}
}