Skip to content

Commit

Permalink
[ui] improve Windows format prompt autoclose
Browse files Browse the repository at this point in the history
* Closes pbatard#794
* Also reorder some messages (so that RUFUS_TEST comes first)
* Also update issue template
  • Loading branch information
pbatard committed Jul 9, 2016
1 parent cebfa4c commit 9dd06e9
Show file tree
Hide file tree
Showing 8 changed files with 297 additions and 205 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE.md
@@ -1,7 +1,7 @@
<PLEASE READ THIS CAREFULLY: You *MUST* read and complete the checklist below, by placing an x into each [ ], BEFORE clicking on 'Submit new issue'. Failure to perform these steps, WHICH ARE ONLY THERE TO HELP *YOU*, will result in the issue being dismissed without warning.>

Checklist
---------
<Please complete the following and place an x into each [ ] to confirm that you have read and performed these preliminary steps>

- [ ] I looked at https://github.com/pbatard/rufus/wiki/FAQ to see if my question has already been answered.
- [ ] I performed a search in the issue tracker for similar issues, using keywords relevant to my problem.
- [ ] I clicked the `Log` button in Rufus and copy/pasted the log into the line that says `<FULL LOG>` below.
Expand Down
47 changes: 1 addition & 46 deletions src/format.c
Expand Up @@ -825,7 +825,7 @@ static BOOL ClearMBRGPT(HANDLE hPhysicalDrive, LONGLONG DiskSize, DWORD SectorSi
// Also, for various reasons (one of which being that Windows seems to have issues
// with GPT drives that contain a lot of small partitions) we try not not to clear
// sectors further than the lowest partition already residing on the disk.
num_sectors_to_clear = min(SelectedDrive.FirstDataSector, (add1MB ? 2048 : 0) + MAX_SECTORS_TO_CLEAR);
num_sectors_to_clear = min(SelectedDrive.FirstDataSector, (DWORD)((add1MB ? 2048 : 0) + MAX_SECTORS_TO_CLEAR));
uprintf("Erasing %d sectors", num_sectors_to_clear);
for (i=0; i<num_sectors_to_clear; i++) {
if ((IS_ERROR(FormatStatus)) || (write_sectors(hPhysicalDrive, SectorSize, i, 1, pBuf) != SectorSize)) {
Expand Down Expand Up @@ -1406,50 +1406,6 @@ static BOOL SetupWinToGo(const char* drive_name, BOOL use_ms_efi)
return TRUE;
}

/*
* Detect if a Windows Format prompt is active, by enumerating the
* whole Windows tree and looking for the relevant popup
*/
static BOOL CALLBACK FormatPromptCallback(HWND hWnd, LPARAM lParam)
{
char str_buf[MAX_PATH];
HWND *hFound = (HWND*)lParam;
static const char* security_string = "Microsoft Windows";

// The format prompt has the popup window style
if (GetWindowLong(hWnd, GWL_STYLE) & WS_POPUPWINDOW) {
str_buf[0] = 0;
GetWindowTextA(hWnd, str_buf, MAX_PATH);
str_buf[MAX_PATH-1] = 0;
if (safe_strcmp(str_buf, security_string) == 0) {
*hFound = hWnd;
return TRUE;
}
}
return TRUE;
}

/*
* When we format a drive that doesn't have any existing partitions, we can't lock it
* prior to partitioning, which means that Windows will display a "You need to format the
* disk in drive X: before you can use it'. You will also get that popup if you start a
* bad blocks check and cancel it before it completes. We have to close that popup manually.
*/
static DWORD WINAPI CloseFormatPromptThread(LPVOID param) {
HWND hFormatPrompt;

while(format_op_in_progress) {
hFormatPrompt = NULL;
EnumChildWindows(GetDesktopWindow(), FormatPromptCallback, (LPARAM)&hFormatPrompt);
if (hFormatPrompt != NULL) {
SendMessage(hFormatPrompt, WM_COMMAND, (WPARAM)IDCANCEL, (LPARAM)0);
uprintf("Closed Windows format prompt\n");
}
Sleep(100);
}
ExitThread(0);
}

static void update_progress(const uint64_t processed_bytes)
{
if (_GetTickCount64() > LastRefresh + MAX_REFRESH) {
Expand Down Expand Up @@ -1687,7 +1643,6 @@ DWORD WINAPI FormatThread(void* param)
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_PARTITION_FAILURE;
goto out;
}
CreateThread(NULL, 0, CloseFormatPromptThread, NULL, 0, NULL);

if (IsChecked(IDC_BADBLOCKS)) {
do {
Expand Down
23 changes: 23 additions & 0 deletions src/msapi_utf8.h
Expand Up @@ -226,6 +226,21 @@ static __inline int MessageBoxExU(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UI
return ret;
}

static __inline int LoadStringU(HINSTANCE hInstance, UINT uID, LPSTR lpBuffer, int nBufferMax)
{
int ret;
DWORD err = ERROR_INVALID_DATA;
walloc(lpBuffer, nBufferMax);
ret = LoadStringW(hInstance, uID, wlpBuffer, nBufferMax);
err = GetLastError();
if ((ret > 0) && ((ret = wchar_to_utf8_no_alloc(wlpBuffer, lpBuffer, nBufferMax)) == 0)) {
err = GetLastError();
}
wfree(lpBuffer);
SetLastError(err);
return ret;
}

static __inline int DrawTextU(HDC hDC, LPCSTR lpText, int nCount, LPRECT lpRect, UINT uFormat)
{
int ret;
Expand Down Expand Up @@ -917,6 +932,14 @@ static __inline BOOL GetVolumeInformationU(LPCSTR lpRootPathName, LPSTR lpVolume
return ret;
}

static __inline HMODULE LoadLibraryU(LPCSTR lpFileName)
{
HMODULE h;
wconvert(lpFileName);
h = LoadLibraryW(wlpFileName);
wfree(lpFileName);
return h;
}

#ifdef __cplusplus
}
Expand Down

0 comments on commit 9dd06e9

Please sign in to comment.