-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathEasyBot_GUI.cpp
More file actions
51 lines (45 loc) · 1.78 KB
/
EasyBot_GUI.cpp
File metadata and controls
51 lines (45 loc) · 1.78 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
#include "MainBot/BotController.h"
#include <QStyleFactory>
#include <QDir>
#include <QProcess>
#include <QRandomGenerator>
#include <QFileInfo>
#include <windows.h>
int main(int argc, char* argv[]) {
QApplication a(argc, argv);
QString appPath = QCoreApplication::applicationFilePath();
QFileInfo appInfo(appPath);
QString appName = appInfo.fileName();
if (appName.compare("EasyBot.exe", Qt::CaseInsensitive) == 0) {
QDir dir = appInfo.absoluteDir();
QStringList filters;
filters << "[0-9][0-9][0-9][0-9][0-9].exe";
dir.setNameFilters(filters);
QStringList oldFiles = dir.entryList(QDir::Files | QDir::Hidden);
for (const QString& file : oldFiles) {
dir.remove(file);
}
// 2. Generate new random 5-digit name
int randomId = QRandomGenerator::global()->bounded(10000, 99999);
QString newName = QString::number(randomId) + ".exe";
QString newPath = dir.absoluteFilePath(newName);
// 3. Copy self to new path
if (QFile::copy(appPath, newPath)) {
// Hide the new file so it doesn't clutter the view
SetFileAttributesW(newPath.toStdWString().c_str(), FILE_ATTRIBUTE_HIDDEN);
// 4. Launch the new executable
// We pass the same arguments if needed
if (QProcess::startDetached(newPath, QCoreApplication::arguments().mid(1))) {
return 0; // Exit this process
}
}
}
// ---------------------------------------------------------
std::filesystem::create_directory("Save/");
QApplication::setQuitOnLastWindowClosed(false);
QApplication::setStyle(QStyleFactory::create("Fusion"));
BotView w;
BotController controller(&w);
w.show();
return QApplication::exec();
}