X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/Ventoy.git/blobdiff_plain/d1481392271fd44b04c384a3dd56f3386edadfb3..d72bb15956ccf039a03702bc47c984f42d7df960:/LinuxGUI/Ventoy2Disk/main_gtk.c diff --git a/LinuxGUI/Ventoy2Disk/main_gtk.c b/LinuxGUI/Ventoy2Disk/main_gtk.c index 1957a43..4f1d8a0 100644 --- a/LinuxGUI/Ventoy2Disk/main_gtk.c +++ b/LinuxGUI/Ventoy2Disk/main_gtk.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -56,6 +57,49 @@ 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; @@ -64,6 +108,7 @@ int main(int argc, char *argv[]) GtkWidget *pWidget = NULL; GtkBuilder *pBuilder = NULL; GError *error = NULL; + struct stat logstat; gtk_init(&argc, &argv); @@ -74,6 +119,11 @@ 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."); @@ -94,11 +144,22 @@ int main(int argc, char *argv[]) } } + 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();