]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
Suppress some prompt window when install Ventoy.
authorlongpanda <admin@ventoy.net>
Sat, 17 Dec 2022 15:36:59 +0000 (23:36 +0800)
committerlongpanda <admin@ventoy.net>
Sat, 17 Dec 2022 15:36:59 +0000 (23:36 +0800)
INSTALL/Ventoy2Disk.exe
INSTALL/Ventoy2Disk_ARM.exe
INSTALL/Ventoy2Disk_ARM64.exe
INSTALL/Ventoy2Disk_X64.exe
Ventoy2Disk/Ventoy2Disk/AlertSuppress.c
Ventoy2Disk/Ventoy2Disk/PhyDrive.c
Ventoy2Disk/Ventoy2Disk/Ventoy2Disk.h
Ventoy2Disk/Ventoy2Disk/WinDialog.c

index 06a56ededf2f365615c0261c3e7378a64fcdf64e..a002bbfb1d7354367bb1ff12753a6f57f7dafe87 100644 (file)
Binary files a/INSTALL/Ventoy2Disk.exe and b/INSTALL/Ventoy2Disk.exe differ
index 5240565cb60c1245f0bc4684947876e9055f92c8..1ef1862d31ba16edb93e3894b1a46173417b276c 100644 (file)
Binary files a/INSTALL/Ventoy2Disk_ARM.exe and b/INSTALL/Ventoy2Disk_ARM.exe differ
index 949fb483d07edfa0390abdaceca8592fc4701076..d44835b7250620b14ecce5626141ee45d6e79367 100644 (file)
Binary files a/INSTALL/Ventoy2Disk_ARM64.exe and b/INSTALL/Ventoy2Disk_ARM64.exe differ
index 5e038a588a3100869c8e29f180c1836d32ef852b..ac4c533d288ca07f599f752a08baef6acf04bf84 100644 (file)
Binary files a/INSTALL/Ventoy2Disk_X64.exe and b/INSTALL/Ventoy2Disk_X64.exe differ
index 00037ac5f51ae1a460ee48fd396866c08db4f35b..333d6bd03934a090a275a90d6ad62d030185168b 100644 (file)
@@ -73,7 +73,12 @@ static __inline wchar_t* utf8_to_wchar(const char* str)
        return wstr;\r
 }\r
 \r
-static char title_str[2][128], button_str[128];\r
+static char g_FormatDiskTitle[256];\r
+static char g_FormatDiskButton[256];\r
+\r
+static char g_LocNotAvaliableTitle[256]; //Location is not available\r
+static char g_InsertDiskTitle[256]; // Insert disk\r
+\r
 static char system_dir[MAX_PATH], sysnative_dir[MAX_PATH];\r
 \r
 static HWINEVENTHOOK ap_weh = NULL;\r
@@ -236,6 +241,96 @@ static __inline HMODULE LoadLibraryU(LPCSTR lpFileName)
        return ret;\r
 }\r
 \r
