]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - LinuxGUI/Ventoy2Disk/main_gtk.c
11 #include <sys/types.h>
12 #include <linux/limits.h>
13 #include <ventoy_define.h>
14 #include <ventoy_util.h>
15 #include "ventoy_gtk.h"
17 char g_log_file
[PATH_MAX
];
18 char g_ini_file
[PATH_MAX
];
20 static int set_image_from_pixbuf(GtkBuilder
*pBuilder
, const char *id
, const void *pData
, int len
)
22 GtkImage
*pImage
= NULL
;
23 GdkPixbuf
*pPixbuf
= NULL
;
24 GInputStream
*pStream
= NULL
;
26 pImage
= (GtkImage
*)gtk_builder_get_object(pBuilder
, id
);
27 pStream
= g_memory_input_stream_new_from_data(pData
, len
, NULL
);
28 pPixbuf
= gdk_pixbuf_new_from_stream(pStream
, NULL
, NULL
);
29 gtk_image_set_from_pixbuf(pImage
, pPixbuf
);
34 static int set_window_icon_from_pixbuf(GtkWindow
*window
, const void *pData
, int len
)
36 GdkPixbuf
*pPixbuf
= NULL
;
37 GInputStream
*pStream
= NULL
;
39 pStream
= g_memory_input_stream_new_from_data(pData
, len
, NULL
);
40 pPixbuf
= gdk_pixbuf_new_from_stream(pStream
, NULL
, NULL
);
42 gtk_window_set_icon(window
, pPixbuf
);
46 int early_msgbox(GtkMessageType type
, GtkButtonsType buttons
, const char *str
)
49 GtkWidget
*pMsgBox
= NULL
;
51 pMsgBox
= gtk_message_dialog_new(NULL
, GTK_DIALOG_MODAL
, type
, buttons
, str
);
53 ret
= gtk_dialog_run(GTK_DIALOG(pMsgBox
));
54 gtk_widget_destroy(pMsgBox
);
59 int main(int argc
, char *argv
[])
63 const void *pData
= NULL
;
64 GtkWidget
*pWidget
= NULL
;
65 GtkBuilder
*pBuilder
= NULL
;
68 gtk_init(&argc
, &argv
);
72 early_msgbox(GTK_MESSAGE_ERROR
, GTK_BUTTONS_CLOSE
,
73 "Ventoy2Disk permission denied!\r\nPlease run with root privileges.");
77 if (access("./boot/boot.img", F_OK
) == -1)
79 early_msgbox(GTK_MESSAGE_ERROR
, GTK_BUTTONS_CLOSE
, "Please run under the correct directory.");
83 snprintf(g_log_file
, sizeof(g_log_file
), "log.txt");
84 snprintf(g_ini_file
, sizeof(g_ini_file
), "./Ventoy2Disk.ini");
85 for (i
= 0; i
< argc
; i
++)
87 if (argv
[i
] && argv
[i
+ 1] && strcmp(argv
[i
], "-l") == 0)
89 snprintf(g_log_file
, sizeof(g_log_file
), "%s", argv
[i
+ 1]);
91 else if (argv
[i
] && argv
[i
+ 1] && strcmp(argv
[i
], "-i") == 0)
93 snprintf(g_ini_file
, sizeof(g_ini_file
), "%s", argv
[i
+ 1]);
99 vlog("================================================\n");
100 vlog("===== Ventoy2Disk %s powered by GTK%d.x =====\n", ventoy_get_local_version(), GTK_MAJOR_VERSION
);
101 vlog("================================================\n");
107 pBuilder
= gtk_builder_new();
110 vlog("failed to create builder\n");
114 if (!gtk_builder_add_from_file(pBuilder
, "./tool/VentoyGTK.glade", &error
))
116 vlog("gtk_builder_add_from_file failed:%s\n", error
->message
);
117 g_clear_error(&error
);
121 pData
= get_refresh_icon_raw_data(&len
);
122 set_image_from_pixbuf(pBuilder
, "image_refresh", pData
, len
);
124 pData
= get_secure_icon_raw_data(&len
);
125 set_image_from_pixbuf(pBuilder
, "image_secure_local", pData
, len
);
126 set_image_from_pixbuf(pBuilder
, "image_secure_dev", pData
, len
);
128 pWidget
= GTK_WIDGET(gtk_builder_get_object(pBuilder
, "window"));
129 gtk_widget_show_all(pWidget
);
131 pData
= get_window_icon_raw_data(&len
);
132 set_window_icon_from_pixbuf(GTK_WINDOW(pWidget
), pData
, len
);
134 on_init_window(pBuilder
);
135 g_signal_connect(G_OBJECT(pWidget
), "delete_event", G_CALLBACK(on_exit_window
), NULL
);
136 g_signal_connect(G_OBJECT(pWidget
), "destroy", G_CALLBACK(gtk_main_quit
), NULL
);
143 g_object_unref (G_OBJECT(pBuilder
));
145 vlog("######## Ventoy2Disk GTK %s exit ########\n", ventoy_get_local_version());
147 /* log exit must at the end */