Suppress some prompt window when install Ventoy.

This commit is contained in:
longpanda 2022-12-17 23:36:59 +08:00
parent 5c174c4521
commit 2de7d9ffe0
8 changed files with 212 additions and 33 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -73,7 +73,12 @@ static __inline wchar_t* utf8_to_wchar(const char* str)
return wstr;
}
static char title_str[2][128], button_str[128];
static char g_FormatDiskTitle[256];
static char g_FormatDiskButton[256];
static char g_LocNotAvaliableTitle[256]; //Location is not available
static char g_InsertDiskTitle[256]; // Insert disk
static char system_dir[MAX_PATH], sysnative_dir[MAX_PATH];
static HWINEVENTHOOK ap_weh = NULL;
@ -236,6 +241,96 @@ static __inline HMODULE LoadLibraryU(LPCSTR lpFileName)
return ret;
}
#pragma pack(1)
typedef struct {
WORD dlgVer;
WORD signature;
DWORD helpID;
DWORD exStyle;
DWORD style;
WORD cDlgItems;
short x;
short y;
short cx;
short cy;
//sz_Or_Ord menu;
//sz_Or_Ord windowClass;
//WCHAR title[titleLen];
//WORD pointsize;
//WORD weight;
//BYTE italic;
//BYTE charset;
//WCHAR typeface[stringLen];
} DLGTEMPLATEEX;
#pragma pack()
static BOOL LoadDialogCaption(HMODULE hMui, DWORD ID, CHAR* title, DWORD len)
{
BOOL bRet = FALSE;
int WordNum = 0;
HRSRC hDlg = NULL;
DLGTEMPLATEEX* pDlgTempEx = NULL;
HGLOBAL hTemplate = NULL;
WORD* pWordData = NULL;
hDlg = FindResource(hMui, MAKEINTRESOURCE(1024), RT_DIALOG);
if (hDlg)
{
hTemplate = LoadResource(hMui, hDlg);
if (hTemplate)
{
pDlgTempEx = (DLGTEMPLATEEX*)LockResource(hTemplate);
if (pDlgTempEx)
{
if (pDlgTempEx->signature != 0xFFFF)
{
return FALSE;
}
pWordData = (WORD *)(pDlgTempEx + 1);
//skip menu
if (*pWordData == 0x0000)
{
pWordData += 1;
}
else if (*pWordData == 0xFFFF)
{
pWordData += 2;
}
else
{
while (*pWordData++)
{
;
}
}
//skip windowClass
if (*pWordData == 0x0000)
{
pWordData += 1;
}
else if (*pWordData == 0xFFFF)
{
pWordData += 2;
}
else
{
while (*pWordData++)
{
;
}
}
wchar_to_utf8_no_alloc(pWordData, title, len);
bRet = TRUE;
}
}
}
return bRet;
}
BOOL SetAlertPromptMessages(void)
{
@ -270,26 +365,42 @@ BOOL SetAlertPromptMessages(void)
hMui = LoadLibraryU(mui_path);
if (hMui)
{
// 4097 = "You need to format the disk in drive %c: before you can use it." (dialog text)
// 4125 = "Microsoft Windows" (dialog title)
// 4126 = "Format disk" (button)
if (LoadStringU(hMui, 4125, title_str[0], sizeof(title_str[0])) <= 0) {
static_strcpy(title_str[0], "Microsoft Windows");
Log("Warning: Could not locate localized format prompt title string in '%s': %u", mui_path, LASTERR);
}
if (LoadStringU(hMui, 4126, button_str, sizeof(button_str)) <= 0) {
static_strcpy(button_str, "Format disk");
Log("Warning: Could not locate localized format prompt button string in '%s': %u", mui_path, LASTERR);
}
FreeLibrary(hMui);
Log("LoadLibrary shell32.dll.mui SUCCESS");
}
else
{
Log("LoadLibrary shell32.dll.mui FAILED");
return FALSE;
}
// String Table:
// 4097 = "You need to format the disk in drive %c: before you can use it." (dialog text)
// 4125 = "Microsoft Windows" (dialog title)
// 4126 = "Format disk" (button)
if (LoadStringU(hMui, 4125, g_FormatDiskTitle, sizeof(g_FormatDiskTitle)) <= 0) {
static_strcpy(g_FormatDiskTitle, "Microsoft Windows");
Log("Warning: Could not locate localized format prompt title string in '%s': %u", mui_path, LASTERR);
}
if (LoadStringU(hMui, 4126, g_FormatDiskButton, sizeof(g_FormatDiskButton)) <= 0) {
static_strcpy(g_FormatDiskButton, "Format disk");
Log("Warning: Could not locate localized format prompt button string in '%s': %u", mui_path, LASTERR);
}
// 32964 = "Location is not available"
if (LoadStringU(hMui, 32964, g_LocNotAvaliableTitle, sizeof(g_LocNotAvaliableTitle)) <= 0) {
static_strcpy(g_LocNotAvaliableTitle, "Location is not available");
Log("Warning: Could not locate localized format prompt title string in '%s': %u", mui_path, LASTERR);
}
if (!LoadDialogCaption(hMui, 1024, g_InsertDiskTitle, sizeof(g_InsertDiskTitle)))
{
static_strcpy(g_InsertDiskTitle, "Insert disk");
Log("Warning: Could not locate insert disk title string in '%s': %u", mui_path, LASTERR);
}
FreeLibrary(hMui);
return TRUE;
}
@ -336,29 +447,59 @@ static BOOL CALLBACK AlertPromptCallback(HWND hWnd, LPARAM lParam)
if (GetWindowTextU(hWnd, str, sizeof(str)) == 0)
return TRUE;
if (strcmp(str, button_str) == 0)
if (strcmp(str, g_FormatDiskButton) == 0)
*found = TRUE;
return TRUE;
}
static volatile BOOL g_AlertPromptHookEnable = FALSE;
void SetAlertPromptHookEnable(BOOL enable)
{
g_AlertPromptHookEnable = enable;
}
static void CALLBACK AlertPromptHook(HWINEVENTHOOK hWinEventHook, DWORD Event, HWND hWnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime)
{
char str[128];
BOOL found;
if (Event == EVENT_SYSTEM_FOREGROUND) {
if (GetWindowLongPtr(hWnd, GWL_STYLE) & WS_POPUPWINDOW) {
str[0] = 0;
GetWindowTextU(hWnd, str, sizeof(str));
if (strcmp(str, title_str[0]) == 0) {
found = FALSE;
EnumChildWindows(hWnd, AlertPromptCallback, (LPARAM)&found);
if (found) {
SendMessage(hWnd, WM_COMMAND, (WPARAM)IDCANCEL, (LPARAM)0);
Log("###### Closed Windows format prompt #######");
}
if (Event != EVENT_SYSTEM_FOREGROUND)
{
return;
}
if (!g_AlertPromptHookEnable)
{
return;
}
//GetWindowTextU(hWnd, str, sizeof(str));
//Log("###### EVENT_SYSTEM_FOREGROUND Windows prompt <%s> #######", str);
if (GetWindowLongPtr(hWnd, GWL_STYLE) & WS_POPUPWINDOW) {
str[0] = 0;
GetWindowTextU(hWnd, str, sizeof(str));
if (strcmp(str, g_FormatDiskTitle) == 0)
{
found = FALSE;
EnumChildWindows(hWnd, AlertPromptCallback, (LPARAM)&found);
if (found)
{
SendMessage(hWnd, WM_COMMAND, (WPARAM)IDCANCEL, (LPARAM)0);
Log("###### Detect 'Windows format' prompt, now close it. #######");
}
}
else if (strcmp(str, g_LocNotAvaliableTitle) == 0)
{
SendMessage(hWnd, WM_COMMAND, (WPARAM)IDCANCEL, (LPARAM)0);
Log("###### Detect 'Location is not available' prompt, now close it. #######");
}
else if (strcmp(str, g_InsertDiskTitle) == 0)
{
SendMessage(hWnd, WM_COMMAND, (WPARAM)IDCANCEL, (LPARAM)0);
Log("###### Detect 'Insert disk' prompt, now close it. #######");
}
}
}

View File

@ -1225,7 +1225,45 @@ static int FormatPart1exFAT(UINT64 DiskSizeBytes)
}
}
static int ZeroPart1FileSystem(HANDLE hDrive, UINT64 Part2StartSector)
{
int i;
DWORD dwSize = 0;
LARGE_INTEGER liCurPos;
LARGE_INTEGER liNewPos;
CHAR TmpBuffer[1024] = { 0 };
liCurPos.QuadPart = VENTOY_PART1_START_SECTOR * 512;
liNewPos.QuadPart = 0;
if (0 == SetFilePointerEx(hDrive, liCurPos, &liNewPos, FILE_BEGIN) ||
liNewPos.QuadPart != liCurPos.QuadPart)
{
Log("SetFilePointerEx Failed %u %llu %llu", LASTERR, (ULONGLONG)liCurPos.QuadPart, (ULONGLONG)liNewPos.QuadPart);
return 1;
}
for (i = 0; i < 1024; i++)
{
WriteFile(hDrive, TmpBuffer, 1024, &dwSize, NULL);
}
liCurPos.QuadPart = (Part2StartSector * 512) - (1024 * 1024);
liNewPos.QuadPart = 0;
if (0 == SetFilePointerEx(hDrive, liCurPos, &liNewPos, FILE_BEGIN) ||
liNewPos.QuadPart != liCurPos.QuadPart)
{
Log("SetFilePointerEx Failed %u %llu %llu", LASTERR, (ULONGLONG)liCurPos.QuadPart, (ULONGLONG)liNewPos.QuadPart);
return 1;
}
for (i = 0; i < 1024; i++)
{
WriteFile(hDrive, TmpBuffer, 1024, &dwSize, NULL);
}
Log("Zero Part1 SUCCESS");
return 0;
}
int ClearVentoyFromPhyDrive(HWND hWnd, PHY_DRIVE_INFO *pPhyDrive, char *pDrvLetter)
{
@ -1826,13 +1864,12 @@ int InstallVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int PartStyle, int TryId)
}
else
{
CHAR TmpBuffer[512] = { 0 };
Log("Zero part1 file system ...");
SetFilePointer(hDrive, VENTOY_PART1_START_SECTOR * 512, NULL, FILE_BEGIN);
for (i = 0; i < 32; i++)
if (0 != ZeroPart1FileSystem(hDrive, Part2StartSector))
{
WriteFile(hDrive, TmpBuffer, 512, &dwSize, NULL);
Log("ZeroPart1FileSystem failed.");
rc = 1;
goto End;
}
}
@ -1962,7 +1999,7 @@ End:
Log("Close handle ...");
CHECK_CLOSE_HANDLE(hDrive);
ReformatOK = FALSE;
ReformatOK = TRUE;
if (state)
{
@ -1983,7 +2020,6 @@ End:
if (bRet)
{
ReformatOK = TRUE;
Log("Reformat %C:\\ to %s SUCCESS", MountDrive, GetVentoyFsName());
pPhyDrive->VentoyFsClusterSize = GetVolumeClusterSize(MountDrive);
@ -1997,6 +2033,7 @@ End:
}
else
{
ReformatOK = FALSE;
Log("Reformat %C:\\ to %s FAILED", MountDrive, GetVentoyFsName());
}
}

View File

@ -357,6 +357,7 @@ void disk_io_reset_write_error(void);
const char* GUID2String(void* guid, char* buf, int len);
void VentoyStringToUpper(CHAR* str);
BOOL AlertSuppressInit(void);
void SetAlertPromptHookEnable(BOOL enable);
#define VTSI_SUPPORT 1

Binary file not shown.