+#pragma pack(1)\r
+typedef struct {\r
+       WORD      dlgVer;\r
+       WORD      signature;\r
+       DWORD     helpID;\r
+       DWORD     exStyle;\r
+       DWORD     style;\r
+       WORD      cDlgItems;\r
+       short     x;\r
+       short     y;\r
+       short     cx;\r
+       short     cy;\r
+       //sz_Or_Ord menu;\r
+       //sz_Or_Ord windowClass;\r
+       //WCHAR     title[titleLen];\r
+       //WORD      pointsize;\r
+       //WORD      weight;\r
+       //BYTE      italic;\r
+       //BYTE      charset;\r
+       //WCHAR     typeface[stringLen];\r
+} DLGTEMPLATEEX;\r
+#pragma pack()\r
+\r
+static BOOL LoadDialogCaption(HMODULE hMui, DWORD ID, CHAR* title, DWORD len)\r
+{\r
+       BOOL bRet = FALSE;\r
+       int WordNum = 0;\r
+       HRSRC hDlg = NULL;\r
+       DLGTEMPLATEEX* pDlgTempEx = NULL;\r
+       HGLOBAL hTemplate = NULL;\r
+       WORD* pWordData = NULL;\r
+\r
+       hDlg = FindResource(hMui, MAKEINTRESOURCE(1024), RT_DIALOG);\r
+       if (hDlg)\r
+       {\r
+               hTemplate = LoadResource(hMui, hDlg);\r
+               if (hTemplate)\r
+               {\r
+                       pDlgTempEx = (DLGTEMPLATEEX*)LockResource(hTemplate);\r
+                       if (pDlgTempEx)\r
+                       {\r
+                               if (pDlgTempEx->signature != 0xFFFF)\r
+                               {\r
+                                       return FALSE;\r
+                               }\r
+\r
+                               pWordData = (WORD *)(pDlgTempEx + 1);\r
+                               \r
+                               //skip menu\r
+                               if (*pWordData == 0x0000)\r
+                               {\r
+                                       pWordData += 1;\r
+                               }\r
+                               else if (*pWordData == 0xFFFF)\r
+                               {\r
+                                       pWordData += 2;\r
+                               }\r
+                               else\r
+                               {\r
+                                       while (*pWordData++)\r
+                                       {\r
+                                               ;\r
+                                       }\r
+                               }\r
+\r
+                               //skip windowClass\r
+                               if (*pWordData == 0x0000)\r
+                               {\r
+                                       pWordData += 1;\r
+                               }\r
+                               else if (*pWordData == 0xFFFF)\r
+                               {\r
+                                       pWordData += 2;\r
+                               }\r
+                               else\r
+                               {\r
+                                       while (*pWordData++)\r
+                                       {\r
+                                               ;\r
+                                       }\r
+                               }\r
+\r
+                               wchar_to_utf8_no_alloc(pWordData, title, len);\r
+                               bRet = TRUE;\r
+                       }\r
+               }\r
+       }\r
+\r
+       return bRet;\r
+}\r
 \r
 BOOL SetAlertPromptMessages(void)\r
 {\r
@@ -270,26 +365,42 @@ BOOL SetAlertPromptMessages(void)
        hMui = LoadLibraryU(mui_path);\r
        if (hMui)\r
        {\r
-               // 4097 = "You need to format the disk in drive %c: before you can use it." (dialog text)\r
-               // 4125 = "Microsoft Windows" (dialog title)\r
-               // 4126 = "Format disk" (button)\r
-               if (LoadStringU(hMui, 4125, title_str[0], sizeof(title_str[0])) <= 0) {\r
-                       static_strcpy(title_str[0], "Microsoft Windows");\r
-                       Log("Warning: Could not locate localized format prompt title string in '%s': %u", mui_path, LASTERR);\r
-               }\r
-               if (LoadStringU(hMui, 4126, button_str, sizeof(button_str)) <= 0) {\r
-                       static_strcpy(button_str, "Format disk");\r
-                       Log("Warning: Could not locate localized format prompt button string in '%s': %u", mui_path, LASTERR);\r
-               }\r
-               FreeLibrary(hMui);\r
-\r
                Log("LoadLibrary shell32.dll.mui SUCCESS");\r
        }\r
        else\r
        {\r
                Log("LoadLibrary shell32.dll.mui FAILED");\r
+               return FALSE;\r
        }\r
 \r
+\r
+       // String Table:\r
+       // 4097 = "You need to format the disk in drive %c: before you can use it." (dialog text)\r
+       // 4125 = "Microsoft Windows" (dialog title)\r
+       // 4126 = "Format disk" (button)\r
+       if (LoadStringU(hMui, 4125, g_FormatDiskTitle, sizeof(g_FormatDiskTitle)) <= 0) {\r
+               static_strcpy(g_FormatDiskTitle, "Microsoft Windows");\r
+               Log("Warning: Could not locate localized format prompt title string in '%s': %u", mui_path, LASTERR);\r
+       }\r
+\r
+       if (LoadStringU(hMui, 4126, g_FormatDiskButton, sizeof(g_FormatDiskButton)) <= 0) {\r
+               static_strcpy(g_FormatDiskButton, "Format disk");\r
+               Log("Warning: Could not locate localized format prompt button string in '%s': %u", mui_path, LASTERR);\r
+       }\r
+\r
+       // 32964 = "Location is not available"\r
+       if (LoadStringU(hMui, 32964, g_LocNotAvaliableTitle, sizeof(g_LocNotAvaliableTitle)) <= 0) {\r
+               static_strcpy(g_LocNotAvaliableTitle, "Location is not available");\r
+               Log("Warning: Could not locate localized format prompt title string in '%s': %u", mui_path, LASTERR);\r
+       }\r
+\r
+       if (!LoadDialogCaption(hMui, 1024, g_InsertDiskTitle, sizeof(g_InsertDiskTitle)))\r
+       {\r
+               static_strcpy(g_InsertDiskTitle, "Insert disk");\r
+               Log("Warning: Could not locate insert disk title string in '%s': %u", mui_path, LASTERR);\r
+       }\r
+\r
+       FreeLibrary(hMui);\r
        return TRUE;\r
 }\r
 \r
