diff options
author | Robin Hübner <profan@prfn.se> | 2019-08-09 06:49:33 +0200 |
---|---|---|
committer | Robin Hübner <profan@prfn.se> | 2019-08-09 11:13:24 +0200 |
commit | 6ab118c4646b136cd83ff8406ce62a2576809def (patch) | |
tree | 7dc10741d9b7c609951f3568e31479257311c59b /platform/windows | |
parent | 22b42c3315081144ecea26e4a51600255dc8eed6 (diff) |
Replace 'ERR_EXPLAIN' with 'ERR_FAIL_*_MSG' in "platform", "modules/gdnative", "modules/gdscript" directories.
Diffstat (limited to 'platform/windows')
-rw-r--r-- | platform/windows/os_windows.cpp | 58 |
1 files changed, 15 insertions, 43 deletions
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index db4575a0cb..a6ce9148f0 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -1435,16 +1435,13 @@ void OS_Windows::set_clipboard(const String &p_text) { String text = p_text.replace("\n", "\r\n"); if (!OpenClipboard(hWnd)) { - ERR_EXPLAIN("Unable to open clipboard."); - ERR_FAIL(); - }; + ERR_FAIL_MSG("Unable to open clipboard."); + } EmptyClipboard(); HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE, (text.length() + 1) * sizeof(CharType)); - if (mem == NULL) { - ERR_EXPLAIN("Unable to allocate memory for clipboard contents."); - ERR_FAIL(); - }; + ERR_FAIL_COND_MSG(mem == NULL, "Unable to allocate memory for clipboard contents."); + LPWSTR lptstrCopy = (LPWSTR)GlobalLock(mem); memcpy(lptstrCopy, text.c_str(), (text.length() + 1) * sizeof(CharType)); GlobalUnlock(mem); @@ -1454,10 +1451,8 @@ void OS_Windows::set_clipboard(const String &p_text) { // set the CF_TEXT version (not needed?) CharString utf8 = text.utf8(); mem = GlobalAlloc(GMEM_MOVEABLE, utf8.length() + 1); - if (mem == NULL) { - ERR_EXPLAIN("Unable to allocate memory for clipboard contents."); - ERR_FAIL(); - }; + ERR_FAIL_COND_MSG(mem == NULL, "Unable to allocate memory for clipboard contents."); + LPTSTR ptr = (LPTSTR)GlobalLock(mem); memcpy(ptr, utf8.get_data(), utf8.length()); ptr[utf8.length()] = 0; @@ -1472,8 +1467,7 @@ String OS_Windows::get_clipboard() const { String ret; if (!OpenClipboard(hWnd)) { - ERR_EXPLAIN("Unable to open clipboard."); - ERR_FAIL_V(""); + ERR_FAIL_V_MSG("", "Unable to open clipboard."); }; if (IsClipboardFormatAvailable(CF_UNICODETEXT)) { @@ -2135,15 +2129,12 @@ Error OS_Windows::open_dynamic_library(const String p_path, void *&p_library_han } p_library_handle = (void *)LoadLibraryExW(path.c_str(), NULL, (p_also_set_library_path && has_dll_directory_api) ? LOAD_LIBRARY_SEARCH_DEFAULT_DIRS : 0); + ERR_FAIL_COND_V_MSG(!p_library_handle, ERR_CANT_OPEN, "Can't open dynamic library: " + p_path + ", error: " + format_error_message(GetLastError()) + "."); if (cookie) { remove_dll_directory(cookie); } - if (!p_library_handle) { - ERR_EXPLAIN("Can't open dynamic library: " + p_path + ". Error: " + format_error_message(GetLastError())); - ERR_FAIL_V(ERR_CANT_OPEN); - } return OK; } @@ -2158,8 +2149,7 @@ Error OS_Windows::get_dynamic_library_symbol_handle(void *p_library_handle, cons p_symbol_handle = (void *)GetProcAddress((HMODULE)p_library_handle, p_name.utf8().get_data()); if (!p_symbol_handle) { if (!p_optional) { - ERR_EXPLAIN("Can't resolve symbol " + p_name + ". Error: " + String::num(GetLastError())); - ERR_FAIL_V(ERR_CANT_RESOLVE); + ERR_FAIL_V_MSG(ERR_CANT_RESOLVE, "Can't resolve symbol " + p_name + ", error: " + String::num(GetLastError()) + "."); } else { return ERR_CANT_RESOLVE; } @@ -2686,10 +2676,7 @@ void OS_Windows::set_native_icon(const String &p_filename) { pos += sizeof(WORD); f->seek(pos); - if (icon_dir->idType != 1) { - ERR_EXPLAIN("Invalid icon file format!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(icon_dir->idType != 1, "Invalid icon file format!"); icon_dir->idCount = f->get_32(); pos += sizeof(WORD); @@ -2722,10 +2709,7 @@ void OS_Windows::set_native_icon(const String &p_filename) { } } - if (big_icon_index == -1) { - ERR_EXPLAIN("No valid icons found!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(big_icon_index == -1, "No valid icons found!"); if (small_icon_index == -1) { WARN_PRINTS("No small icon found, reusing " + itos(big_icon_width) + "x" + itos(big_icon_width) + " @" + itos(big_icon_cc) + " icon!"); @@ -2741,10 +2725,7 @@ void OS_Windows::set_native_icon(const String &p_filename) { f->seek(pos); f->get_buffer((uint8_t *)&data_big.write[0], bytecount_big); HICON icon_big = CreateIconFromResource((PBYTE)&data_big.write[0], bytecount_big, TRUE, 0x00030000); - if (!icon_big) { - ERR_EXPLAIN("Could not create " + itos(big_icon_width) + "x" + itos(big_icon_width) + " @" + itos(big_icon_cc) + " icon, error: " + format_error_message(GetLastError())); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!icon_big, "Could not create " + itos(big_icon_width) + "x" + itos(big_icon_width) + " @" + itos(big_icon_cc) + " icon, error: " + format_error_message(GetLastError()) + "."); // Read the small icon DWORD bytecount_small = icon_dir->idEntries[small_icon_index].dwBytesInRes; @@ -2754,10 +2735,7 @@ void OS_Windows::set_native_icon(const String &p_filename) { f->seek(pos); f->get_buffer((uint8_t *)&data_small.write[0], bytecount_small); HICON icon_small = CreateIconFromResource((PBYTE)&data_small.write[0], bytecount_small, TRUE, 0x00030000); - if (!icon_small) { - ERR_EXPLAIN("Could not create 16x16 @" + itos(small_icon_cc) + " icon, error: " + format_error_message(GetLastError())); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!icon_small, "Could not create 16x16 @" + itos(small_icon_cc) + " icon, error: " + format_error_message(GetLastError()) + "."); // Online tradition says to be sure last error is cleared and set the small icon first int err = 0; @@ -2765,17 +2743,11 @@ void OS_Windows::set_native_icon(const String &p_filename) { SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)icon_small); err = GetLastError(); - if (err) { - ERR_EXPLAIN("Error setting ICON_SMALL: " + format_error_message(err)); - ERR_FAIL(); - } + ERR_FAIL_COND(err, "Error setting ICON_SMALL: " + format_error_message(err) + "."); SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)icon_big); err = GetLastError(); - if (err) { - ERR_EXPLAIN("Error setting ICON_BIG: " + format_error_message(err)); - ERR_FAIL(); - } + ERR_FAIL_COND(err, "Error setting ICON_BIG: " + format_error_message(err) + "."); memdelete(f); memdelete(icon_dir); |