X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/Ventoy.git/blobdiff_plain/dd2411d7d47fd72be78802cb28d6f0ef73785e9e..8cecdae8f9d7e1b77917e172c37cfd07907aeb71:/LinuxGUI/Ventoy2Disk/main_gtk.c diff --git a/LinuxGUI/Ventoy2Disk/main_gtk.c b/LinuxGUI/Ventoy2Disk/main_gtk.c index 5560991..4f1d8a0 100644 --- a/LinuxGUI/Ventoy2Disk/main_gtk.c +++ b/LinuxGUI/Ventoy2Disk/main_gtk.c @@ -8,10 +8,16 @@ #include #include #include +#include +#include +#include #include #include #include "ventoy_gtk.h" +char g_log_file[PATH_MAX]; +char g_ini_file[PATH_MAX]; + static int set_image_from_pixbuf(GtkBuilder *pBuilder, const char *id, const void *pData, int len) { GtkImage *pImage = NULL; @@ -51,13 +57,58 @@ int early_msgbox(GtkMessageType type, GtkButtonsType buttons, const char *str) return ret; } +static int adjust_cur_dir(char *argv0) +{ + int ret = 2; + char c; + char *pos = NULL; + char *end = NULL; + + if (argv0[0] == '.') + { + return 1; + } + + for (pos = argv0; pos && *pos; pos++) + { + if (*pos == '/') + { + end = pos; + } + } + + if (end) + { + c = *end; + *end = 0; + + pos = strstr(argv0, "/tool/"); + if (pos) + { + *pos = 0; + } + + ret = chdir(argv0); + + *end = c; + if (pos) + { + *pos = '/'; + } + } + + return ret; +} + int main(int argc, char *argv[]) { + int i; int len; const void *pData = NULL; GtkWidget *pWidget = NULL; GtkBuilder *pBuilder = NULL; GError *error = NULL; + struct stat logstat; gtk_init(&argc, &argv); @@ -68,17 +119,47 @@ int main(int argc, char *argv[]) return EACCES; } + if (access("./boot/boot.img", F_OK) == -1) + { + adjust_cur_dir(argv[0]); + } + if (access("./boot/boot.img", F_OK) == -1) { early_msgbox(GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Please run under the correct directory."); return 1; } + snprintf(g_log_file, sizeof(g_log_file), "log.txt"); + snprintf(g_ini_file, sizeof(g_ini_file), "./Ventoy2Disk.ini"); + for (i = 0; i < argc; i++) + { + if (argv[i] && argv[i + 1] && strcmp(argv[i], "-l") == 0) + { + snprintf(g_log_file, sizeof(g_log_file), "%s", argv[i + 1]); + } + else if (argv[i] && argv[i + 1] && strcmp(argv[i], "-i") == 0) + { + snprintf(g_ini_file, sizeof(g_ini_file), "%s", argv[i + 1]); + } + } + + memset(&logstat, 0, sizeof(logstat)); + if (0 == stat(g_log_file, &logstat)) + { + if (logstat.st_size >= 4 * SIZE_1MB) + { + remove(g_log_file); + } + } + ventoy_log_init(); vlog("================================================\n"); vlog("===== Ventoy2Disk %s powered by GTK%d.x =====\n", ventoy_get_local_version(), GTK_MAJOR_VERSION); vlog("================================================\n"); + vlog("log file is <%s> lastsize:%lld\n", g_log_file, (long long)logstat.st_size); + vlog("ini file is <%s>\n", g_ini_file); ventoy_disk_init(); @@ -113,6 +194,7 @@ int main(int argc, char *argv[]) on_init_window(pBuilder); g_signal_connect(G_OBJECT(pWidget), "delete_event", G_CALLBACK(on_exit_window), NULL); + g_signal_connect(G_OBJECT(pWidget), "destroy", G_CALLBACK(gtk_main_quit), NULL); gtk_main();