-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
248 lines (235 loc) · 9.82 KB
/
main.cpp
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#include <dialog/Splash.h>
#include <QApplication>
#include <QtUiTools/QUiLoader>
#include <QFile>
#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <QTimer>
#include <QDebug>
#include <QProgressBar>
#include "get/get_device.h"
#include "get/get_codename.h"
#include "dialog/devNotes.h"
#include "QMessageBox"
#include "functions/system.h"
#include <string>
#include "functions/getFiles.h"
#include "functions/parseDevices.h"
#include <iostream>
#include "functions/parseRedirects.h"
#include "functions/getFriendly.h"
#include <QStringList>
#include "functions/argumentParser.hpp"
#include "functions/log/loggingSystem.hpp"
#include "functions/DataShop/DataShop.hpp"
#include "dialog/OptionsDialog.hpp"
#include "dialog/download.hpp"
#include "functions/jsonparse.h"
#include "nlohmann/json.hpp"
#include "functions/GetSF.h"
#include "functions/interface/RecoveryInterface.hpp"
#include <QTimer>
void onExit() {
System syst;
QStringList ar1;
ar1 << "-rf" << "cache";
syst.runCmd("rm", ar1);
Logger log;
log.logMessage(INFO, "Exiting...");
exit(0);
}
int onInstall() {
Store store;
Logger log;
GetSF get;
QThread thread;
OptionsDialog odg;
QTimer *timer = new QTimer();
QString dig = DevNotes::showDialog();
RI rc;
if (dig == "Yes") {
odg.show_dialog();
store.save("main.oninstall", "true");
store.save("status.text", "dr");
std::string codename = store.get("main.codename");
JsonParse json_io("cache/" + odg.collect().toStdString() + ".json");
std::string result = json_io.find("download");
log.logMessage(DEBUG, "Download link: " + result);
QString urlString = QString::fromStdString(result);
QString outputFilePath = "cache/droidx_" + QString::fromStdString(codename) + "_" + odg.collect() + ".zip";
store.save("install.cleanname", "droidx_" + codename + "_" + odg.collect().toStdString() + ".zip");
store.save("install.filename", outputFilePath.toStdString());
get.moveToThread(&thread);
QObject::connect(&thread, &QThread::started, [&get, &urlString, &outputFilePath]() {
get.download(urlString.toStdString(), outputFilePath.toStdString());
});
QObject::connect(&get, &GetSF::downloadComplete, [&store, &rc, &timer, &log](){
store.save("status.text", "fos");
QObject::connect(timer, &QTimer::timeout, [&store, &rc]() {
rc.sideload(store.get("install.filename"), store.get("install.cleanname"));
rc.format_data();
});
log.logMessage(INFO, "Waiting for device '80-state'");
QMessageBox::warning(nullptr, "Warning", "Your device is commanded to reboot in recovery, installer will continue after 80 seconds\nPlease unlock your device if you have any types of screen locks.");
timer->start(80000);
log.logMessage(INFO, "Finished.");
store.save("status.text", "finished");
});
QObject::connect(&get, &GetSF::downloadFailed, [&store]() {
store.save("status.text", "df");
return 1;
});
thread.start();
thread.wait();
} else {
}
}
void errorUnofficial() {
QMessageBox::critical(nullptr, "Error", "Your device isnt connected or its not officially supported.\nPlease restart the program if your phone was disconnected.");
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Logger log;
log.logMessage(INFO, "Initializing...");
// Parse arguments
ArgumentParser args(app);
args.parseArgs();
// Load the UI file
QUiLoader loader;
QFile file(":/assets/UserInterface/main.ui");
file.open(QFile::ReadOnly);
SplashScreen splsh;
// Create the main window from the UI file
QWidget *mainWindow = loader.load(&file);
file.close();
bool isDisconnected = false;
GetDevice device;
System sys;
GetFile down;
Store store;
std::string installation_file;
GetFriendly getFriendly;
QLabel *deviceLabel = mainWindow->findChild<QLabel*>("device");
QProgressBar *pbar = mainWindow->findChild<QProgressBar*>("pbar");
QPushButton *install = mainWindow->findChild<QPushButton*>("install");
QPushButton *Pro = mainWindow->findChild<QPushButton*>("offline");
if (args.isDeveloperMode()) {
Pro->setEnabled(true);
} else {
Pro->setEnabled(false);
}
QString productName;
pbar->setValue(0);
// Connect the deviceConnected signal to a slot
QObject::connect(&device, &GetDevice::deviceConnected, [deviceLabel, &isDisconnected, &pbar, &getFriendly, &productName, &sys, &install](bool connected) {
if (connected) {
if (deviceLabel) {
QStringList ar2;
Store store;
ar2 << "getvar" << "product";
QString out = sys.runCmd("fastboot", ar2);
productName = getFriendly.extractProductName(out);
if (store.get("status.text") == "dr") {
deviceLabel->setText("Downloading the Operating System...");
install->setEnabled(false);
pbar->setValue(25);
} else if (store.get("status.text") == "cf") {
deviceLabel->setText("Flashing the Operating System...");
install->setEnabled(false);
pbar->setValue(55);
} else if (store.get("status.text") == "df") {
deviceLabel->setText("Download failed.");
install->setEnabled(true);
pbar->setValue(100);
} else if (store.get("status.text") == "finished") {
deviceLabel->setText("Finished.");
install->setEnabled(true);
pbar->setValue(100);
} else {
deviceLabel->setText("Device connected, codename: " + productName);
isDisconnected = true;
pbar->setValue(7);
}
}
} else {
Store store;
if (deviceLabel) {
if (isDisconnected) {
if (store.get("main.oninstall") == "true") {
deviceLabel->setText("Device is rebooted to recovery...");
pbar->setValue(16);
} else {
deviceLabel->setText("Device is disconnected or rebooted, or you have a bad cable. Please restart the installer");
pbar->setValue(0);
}
} else {
deviceLabel->setText("No device in fastboot mode found. Connect your phone then restart the installer.");
}
}
}
});
//QString state = splsh.showSplash();
//if (state != "Everything is fine you can continue") {
// QMessageBox::critical(nullptr, "Error", "Critical Error Happened, report this to our team.\nCode: ED_nGROK");
// QStringList ar1;
// ar1 << "-rf" << "cache";
// sys.runCmd("rm", ar1);
// exit(0);
//} else {
// qDebug() << "Fuck man, How the fuck this survived";
//}
QPushButton *exit = mainWindow->findChild<QPushButton*>("exit");
QObject::connect(exit, &QPushButton::clicked, onExit);
QStringList ar3;
ar3 << "getvar" << "product";
QString out = sys.runCmd("fastboot", ar3);
log.logMessage(DEBUG, "fastboot getvar profucked output: " + out.toStdString());
productName = getFriendly.extractProductName(out);
QStringList ar4;
ar4 << "cache";
sys.runCmd("mkdir", ar4);
QStringList ar5;
ar5 << "cache/global_caches.txt";
sys.runCmd("touch", ar5);
log.logMessage(INFO, "Downloading device json file.");
down.downloadFile("https://raw.githubusercontent.com/DroidX-UI-Devices/vendor_droidxOTA/14/devices.json", "cache/devices.json");
log.logMessage(INFO, "Done.");
ParseDevices parser("cache/devices.json");
bool official = parser.find(productName);
//std::cout << "Codename: " << productName << endl;
if (official) {
QObject::connect(install, &QPushButton::clicked, onInstall);
log.logMessage(INFO, "Downloading device developer notes file");
down.downloadFile("https://raw.githubusercontent.com/DroidX-UI-Devices/vendor_droidxOTA/14/changelogs/" + productName + ".txt", "cache/devnotes.txt");
store.save("main.codename", productName.toStdString());
log.logMessage(INFO, "Done.");
} else {
ParseRedirects parser_off;
std::string redirectCodename = parser_off.findRedirect(productName.toStdString());
bool official_check = parser.find(QString::fromStdString(redirectCodename));
//std::cout << "Hello, World!" << redirectCodename << std::endl; Debug
if (official_check) {
QObject::connect(install, &QPushButton::clicked, onInstall);
log.logMessage(INFO, "Downloading device developer notes file");
down.downloadFile(QString::fromStdString("https://raw.githubusercontent.com/DroidX-UI-Devices/vendor_droidxOTA/14/changelogs/") + QString::fromStdString(redirectCodename) + ".txt", "cache/devnotes.txt");
store.save("main.codename", redirectCodename);
log.logMessage(INFO, "Done.");
} else {
QObject::connect(install, &QPushButton::clicked, errorUnofficial);
}
}
log.logMessage(INFO, "All of downloads are done.");
// Use a timer to periodically check the device status
log.logMessage(INFO, "Start the device checking loop");
QTimer *timer = new QTimer();
QObject::connect(timer, &QTimer::timeout, [&device]() {
device.startDetection();
});
timer->start(1000); // Check every 1 second
// Show the main window
log.logMessage(INFO, "Initializing done, opening the user interface.");
mainWindow->show();
return app.exec();
}