From: longpanda Date: Thu, 17 Feb 2022 02:49:56 +0000 (+0800) Subject: Add check for vlnk file suffix in save as X-Git-Tag: v1.0.70~10 X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/Ventoy.git/commitdiff_plain/9118d5fe45d00d036a7767efc43f012a537989c4?ds=sidebyside Add check for vlnk file suffix in save as --- diff --git a/Vlnk/src/main_windows.c b/Vlnk/src/main_windows.c index ba195f2..34f7548 100644 --- a/Vlnk/src/main_windows.c +++ b/Vlnk/src/main_windows.c @@ -37,6 +37,7 @@ typedef enum MSGID MSGID_VLNK_POINT_TO, MSGID_VLNK_NO_DST, MSGID_FILE_NAME_TOO_LONG, + MSGID_INVALID_SUFFIX, MSGID_BUTT }MSGID; @@ -61,6 +62,7 @@ const WCHAR *g_msg_cn[MSGID_BUTT] = L"´Ë vlnk ÎļþÖ¸Ïò ", L"´Ë vlnk Ö¸ÏòµÄÎļþ²»´æÔÚ£¡", L"Îļþ·¾¶Ì«³¤£¡", + L"·Ç·¨µÄvlnkÎļþºó׺Ãû!", }; const WCHAR *g_msg_en[MSGID_BUTT] = { @@ -81,6 +83,7 @@ const WCHAR *g_msg_en[MSGID_BUTT] = L"The vlnk file point to ", L"The file pointed by the vlnk does NOT exist!", L"The file full path is too long!", + L"Invalid vlnk file suffix!", }; const WCHAR **g_msg_lang = NULL; @@ -382,6 +385,38 @@ static BOOL VentoyGetSaveFileName(HWND hWnd, WCHAR *szFile) return GetSaveFileName(&ofn); } +static BOOL IsSupportedVlnkSuffix(WCHAR *FileName) +{ + int len; + + len = lstrlen(FileName); + + if (len > 9) + { + if (lstrcmp(FileName - 9, L".vlnk.iso") == 0 || + lstrcmp(FileName - 9, L".vlnk.img") == 0 || + lstrcmp(FileName - 9, L".vlnk.wim") == 0 || + lstrcmp(FileName - 9, L".vlnk.vhd") == 0 || + lstrcmp(FileName - 9, L".vlnk.efi") == 0 || + lstrcmp(FileName - 9, L".vlnk.dat") == 0) + { + return TRUE; + } + } + + + if (len > 10) + { + if (lstrcmp(FileName - 10, L".vlnk.vhdx") == 0 || + lstrcmp(FileName - 9, L".vlnk.vtoy") == 0) + { + return TRUE; + } + } + + return FALSE; +} + static int CreateVlnk(HWND hWnd, WCHAR *Dir, WCHAR *InFile, WCHAR *OutFile) { int i; @@ -542,8 +577,17 @@ static int CreateVlnk(HWND hWnd, WCHAR *Dir, WCHAR *InFile, WCHAR *OutFile) wcscpy_s(szFile, MAX_PATH, DstFullPath); if (VentoyGetSaveFileName(hWnd, szFile)) { - wcscpy_s(DstFullPath, MAX_PATH, szFile); - SetOutFile = TRUE; + if (IsSupportedVlnkSuffix(szFile)) + { + wcscpy_s(DstFullPath, MAX_PATH, szFile); + SetOutFile = TRUE; + } + else + { + VtoyMessageBox(hWnd, g_msg_lang[MSGID_INVALID_SUFFIX], g_msg_lang[MSGID_ERROR], MB_OK | MB_ICONERROR); + LogA("Invalid vlnk suffix\n"); + goto end; + } } else { @@ -577,6 +621,7 @@ static int CreateVlnk(HWND hWnd, WCHAR *Dir, WCHAR *InFile, WCHAR *OutFile) VtoyMessageBox(hWnd, g_msg_lang[MSGID_CREATE_FILE_ERR], g_msg_lang[MSGID_ERROR], MB_OK | MB_ICONERROR); } + end: free(Buf); } diff --git a/Vlnk/vs/VentoyVlnk/Release/VentoyVlnk.exe b/Vlnk/vs/VentoyVlnk/Release/VentoyVlnk.exe index 4e37e43..ac8bfa3 100644 Binary files a/Vlnk/vs/VentoyVlnk/Release/VentoyVlnk.exe and b/Vlnk/vs/VentoyVlnk/Release/VentoyVlnk.exe differ