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