]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - LinuxGUI/Ventoy2Disk/QT/main.cpp
1.0.89 release
[Ventoy.git] / LinuxGUI / Ventoy2Disk / QT / main.cpp
1 #include "ventoy2diskwindow.h"
2
3 #include <QApplication>
4 #include <QMessageBox>
5 #include <QFileInfo>
6 #include <QStyle>
7 #include <QDir>
8 #include <QDesktopWidget>
9 #include <QPixmap>
10 #include <unistd.h>
11 #include <sys/types.h>
12
13 extern "C" {
14 #include "ventoy_define.h"
15 #include "ventoy_util.h"
16 #include "ventoy_qt.h"
17 }
18
19 using namespace std;
20
21 char g_log_file[4096];
22 char g_ini_file[4096];
23
24 int main(int argc, char *argv[])
25 {
26 int ret;
27 long long size;
28 QApplication a(argc, argv);
29 Ventoy2DiskWindow w;
30
31 #ifdef QT_CHECK_EUID
32 if (geteuid() != 0)
33 {
34 QMessageBox::critical(NULL, "Error", "Permission denied!\nPlease run with root privileges.");
35 return 1;
36 }
37 #endif
38
39 if (!QFileInfo::exists("./boot/boot.img"))
40 {
41 QString curdir = a.applicationDirPath();
42 int index = curdir.indexOf("/tool/");
43
44 if (index >= 0)
45 {
46 QDir::setCurrent(curdir.left(index));
47 }
48 else
49 {
50 QDir::setCurrent(curdir);
51 }
52 }
53
54 if (!QFileInfo::exists("./boot/boot.img"))
55 {
56 QMessageBox::critical(NULL, "Error", "Please run under the correct directory.");
57 return 1;
58 }
59
60 ventoy_log_init();
61
62 snprintf(g_log_file, sizeof(g_log_file), "./log.txt");
63 snprintf(g_ini_file, sizeof(g_ini_file), "./Ventoy2Disk.ini");
64 for (int i = 0; i < argc; i++)
65 {
66 if (argv[i] && argv[i + 1] && strcmp(argv[i], "-l") == 0)
67 {
68 snprintf(g_log_file, sizeof(g_log_file), "%s", argv[i + 1]);
69 }
70 else if (argv[i] && argv[i + 1] && strcmp(argv[i], "-i") == 0)
71 {
72 snprintf(g_ini_file, sizeof(g_ini_file), "%s", argv[i + 1]);
73 }
74 }
75
76 QFileInfo Info(g_log_file);
77 size = (long long)Info.size();
78 if (size >= 4 * SIZE_1MB)
79 {
80 QFile::remove(g_log_file);
81 }
82
83 vlog("===================================================\n");
84 vlog("===== Ventoy2Disk %s powered by QT %s =====\n", ventoy_get_local_version(), qVersion());
85 vlog("===================================================\n");
86 vlog("log file is <%s> lastsize:%lld\n", g_log_file, (long long)size);
87 vlog("ini file is <%s>\n", g_ini_file);
88
89 ventoy_disk_init();
90 ventoy_http_init();
91
92 w.setGeometry(QStyle::alignedRect(Qt::LeftToRight,
93 Qt::AlignCenter,
94 w.size(),
95 a.desktop()->availableGeometry()));
96
97 QPixmap pix;
98 QIcon icon;
99 int len;
100 const uchar *data;
101
102 data = (const uchar *)get_window_icon_raw_data(&len);
103 pix.loadFromData(data, len);
104 icon.addPixmap(pix);
105 w.setWindowIcon(icon);
106
107 w.show();
108 w.setFixedSize(w.size());
109
110 ret = a.exec();
111
112 ventoy_disk_exit();
113 ventoy_http_exit();
114
115 vlog("######## Ventoy2Disk QT %s exit ########\n", ventoy_get_local_version());
116
117 /* log exit must at the end */
118 ventoy_log_exit();
119
120 return ret;
121 }