@@ -336,29 +447,59 @@ static BOOL CALLBACK AlertPromptCallback(HWND hWnd, LPARAM lParam)
 \r
        if (GetWindowTextU(hWnd, str, sizeof(str)) == 0)\r
                return TRUE;\r
-       if (strcmp(str, button_str) == 0)\r
+       if (strcmp(str, g_FormatDiskButton) == 0)\r
                *found = TRUE;\r
        return TRUE;\r
 }\r
 \r
+static volatile BOOL g_AlertPromptHookEnable = FALSE;\r
+\r
+void SetAlertPromptHookEnable(BOOL enable)\r
+{\r
+       g_AlertPromptHookEnable = enable;\r
+}\r
+\r
 static void CALLBACK AlertPromptHook(HWINEVENTHOOK hWinEventHook, DWORD Event, HWND hWnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime)\r
 {\r
        char str[128];\r
        BOOL found;\r
 \r
-       if (Event == EVENT_SYSTEM_FOREGROUND) {\r
-               if (GetWindowLongPtr(hWnd, GWL_STYLE) & WS_POPUPWINDOW) {\r
-                       str[0] = 0;\r
-                       GetWindowTextU(hWnd, str, sizeof(str));\r
-                       if (strcmp(str, title_str[0]) == 0) {\r
-                               found = FALSE;\r
-                               EnumChildWindows(hWnd, AlertPromptCallback, (LPARAM)&found);\r
-                               if (found) {\r
-                                       SendMessage(hWnd, WM_COMMAND, (WPARAM)IDCANCEL, (LPARAM)0);\r
-                                       Log("###### Closed Windows format prompt #######");\r
-                               }\r
+       if (Event != EVENT_SYSTEM_FOREGROUND)\r
+       {\r
+               return;\r
+       }\r
+\r
+       if (!g_AlertPromptHookEnable)\r
+       {\r
+               return;\r
+       }\r
+\r
+       //GetWindowTextU(hWnd, str, sizeof(str));\r
+       //Log("###### EVENT_SYSTEM_FOREGROUND Windows prompt <%s> #######", str);\r
+\r
+       if (GetWindowLongPtr(hWnd, GWL_STYLE) & WS_POPUPWINDOW) {\r
+               str[0] = 0;\r
+               GetWindowTextU(hWnd, str, sizeof(str));\r
+               if (strcmp(str, g_FormatDiskTitle) == 0)\r
+               {\r
+                       found = FALSE;\r
+                       EnumChildWindows(hWnd, AlertPromptCallback, (LPARAM)&found);\r
+                       if (found)\r
+                       {\r
+                               SendMessage(hWnd, WM_COMMAND, (WPARAM)IDCANCEL, (LPARAM)0);\r
+                               Log("###### Detect 'Windows format' prompt, now close it. #######");\r
                        }\r
                }\r
+               else if (strcmp(str, g_LocNotAvaliableTitle) == 0)\r
+               {\r
+                       SendMessage(hWnd, WM_COMMAND, (WPARAM)IDCANCEL, (LPARAM)0);\r
+                       Log("###### Detect 'Location is not available' prompt, now close it. #######");\r
+               }\r
+               else if (strcmp(str, g_InsertDiskTitle) == 0)\r
+               {\r
+                       SendMessage(hWnd, WM_COMMAND, (WPARAM)IDCANCEL, (LPARAM)0);\r
+                       Log("###### Detect 'Insert disk' prompt, now close it. #######");\r
+               }\r
        }\r
 }\r
 \r
index 256a9cf28706b63d03f4e2486f18237e0fea17af..11e3d966f7d6f21235bfef01edec7b874a439176 100644 (file)
@@ -1225,7 +1225,45 @@ static int FormatPart1exFAT(UINT64 DiskSizeBytes)
     }\r
 }\r
 \r
+static int ZeroPart1FileSystem(HANDLE hDrive, UINT64 Part2StartSector)\r
+{\r
+    int i;\r
+    DWORD dwSize = 0;\r
+    LARGE_INTEGER liCurPos;\r
+    LARGE_INTEGER liNewPos;\r
+    CHAR TmpBuffer[1024] = { 0 };\r
+\r
+    liCurPos.QuadPart = VENTOY_PART1_START_SECTOR * 512;\r
+    liNewPos.QuadPart = 0;\r
+    if (0 == SetFilePointerEx(hDrive, liCurPos, &liNewPos, FILE_BEGIN) ||\r
+        liNewPos.QuadPart != liCurPos.QuadPart)\r
+    {\r
+        Log("SetFilePointerEx Failed %u %llu %llu", LASTERR, (ULONGLONG)liCurPos.QuadPart, (ULONGLONG)liNewPos.QuadPart);\r
+        return 1;\r
+    }\r
+\r
+    for (i = 0; i < 1024; i++)\r
+    {\r
+        WriteFile(hDrive, TmpBuffer, 1024, &dwSize, NULL);\r
+    }\r
+\r
+    liCurPos.QuadPart = (Part2StartSector * 512) - (1024 * 1024);\r
+    liNewPos.QuadPart = 0;\r
+    if (0 == SetFilePointerEx(hDrive, liCurPos, &liNewPos, FILE_BEGIN) ||\r
+        liNewPos.QuadPart != liCurPos.QuadPart)\r
+    {\r
+        Log("SetFilePointerEx Failed %u %llu %llu", LASTERR, (ULONGLONG)liCurPos.QuadPart, (ULONGLONG)liNewPos.QuadPart);\r
+        return 1;\r
+    }\r
 \r
+    for (i = 0; i < 1024; i++)\r
+    {\r
+        WriteFile(hDrive, TmpBuffer, 1024, &dwSize, NULL);\r
+    }\r
+\r
+    Log("Zero Part1 SUCCESS");\r
+    return 0;\r
+}\r
 \r
 int ClearVentoyFromPhyDrive(HWND hWnd, PHY_DRIVE_INFO *pPhyDrive, char *pDrvLetter)\r
 {\r
@@ -1826,13 +1864,12 @@ int InstallVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int PartStyle, int TryId)
     }\r
     else\r
     {\r
-        CHAR TmpBuffer[512] = { 0 };\r
-\r
         Log("Zero part1 file system ...");\r
-        SetFilePointer(hDrive, VENTOY_PART1_START_SECTOR * 512, NULL, FILE_BEGIN);\r
-        for (i = 0; i < 32; i++)\r
+        if (0 != ZeroPart1FileSystem(hDrive, Part2StartSector))\r
         {\r
-            WriteFile(hDrive, TmpBuffer, 512, &dwSize, NULL);\r
+            Log("ZeroPart1FileSystem failed.");\r
+            rc = 1;\r
+            goto End;\r
         }\r
     }\r
 \r
