| 79 | |
| 80 | |
| 81 | bool downloadFile(BString url, BString filePath, std::function<void(U64 bytesCompleted)> f, NetworkProxy* proxy, BString& errorMsg, bool* cancel) { |
| 82 | DownloadProgress progress; |
| 83 | progress.cancel = cancel; |
| 84 | progress.f = f; |
| 85 | |
| 86 | HRESULT hr = URLDownloadToFile(nullptr, url.c_str(), filePath.c_str(), 0, &progress); |
| 87 | if (hr != S_OK) { |
| 88 | LPSTR messageBuffer = nullptr; |
| 89 | // the use of FORMAT_MESSAGE_ALLOCATE_BUFFER causes this funky cast |
| 90 | LPSTR pArg = reinterpret_cast<LPSTR>(&messageBuffer); |
| 91 | FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), pArg, 0, nullptr); |
| 92 | errorMsg = BString::copy(messageBuffer); |
| 93 | LocalFree(messageBuffer); |
| 94 | } |
| 95 | return hr == S_OK; |
| 96 | } |
| 97 | |
| 98 | #else |
| 99 | #include <curl/curl.h> |
no test coverage detected