X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/Ventoy.git/blobdiff_plain/dcc588967716395dfdb51be9dcd24e64145edd1b..0ffb1b15ef6fcbc8774133799f463bdfdbb15b4d:/Plugson/src/main_windows.c diff --git a/Plugson/src/main_windows.c b/Plugson/src/main_windows.c index 066eb63..49e89c3 100644 --- a/Plugson/src/main_windows.c +++ b/Plugson/src/main_windows.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -10,8 +10,9 @@ #include #include -char g_ventoy_dir[MAX_PATH]; +char g_ventoy_dir[MAX_PATH]; +static BOOL g_ChromeFirst = TRUE; static BOOL g_running = FALSE; static HWND g_refresh_button; static HWND g_start_button; @@ -44,22 +45,22 @@ typedef enum MSGID const WCHAR *g_msg_cn[MSGID_BUTT] = { - L"´íÎó", - L"ÌáÐÑ", - L"ÇëÔÚ Ventoy Å̸ùĿ¼ÏÂÔËÐб¾³ÌÐò£¡£¨´æ·ÅISOÎļþµÄλÖã©", - L"´´½¨ ventoy Ŀ¼ʧ°Ü£¬ÎÞ·¨¼ÌÐø£¡", - L"ventoy Ŀ¼´æÔÚ£¬µ«ÊÇ´óСд²»Æ¥Å䣬ÇëÏȽ«ÆäÖØÃüÃû£¡", - L"ÄÚ²¿´íÎ󣬳ÌÐò¼´½«Í˳ö£¡", - L"Ë¢ÐÂ", - L"Æô¶¯", - L"Í£Ö¹", - L"Á´½Ó", - L"Í˳ö", - - L"Í£Ö¹ÔËÐкóä¯ÀÀÆ÷Ò³Ãæ½«»á¹Ø±Õ£¬ÊÇ·ñ¼ÌÐø£¿", - L"µ±Ç°·þÎñÕýÔÚÔËÐУ¬ÊÇ·ñÍ˳ö£¿", - L"ÇëÏȹرÕÕýÔÚÔËÐÐµÄ VentoyPlugson ³ÌÐò£¡", - L"ventoy\\plugson.tar.xz Îļþ²»´æÔÚ£¬ÇëÔÚÕýÈ·µÄĿ¼ÏÂÔËÐУ¡", + L"错误", + L"提醒", + L"请在 Ventoy 盘根目录下运行本程序!(存放ISO文件的位置)", + L"创建 ventoy 目录失败,无法继续!", + L"ventoy 目录存在,但是大小写不匹配,请先将其重命名!", + L"内部错误,程序即将退出!", + L"刷新", + L"启动", + L"停止", + L"链接", + L"退出", + + L"停止运行后浏览器页面将会关闭,是否继续?", + L"当前服务正在运行,是否退出?", + L"请先关闭正在运行的 VentoyPlugson 程序!", + L"ventoy\\plugson.tar.xz 文件不存在,请在正确的目录下运行!", }; const WCHAR *g_msg_en[MSGID_BUTT] = { @@ -81,6 +82,14 @@ const WCHAR *g_msg_en[MSGID_BUTT] = L"ventoy\\plugson.tar.xz does not exist, please run under the correct directory!", }; +#define UTF8_Log(fmt, wstr) \ +{\ + memset(TmpPathA, 0, sizeof(TmpPathA));\ + WideCharToMultiByte(CP_UTF8, 0, wstr, -1, TmpPathA, sizeof(TmpPathA), NULL, NULL);\ + vlog(fmt, TmpPathA);\ +} + + const WCHAR **g_msg_lang = NULL; HINSTANCE g_hInst; @@ -93,7 +102,7 @@ void ventoy_log_exit(void); static BOOL OnDestroyDialog() { - ventoy_http_exit(); + ventoy_http_exit(); ventoy_disk_exit(); #ifndef VENTOY_SIM ventoy_www_exit(); @@ -118,14 +127,17 @@ static void OpenURL(void) sprintf_s(url, sizeof(url), "http://%s:%s/index.html", g_sysinfo.ip, g_sysinfo.port); - for (i = 0; Browsers[i] != NULL; i++) - { - if (ventoy_is_file_exist("%s", Browsers[i])) - { - ShellExecuteA(NULL, "open", Browsers[i], url, NULL, SW_SHOW); - return; - } - } + if (g_ChromeFirst) + { + for (i = 0; Browsers[i] != NULL; i++) + { + if (ventoy_is_file_exist("%s", Browsers[i])) + { + ShellExecuteA(NULL, "open", Browsers[i], url, NULL, SW_SHOW); + return; + } + } + } ShellExecuteA(NULL, "open", url, NULL, NULL, SW_SHOW); } @@ -395,7 +407,7 @@ INT_PTR CALLBACK DialogProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lPara { InitDialog(hWnd, wParam, lParam); break; - } + } case WM_CLOSE: { if (g_running) @@ -410,6 +422,7 @@ INT_PTR CALLBACK DialogProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lPara OnDestroyDialog(); EndDialog(hWnd, 0); + break; } } @@ -468,6 +481,7 @@ static int ParseCmdLine(LPSTR lpCmdLine, char *ip, char *port) // //copy from Rufus +//Copyright © 2011-2021 Pete Batard // #include // For delay-loaded DLLs, use LOAD_LIBRARY_SEARCH_SYSTEM32 to avoid DLL search order hijacking. @@ -520,12 +534,28 @@ static void DllProtect(void) int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow) { + int i; int rc; + int status = 0; HANDLE hMutex; + WCHAR* Pos = NULL; WCHAR CurDir[MAX_PATH]; + WCHAR ExePath[MAX_PATH]; + WCHAR CurDirBk[MAX_PATH]; + WCHAR ExePathBk[MAX_PATH]; + CHAR TmpPathA[MAX_PATH]; UNREFERENCED_PARAMETER(hPrevInstance); + for (i = 0; i < __argc; i++) + { + if (__argv[i] && _stricmp(__argv[i], "/F") == 0) + { + g_ChromeFirst = FALSE; + break; + } + } + DllProtect(); if (GetUserDefaultUILanguage() == 0x0804) @@ -547,12 +577,67 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi } GetCurrentDirectoryW(MAX_PATH, CurDir); + GetCurrentDirectoryW(MAX_PATH, CurDirBk); + GetModuleFileNameW(NULL, ExePath, MAX_PATH); + GetModuleFileNameW(NULL, ExePathBk, MAX_PATH); + + for (Pos = NULL, i = 0; i < MAX_PATH && ExePath[i]; i++) + { + if (ExePath[i] == '\\' || ExePath[i] == '/') + { + Pos = ExePath + i; + } + } + + if (Pos) + { + *Pos = 0; + if (wcscmp(CurDir, ExePath)) + { + status |= 1; + SetCurrentDirectoryW(ExePath); + GetCurrentDirectoryW(MAX_PATH, CurDir); + } + else + { + status |= 2; + } + } + + Pos = wcsstr(CurDir, L"\\altexe"); + if (Pos) + { + *Pos = 0; + status |= 4; + SetCurrentDirectoryW(CurDir); + } + + WideCharToMultiByte(CP_UTF8, 0, CurDir, -1, g_cur_dir, MAX_PATH, NULL, 0); sprintf_s(g_ventoy_dir, sizeof(g_ventoy_dir), "%s", g_cur_dir); - sprintf_s(g_log_file, sizeof(g_log_file), "%s\\%s", g_cur_dir, LOG_FILE); + sprintf_s(g_log_file, sizeof(g_log_file), "%s", LOG_FILE); ventoy_log_init(); + vlog("====================== Ventoy Plugson =========================\n"); + + UTF8_Log("Current Directory <%s>\n", CurDirBk); + UTF8_Log("Exe file path <%s>\n", ExePathBk); + + if (status & 1) + { + UTF8_Log("Change current dir to exe <%s>\n", ExePath); + } + if (status & 2) + { + vlog("Current directory check OK.\n"); + } + if (status & 4) + { + UTF8_Log("altexe detected, change current dir to <%s>\n", CurDir); + } + + if (!ventoy_is_file_exist("%s\\ventoy\\%s", g_ventoy_dir, PLUGSON_TXZ)) { MessageBoxW(NULL, g_msg_lang[MSGID_NO_TARXZ_TIP], g_msg_lang[MSGID_ERROR], MB_OK | MB_ICONERROR); @@ -570,7 +655,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi } vlog("===============================================\n"); - vlog("===== Ventoy Plugson %s:%s =====\n", g_sysinfo.ip, g_sysinfo.port); + vlog("========= Ventoy Plugson %s:%s =========\n", g_sysinfo.ip, g_sysinfo.port); vlog("===============================================\n"); @@ -590,7 +675,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi ventoy_http_init(); g_hInst = hInstance; - DialogBoxA(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DialogProc); + DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DialogProc); return 0; }