@@ -1962,7 +1999,7 @@ End:
         Log("Close handle ...");\r
         CHECK_CLOSE_HANDLE(hDrive);\r
 \r
-        ReformatOK = FALSE;\r
+        ReformatOK = TRUE;\r
 \r
         if (state)\r
         {\r
@@ -1983,7 +2020,6 @@ End:
 \r
                 if (bRet)\r
                 {\r
-                    ReformatOK = TRUE;\r
                     Log("Reformat %C:\\ to %s SUCCESS", MountDrive, GetVentoyFsName());\r
                     pPhyDrive->VentoyFsClusterSize = GetVolumeClusterSize(MountDrive);\r
 \r
@@ -1997,6 +2033,7 @@ End:
                 }\r
                 else\r
                 {\r
+                    ReformatOK = FALSE;\r
                     Log("Reformat %C:\\ to %s FAILED", MountDrive, GetVentoyFsName());\r
                 }\r
             }\r
index b9265a39e44b3666f6b1ebab73f980bd7e2814c8..21287279c2ea5796301226a2a913cc097d5015f9 100644 (file)
@@ -357,6 +357,7 @@ void disk_io_reset_write_error(void);
 const char* GUID2String(void* guid, char* buf, int len);\r
 void VentoyStringToUpper(CHAR* str);\r
 BOOL AlertSuppressInit(void);\r
+void SetAlertPromptHookEnable(BOOL enable);\r
 \r
 #define VTSI_SUPPORT 1\r
 \r
index 3c813fd3414d8803114a2dea8d08a0781a035710..2e4a369278d273d7a214810be34334d74aab5a0e 100644 (file)
Binary files a/Ventoy2Disk/Ventoy2Disk/WinDialog.c and b/Ventoy2Disk/Ventoy2Disk/WinDialog.c differ