diff --git a/ExplorerPatcher/GUI.c b/ExplorerPatcher/GUI.c index 24b3b59..a7d639e 100644 --- a/ExplorerPatcher/GUI.c +++ b/ExplorerPatcher/GUI.c @@ -1829,9 +1829,9 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) } else { - WCHAR* wszTitle = malloc(MAX_LINE_LENGTH * sizeof(WCHAR)); - wchar_t* x = wcschr(ddd + 2, L'"'); - x[0] = 0; + //WCHAR* wszTitle = malloc(MAX_LINE_LENGTH * sizeof(WCHAR)); + //wchar_t* x = wcschr(ddd + 2, L'"'); + //x[0] = 0; //wprintf(L">>> %s\n", ddd + 2); } } @@ -2359,18 +2359,28 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt) DWORD val = 0; if (bInput) { - WCHAR* wszAnswer = malloc(MAX_LINE_LENGTH * sizeof(WCHAR)); - InputBox(FALSE, hwnd, wszPrompt, wszTitle, wszDefault, wszAnswer, MAX_LINE_LENGTH); - GUI_RegSetValueExW( - hKey, - name, - 0, - REG_SZ, - wszAnswer, - (wcslen(wszAnswer) + 1) * sizeof(WCHAR) - ); - Sleep(100); - PostMessageW(FindWindowW(_T(EPW_WEATHER_CLASSNAME), NULL), EP_WEATHER_WM_FETCH_DATA, 0, 0); + WCHAR* wszAnswer = calloc(MAX_LINE_LENGTH, sizeof(WCHAR)); + BOOL bWasCancelled = FALSE; + if (SUCCEEDED(InputBox(FALSE, hwnd, wszPrompt, wszTitle, wszDefault, wszAnswer, MAX_LINE_LENGTH, &bWasCancelled)) && !bWasCancelled) + { + if (wszAnswer[0]) + { + GUI_RegSetValueExW( + hKey, + name, + 0, + REG_SZ, + wszAnswer, + (wcslen(wszAnswer) + 1) * sizeof(WCHAR) + ); + } + else + { + RegDeleteValueW(hKey, name); + } + Sleep(100); + PostMessageW(FindWindowW(_T(EPW_WEATHER_CLASSNAME), NULL), EP_WEATHER_WM_FETCH_DATA, 0, 0); + } free(wszAnswer); } else if (bChoice || bChoiceLefted) diff --git a/ExplorerPatcher/utility.c b/ExplorerPatcher/utility.c index 052fa10..82f43e7 100644 --- a/ExplorerPatcher/utility.c +++ b/ExplorerPatcher/utility.c @@ -1088,10 +1088,15 @@ static LRESULT CALLBACK InputBoxProc(int nCode, WPARAM wParam, LPARAM lParam) { return CallNextHookEx(0, nCode, wParam, lParam); } -HRESULT InputBox(BOOL bPassword, HWND hWnd, LPCWSTR wszPrompt, LPCWSTR wszTitle, LPCWSTR wszDefault, LPCWSTR wszAnswer, DWORD cbAnswer) +HRESULT InputBox(BOOL bPassword, HWND hWnd, LPCWSTR wszPrompt, LPCWSTR wszTitle, LPCWSTR wszDefault, LPWSTR wszAnswer, DWORD cbAnswer, BOOL* bCancelled) { HRESULT hr = S_OK; + if (!wszPrompt || !wszTitle || !wszDefault || !wszAnswer || !cbAnswer || !bCancelled) + { + return E_FAIL; + } + GUID guidBuffer; hr = getEngineGuid(L".vbs", &guidBuffer); @@ -1162,11 +1167,23 @@ HRESULT InputBox(BOOL bPassword, HWND hWnd, LPCWSTR wszPrompt, LPCWSTR wszTitle, HideInput = bPassword; hr = pActiveScriptParse->lpVtbl->ParseScriptText(pActiveScriptParse, wszEvaluation2, NULL, NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &result, &ei); + *bCancelled = (result.vt == VT_EMPTY); + UnhookWindowsHookEx(hHook); free(wszEvaluation2); - memcpy(wszAnswer, result.bstrVal, cbAnswer * sizeof(WCHAR)); + if (result.bstrVal) + { + memcpy(wszAnswer, result.bstrVal, cbAnswer * sizeof(WCHAR)); + } + else + { + if (result.vt != VT_EMPTY) + { + wszAnswer[0] = 0; + } + } VariantClear(&result); } diff --git a/ExplorerPatcher/utility.h b/ExplorerPatcher/utility.h index e9bc319..a9a77da 100644 --- a/ExplorerPatcher/utility.h +++ b/ExplorerPatcher/utility.h @@ -249,7 +249,7 @@ char* StrReplaceAllA(const char* s, const char* oldW, const char* newW, int* dwN WCHAR* StrReplaceAllW(const WCHAR* s, const WCHAR* oldW, const WCHAR* newW, int* dwNewSize); -HRESULT InputBox(BOOL bPassword, HWND hWnd, LPCWSTR wszPrompt, LPCWSTR wszTitle, LPCWSTR wszDefault, LPCWSTR wszAnswer, DWORD cbAnswer); +HRESULT InputBox(BOOL bPassword, HWND hWnd, LPCWSTR wszPrompt, LPCWSTR wszTitle, LPCWSTR wszDefault, LPWSTR wszAnswer, DWORD cbAnswer, BOOL* bCancelled); inline BOOL IsHighContrast() {