diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2021-03-02 14:19:14 -0600 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2021-03-02 15:40:02 -0600 |
| commit | 10ebf674da5df9224e4eddd3545518434c5b455b (patch) | |
| tree | ea1f4063edd46e9942eab94dd7adb2f75c6c589e /src/dutil/dlutil.cpp | |
| parent | 3bbf1347b900ec115a12faf8f46965c9b7649696 (diff) | |
| download | wix-10ebf674da5df9224e4eddd3545518434c5b455b.tar.gz wix-10ebf674da5df9224e4eddd3545518434c5b455b.tar.bz2 wix-10ebf674da5df9224e4eddd3545518434c5b455b.zip | |
Update rest of dutil to use their own source with the Exit* macros.
Fix some CA warnings.
Diffstat (limited to 'src/dutil/dlutil.cpp')
| -rw-r--r-- | src/dutil/dlutil.cpp | 89 |
1 files changed, 52 insertions, 37 deletions
diff --git a/src/dutil/dlutil.cpp b/src/dutil/dlutil.cpp index 1b30f410..70155e6f 100644 --- a/src/dutil/dlutil.cpp +++ b/src/dutil/dlutil.cpp | |||
| @@ -5,6 +5,21 @@ | |||
| 5 | #include <inetutil.h> | 5 | #include <inetutil.h> |
| 6 | #include <uriutil.h> | 6 | #include <uriutil.h> |
| 7 | 7 | ||
| 8 | |||
| 9 | // Exit macros | ||
| 10 | #define DlExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_DLUTIL, x, s, __VA_ARGS__) | ||
| 11 | #define DlExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_DLUTIL, x, s, __VA_ARGS__) | ||
| 12 | #define DlExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_DLUTIL, x, s, __VA_ARGS__) | ||
| 13 | #define DlExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_DLUTIL, x, s, __VA_ARGS__) | ||
| 14 | #define DlExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_DLUTIL, x, s, __VA_ARGS__) | ||
| 15 | #define DlExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_DLUTIL, x, s, __VA_ARGS__) | ||
| 16 | #define DlExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_DLUTIL, p, x, e, s, __VA_ARGS__) | ||
| 17 | #define DlExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_DLUTIL, p, x, s, __VA_ARGS__) | ||
| 18 | #define DlExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_DLUTIL, p, x, e, s, __VA_ARGS__) | ||
| 19 | #define DlExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DLUTIL, p, x, s, __VA_ARGS__) | ||
| 20 | #define DlExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DLUTIL, e, x, s, __VA_ARGS__) | ||
| 21 | #define DlExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DLUTIL, g, x, s, __VA_ARGS__) | ||
| 22 | |||
| 8 | static const DWORD64 DOWNLOAD_ENGINE_TWO_GIGABYTES = DWORD64(2) * 1024 * 1024 * 1024; | 23 | static const DWORD64 DOWNLOAD_ENGINE_TWO_GIGABYTES = DWORD64(2) * 1024 * 1024 * 1024; |
| 9 | static LPCWSTR DOWNLOAD_ENGINE_ACCEPT_TYPES[] = { L"*/*", NULL }; | 24 | static LPCWSTR DOWNLOAD_ENGINE_ACCEPT_TYPES[] = { L"*/*", NULL }; |
| 10 | 25 | ||
| @@ -41,7 +56,7 @@ static HRESULT DownloadResource( | |||
| 41 | static HRESULT AllocateRangeRequestHeader( | 56 | static HRESULT AllocateRangeRequestHeader( |
| 42 | __in DWORD64 dw64ResumeOffset, | 57 | __in DWORD64 dw64ResumeOffset, |
| 43 | __in DWORD64 dw64ResourceLength, | 58 | __in DWORD64 dw64ResourceLength, |
| 44 | __deref_out_z LPWSTR* psczHeader | 59 | __deref_inout_z LPWSTR* psczHeader |
| 45 | ); | 60 | ); |
| 46 | static HRESULT WriteToFile( | 61 | static HRESULT WriteToFile( |
| 47 | __in HINTERNET hUrl, | 62 | __in HINTERNET hUrl, |
| @@ -126,10 +141,10 @@ extern "C" HRESULT DAPI DownloadUrl( | |||
| 126 | // Copy the download source into a working variable to handle redirects then | 141 | // Copy the download source into a working variable to handle redirects then |
| 127 | // open the internet session. | 142 | // open the internet session. |
| 128 | hr = StrAllocString(&sczUrl, pDownloadSource->sczUrl, 0); | 143 | hr = StrAllocString(&sczUrl, pDownloadSource->sczUrl, 0); |
| 129 | ExitOnFailure(hr, "Failed to copy download source URL."); | 144 | DlExitOnFailure(hr, "Failed to copy download source URL."); |
| 130 | 145 | ||
| 131 | hSession = ::InternetOpenW(L"Burn", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); | 146 | hSession = ::InternetOpenW(L"Burn", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); |
| 132 | ExitOnNullWithLastError(hSession, hr, "Failed to open internet session"); | 147 | DlExitOnNullWithLastError(hSession, hr, "Failed to open internet session"); |
| 133 | 148 | ||
| 134 | // Make a best effort to set the download timeouts to 2 minutes or whatever policy says. | 149 | // Make a best effort to set the download timeouts to 2 minutes or whatever policy says. |
| 135 | PolcReadNumber(POLICY_BURN_REGISTRY_PATH, L"DownloadTimeout", 2 * 60, &dwTimeout); | 150 | PolcReadNumber(POLICY_BURN_REGISTRY_PATH, L"DownloadTimeout", 2 * 60, &dwTimeout); |
| @@ -143,14 +158,14 @@ extern "C" HRESULT DAPI DownloadUrl( | |||
| 143 | 158 | ||
| 144 | // Get the resource size and creation time from the internet. | 159 | // Get the resource size and creation time from the internet. |
| 145 | hr = GetResourceMetadata(hSession, &sczUrl, pDownloadSource->sczUser, pDownloadSource->sczPassword, pAuthenticate, &dw64Size, &ftCreated); | 160 | hr = GetResourceMetadata(hSession, &sczUrl, pDownloadSource->sczUser, pDownloadSource->sczPassword, pAuthenticate, &dw64Size, &ftCreated); |
| 146 | ExitOnFailure(hr, "Failed to get size and time for URL: %ls", sczUrl); | 161 | DlExitOnFailure(hr, "Failed to get size and time for URL: %ls", sczUrl); |
| 147 | 162 | ||
| 148 | // Ignore failure to initialize resume because we will fall back to full download then | 163 | // Ignore failure to initialize resume because we will fall back to full download then |
| 149 | // download. | 164 | // download. |
| 150 | InitializeResume(wzDestinationPath, &sczResumePath, &hResumeFile, &dw64ResumeOffset); | 165 | InitializeResume(wzDestinationPath, &sczResumePath, &hResumeFile, &dw64ResumeOffset); |
| 151 | 166 | ||
| 152 | hr = DownloadResource(hSession, &sczUrl, pDownloadSource->sczUser, pDownloadSource->sczPassword, wzDestinationPath, dw64AuthoredDownloadSize, dw64Size, dw64ResumeOffset, hResumeFile, pCache, pAuthenticate); | 167 | hr = DownloadResource(hSession, &sczUrl, pDownloadSource->sczUser, pDownloadSource->sczPassword, wzDestinationPath, dw64AuthoredDownloadSize, dw64Size, dw64ResumeOffset, hResumeFile, pCache, pAuthenticate); |
| 153 | ExitOnFailure(hr, "Failed to download URL: %ls", sczUrl); | 168 | DlExitOnFailure(hr, "Failed to download URL: %ls", sczUrl); |
| 154 | 169 | ||
| 155 | // Cleanup the resume file because we successfully downloaded the whole file. | 170 | // Cleanup the resume file because we successfully downloaded the whole file. |
| 156 | if (sczResumePath && *sczResumePath) | 171 | if (sczResumePath && *sczResumePath) |
| @@ -185,19 +200,19 @@ static HRESULT InitializeResume( | |||
| 185 | *pdw64ResumeOffset = 0; | 200 | *pdw64ResumeOffset = 0; |
| 186 | 201 | ||
| 187 | hr = DownloadGetResumePath(wzDestinationPath, psczResumePath); | 202 | hr = DownloadGetResumePath(wzDestinationPath, psczResumePath); |
| 188 | ExitOnFailure(hr, "Failed to calculate resume path from working path: %ls", wzDestinationPath); | 203 | DlExitOnFailure(hr, "Failed to calculate resume path from working path: %ls", wzDestinationPath); |
| 189 | 204 | ||
| 190 | hResumeFile = ::CreateFileW(*psczResumePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); | 205 | hResumeFile = ::CreateFileW(*psczResumePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
| 191 | if (INVALID_HANDLE_VALUE == hResumeFile) | 206 | if (INVALID_HANDLE_VALUE == hResumeFile) |
| 192 | { | 207 | { |
| 193 | ExitWithLastError(hr, "Failed to create resume file: %ls", *psczResumePath); | 208 | DlExitWithLastError(hr, "Failed to create resume file: %ls", *psczResumePath); |
| 194 | } | 209 | } |
| 195 | 210 | ||
| 196 | do | 211 | do |
| 197 | { | 212 | { |
| 198 | if (!::ReadFile(hResumeFile, reinterpret_cast<BYTE*>(pdw64ResumeOffset) + cbTotalReadResumeData, sizeof(DWORD64) - cbTotalReadResumeData, &cbReadData, NULL)) | 213 | if (!::ReadFile(hResumeFile, reinterpret_cast<BYTE*>(pdw64ResumeOffset) + cbTotalReadResumeData, sizeof(DWORD64) - cbTotalReadResumeData, &cbReadData, NULL)) |
| 199 | { | 214 | { |
| 200 | ExitWithLastError(hr, "Failed to read resume file: %ls", *psczResumePath); | 215 | DlExitWithLastError(hr, "Failed to read resume file: %ls", *psczResumePath); |
| 201 | } | 216 | } |
| 202 | cbTotalReadResumeData += cbReadData; | 217 | cbTotalReadResumeData += cbReadData; |
| 203 | } while (cbReadData && sizeof(DWORD64) > cbTotalReadResumeData); | 218 | } while (cbReadData && sizeof(DWORD64) > cbTotalReadResumeData); |
| @@ -233,7 +248,7 @@ static HRESULT GetResourceMetadata( | |||
| 233 | LONGLONG llLength = 0; | 248 | LONGLONG llLength = 0; |
| 234 | 249 | ||
| 235 | hr = MakeRequest(hSession, psczUrl, L"HEAD", NULL, wzUser, wzPassword, pAuthenticate, &hConnect, &hUrl, &fRangeRequestsAccepted); | 250 | hr = MakeRequest(hSession, psczUrl, L"HEAD", NULL, wzUser, wzPassword, pAuthenticate, &hConnect, &hUrl, &fRangeRequestsAccepted); |
| 236 | ExitOnFailure(hr, "Failed to connect to URL: %ls", *psczUrl); | 251 | DlExitOnFailure(hr, "Failed to connect to URL: %ls", *psczUrl); |
| 237 | 252 | ||
| 238 | hr = InternetGetSizeByHandle(hUrl, &llLength); | 253 | hr = InternetGetSizeByHandle(hUrl, &llLength); |
| 239 | if (FAILED(hr)) | 254 | if (FAILED(hr)) |
| @@ -286,12 +301,12 @@ static HRESULT DownloadResource( | |||
| 286 | hPayloadFile = ::CreateFileW(wzDestinationPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); | 301 | hPayloadFile = ::CreateFileW(wzDestinationPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
| 287 | if (INVALID_HANDLE_VALUE == hPayloadFile) | 302 | if (INVALID_HANDLE_VALUE == hPayloadFile) |
| 288 | { | 303 | { |
| 289 | ExitWithLastError(hr, "Failed to create download destination file: %ls", wzDestinationPath); | 304 | DlExitWithLastError(hr, "Failed to create download destination file: %ls", wzDestinationPath); |
| 290 | } | 305 | } |
| 291 | 306 | ||
| 292 | // Allocate a memory block on a page boundary in case we want to do optimal writing. | 307 | // Allocate a memory block on a page boundary in case we want to do optimal writing. |
| 293 | pbData = static_cast<BYTE*>(::VirtualAlloc(NULL, cbMaxData, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); | 308 | pbData = static_cast<BYTE*>(::VirtualAlloc(NULL, cbMaxData, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); |
| 294 | ExitOnNullWithLastError(pbData, hr, "Failed to allocate buffer to download files into."); | 309 | DlExitOnNullWithLastError(pbData, hr, "Failed to allocate buffer to download files into."); |
| 295 | 310 | ||
| 296 | // Let's try downloading the file assuming that range requests are accepted. If range requests | 311 | // Let's try downloading the file assuming that range requests are accepted. If range requests |
| 297 | // are not supported we'll have to start over and accept the fact that we only get one shot | 312 | // are not supported we'll have to start over and accept the fact that we only get one shot |
| @@ -300,13 +315,13 @@ static HRESULT DownloadResource( | |||
| 300 | while (fRangeRequestsAccepted && (0 == dw64ResourceLength || dw64ResumeOffset < dw64ResourceLength)) | 315 | while (fRangeRequestsAccepted && (0 == dw64ResourceLength || dw64ResumeOffset < dw64ResourceLength)) |
| 301 | { | 316 | { |
| 302 | hr = AllocateRangeRequestHeader(dw64ResumeOffset, 0 == dw64ResourceLength ? dw64AuthoredResourceLength : dw64ResourceLength, &sczRangeRequestHeader); | 317 | hr = AllocateRangeRequestHeader(dw64ResumeOffset, 0 == dw64ResourceLength ? dw64AuthoredResourceLength : dw64ResourceLength, &sczRangeRequestHeader); |
| 303 | ExitOnFailure(hr, "Failed to allocate range request header."); | 318 | DlExitOnFailure(hr, "Failed to allocate range request header."); |
| 304 | 319 | ||
| 305 | ReleaseNullInternet(hConnect); | 320 | ReleaseNullInternet(hConnect); |
| 306 | ReleaseNullInternet(hUrl); | 321 | ReleaseNullInternet(hUrl); |
| 307 | 322 | ||
| 308 | hr = MakeRequest(hSession, psczUrl, L"GET", sczRangeRequestHeader, wzUser, wzPassword, pAuthenticate, &hConnect, &hUrl, &fRangeRequestsAccepted); | 323 | hr = MakeRequest(hSession, psczUrl, L"GET", sczRangeRequestHeader, wzUser, wzPassword, pAuthenticate, &hConnect, &hUrl, &fRangeRequestsAccepted); |
| 309 | ExitOnFailure(hr, "Failed to request URL for download: %ls", *psczUrl); | 324 | DlExitOnFailure(hr, "Failed to request URL for download: %ls", *psczUrl); |
| 310 | 325 | ||
| 311 | // If we didn't get the size of the resource from the initial "HEAD" request | 326 | // If we didn't get the size of the resource from the initial "HEAD" request |
| 312 | // then let's try to get the size from this "GET" request. | 327 | // then let's try to get the size from this "GET" request. |
| @@ -335,7 +350,7 @@ static HRESULT DownloadResource( | |||
| 335 | } | 350 | } |
| 336 | 351 | ||
| 337 | hr = WriteToFile(hUrl, hPayloadFile, &dw64ResumeOffset, hResumeFile, dw64ResourceLength, pbData, cbMaxData, pCache); | 352 | hr = WriteToFile(hUrl, hPayloadFile, &dw64ResumeOffset, hResumeFile, dw64ResourceLength, pbData, cbMaxData, pCache); |
| 338 | ExitOnFailure(hr, "Failed while reading from internet and writing to: %ls", wzDestinationPath); | 353 | DlExitOnFailure(hr, "Failed while reading from internet and writing to: %ls", wzDestinationPath); |
| 339 | } | 354 | } |
| 340 | 355 | ||
| 341 | LExit: | 356 | LExit: |
| @@ -354,7 +369,7 @@ LExit: | |||
| 354 | static HRESULT AllocateRangeRequestHeader( | 369 | static HRESULT AllocateRangeRequestHeader( |
| 355 | __in DWORD64 dw64ResumeOffset, | 370 | __in DWORD64 dw64ResumeOffset, |
| 356 | __in DWORD64 dw64ResourceLength, | 371 | __in DWORD64 dw64ResourceLength, |
| 357 | __deref_out_z LPWSTR* psczHeader | 372 | __deref_inout_z LPWSTR* psczHeader |
| 358 | ) | 373 | ) |
| 359 | { | 374 | { |
| 360 | HRESULT hr = S_OK; | 375 | HRESULT hr = S_OK; |
| @@ -368,7 +383,7 @@ static HRESULT AllocateRangeRequestHeader( | |||
| 368 | if (0 < dw64ResumeOffset) | 383 | if (0 < dw64ResumeOffset) |
| 369 | { | 384 | { |
| 370 | hr = StrAllocFormatted(psczHeader, L"Range: bytes=%I64u-", dw64ResumeOffset); | 385 | hr = StrAllocFormatted(psczHeader, L"Range: bytes=%I64u-", dw64ResumeOffset); |
| 371 | ExitOnFailure(hr, "Failed to add range read header."); | 386 | DlExitOnFailure(hr, "Failed to add range read header."); |
| 372 | } | 387 | } |
| 373 | else | 388 | else |
| 374 | { | 389 | { |
| @@ -378,7 +393,7 @@ static HRESULT AllocateRangeRequestHeader( | |||
| 378 | else // we'll have to download in chunks. | 393 | else // we'll have to download in chunks. |
| 379 | { | 394 | { |
| 380 | hr = StrAllocFormatted(psczHeader, L"Range: bytes=%I64u-%I64u", dw64ResumeOffset, dw64ResumeOffset + dw64RemainingLength - 1); | 395 | hr = StrAllocFormatted(psczHeader, L"Range: bytes=%I64u-%I64u", dw64ResumeOffset, dw64ResumeOffset + dw64RemainingLength - 1); |
| 381 | ExitOnFailure(hr, "Failed to add range read header."); | 396 | DlExitOnFailure(hr, "Failed to add range read header."); |
| 382 | } | 397 | } |
| 383 | 398 | ||
| 384 | LExit: | 399 | LExit: |
| @@ -400,14 +415,14 @@ static HRESULT WriteToFile( | |||
| 400 | DWORD cbReadData = 0; | 415 | DWORD cbReadData = 0; |
| 401 | 416 | ||
| 402 | hr = FileSetPointer(hPayloadFile, *pdw64ResumeOffset, NULL, FILE_BEGIN); | 417 | hr = FileSetPointer(hPayloadFile, *pdw64ResumeOffset, NULL, FILE_BEGIN); |
| 403 | ExitOnFailure(hr, "Failed to seek to start point in file."); | 418 | DlExitOnFailure(hr, "Failed to seek to start point in file."); |
| 404 | 419 | ||
| 405 | do | 420 | do |
| 406 | { | 421 | { |
| 407 | // Read bits from the internet. | 422 | // Read bits from the internet. |
| 408 | if (!::InternetReadFile(hUrl, static_cast<void*>(pbData), cbData, &cbReadData)) | 423 | if (!::InternetReadFile(hUrl, static_cast<void*>(pbData), cbData, &cbReadData)) |
| 409 | { | 424 | { |
| 410 | ExitWithLastError(hr, "Failed while reading from internet."); | 425 | DlExitWithLastError(hr, "Failed while reading from internet."); |
| 411 | } | 426 | } |
| 412 | 427 | ||
| 413 | // Write bits to disk (if there are any). | 428 | // Write bits to disk (if there are any). |
| @@ -419,7 +434,7 @@ static HRESULT WriteToFile( | |||
| 419 | { | 434 | { |
| 420 | if (!::WriteFile(hPayloadFile, pbData + cbTotalWritten, cbReadData - cbTotalWritten, &cbWritten, NULL)) | 435 | if (!::WriteFile(hPayloadFile, pbData + cbTotalWritten, cbReadData - cbTotalWritten, &cbWritten, NULL)) |
| 421 | { | 436 | { |
| 422 | ExitWithLastError(hr, "Failed to write data from internet."); | 437 | DlExitWithLastError(hr, "Failed to write data from internet."); |
| 423 | } | 438 | } |
| 424 | 439 | ||
| 425 | cbTotalWritten += cbWritten; | 440 | cbTotalWritten += cbWritten; |
| @@ -431,7 +446,7 @@ static HRESULT WriteToFile( | |||
| 431 | if (pCallback && pCallback->pfnProgress) | 446 | if (pCallback && pCallback->pfnProgress) |
| 432 | { | 447 | { |
| 433 | hr = DownloadSendProgressCallback(pCallback, *pdw64ResumeOffset, dw64ResourceLength, hPayloadFile); | 448 | hr = DownloadSendProgressCallback(pCallback, *pdw64ResumeOffset, dw64ResourceLength, hPayloadFile); |
| 434 | ExitOnFailure(hr, "UX aborted on cache progress."); | 449 | DlExitOnFailure(hr, "UX aborted on cache progress."); |
| 435 | } | 450 | } |
| 436 | } | 451 | } |
| 437 | } while (cbReadData); | 452 | } while (cbReadData); |
| @@ -456,14 +471,14 @@ static HRESULT UpdateResumeOffset( | |||
| 456 | DWORD cbWrittenResumeData = 0; | 471 | DWORD cbWrittenResumeData = 0; |
| 457 | 472 | ||
| 458 | hr = FileSetPointer(hResumeFile, 0, NULL, FILE_BEGIN); | 473 | hr = FileSetPointer(hResumeFile, 0, NULL, FILE_BEGIN); |
| 459 | ExitOnFailure(hr, "Failed to seek to start point in file."); | 474 | DlExitOnFailure(hr, "Failed to seek to start point in file."); |
| 460 | 475 | ||
| 461 | do | 476 | do |
| 462 | { | 477 | { |
| 463 | // Ignore failure to write to the resume file as that should not prevent the download from happening. | 478 | // Ignore failure to write to the resume file as that should not prevent the download from happening. |
| 464 | if (!::WriteFile(hResumeFile, pdw64ResumeOffset + cbTotalWrittenResumeData, sizeof(DWORD64) - cbTotalWrittenResumeData, &cbWrittenResumeData, NULL)) | 479 | if (!::WriteFile(hResumeFile, pdw64ResumeOffset + cbTotalWrittenResumeData, sizeof(DWORD64) - cbTotalWrittenResumeData, &cbWrittenResumeData, NULL)) |
| 465 | { | 480 | { |
| 466 | ExitOnFailure(hr, "Failed to seek to write to file."); | 481 | DlExitOnFailure(hr, "Failed to seek to write to file."); |
| 467 | } | 482 | } |
| 468 | 483 | ||
| 469 | cbTotalWrittenResumeData += cbWrittenResumeData; | 484 | cbTotalWrittenResumeData += cbWrittenResumeData; |
| @@ -504,10 +519,10 @@ static HRESULT MakeRequest( | |||
| 504 | 519 | ||
| 505 | // Open the url. | 520 | // Open the url. |
| 506 | hr = UriCrackEx(*psczSourceUrl, &uri); | 521 | hr = UriCrackEx(*psczSourceUrl, &uri); |
| 507 | ExitOnFailure(hr, "Failed to break URL into server and resource parts."); | 522 | DlExitOnFailure(hr, "Failed to break URL into server and resource parts."); |
| 508 | 523 | ||
| 509 | hConnect = ::InternetConnectW(hSession, uri.sczHostName, uri.port, (wzUser && *wzUser) ? wzUser : uri.sczUser, (wzPassword && *wzPassword) ? wzPassword : uri.sczPassword, INTERNET_SCHEME_FTP == uri.scheme ? INTERNET_SERVICE_FTP : INTERNET_SERVICE_HTTP, 0, 0); | 524 | hConnect = ::InternetConnectW(hSession, uri.sczHostName, uri.port, (wzUser && *wzUser) ? wzUser : uri.sczUser, (wzPassword && *wzPassword) ? wzPassword : uri.sczPassword, INTERNET_SCHEME_FTP == uri.scheme ? INTERNET_SERVICE_FTP : INTERNET_SERVICE_HTTP, 0, 0); |
| 510 | ExitOnNullWithLastError(hConnect, hr, "Failed to connect to URL: %ls", *psczSourceUrl); | 525 | DlExitOnNullWithLastError(hConnect, hr, "Failed to connect to URL: %ls", *psczSourceUrl); |
| 511 | 526 | ||
| 512 | // Best effort set the proxy username and password, if they were provided. | 527 | // Best effort set the proxy username and password, if they were provided. |
| 513 | if ((wzUser && *wzUser) && (wzPassword && *wzPassword)) | 528 | if ((wzUser && *wzUser) && (wzPassword && *wzPassword)) |
| @@ -519,10 +534,10 @@ static HRESULT MakeRequest( | |||
| 519 | } | 534 | } |
| 520 | 535 | ||
| 521 | hr = OpenRequest(hConnect, wzMethod, uri.scheme, uri.sczPath, uri.sczQueryString, wzHeaders, &hUrl); | 536 | hr = OpenRequest(hConnect, wzMethod, uri.scheme, uri.sczPath, uri.sczQueryString, wzHeaders, &hUrl); |
| 522 | ExitOnFailure(hr, "Failed to open internet URL: %ls", *psczSourceUrl); | 537 | DlExitOnFailure(hr, "Failed to open internet URL: %ls", *psczSourceUrl); |
| 523 | 538 | ||
| 524 | hr = SendRequest(hUrl, psczSourceUrl, pAuthenticate, &fRetry, pfRangeRequestsAccepted); | 539 | hr = SendRequest(hUrl, psczSourceUrl, pAuthenticate, &fRetry, pfRangeRequestsAccepted); |
| 525 | ExitOnFailure(hr, "Failed to send request to URL: %ls", *psczSourceUrl); | 540 | DlExitOnFailure(hr, "Failed to send request to URL: %ls", *psczSourceUrl); |
| 526 | } while (fRetry); | 541 | } while (fRetry); |
| 527 | 542 | ||
| 528 | // Okay, we're all ready to start downloading. Update the connection information. | 543 | // Okay, we're all ready to start downloading. Update the connection information. |
| @@ -565,23 +580,23 @@ static HRESULT OpenRequest( | |||
| 565 | 580 | ||
| 566 | // Allocate the resource name. | 581 | // Allocate the resource name. |
| 567 | hr = StrAllocString(&sczResource, wzResource, 0); | 582 | hr = StrAllocString(&sczResource, wzResource, 0); |
| 568 | ExitOnFailure(hr, "Failed to allocate string for resource URI."); | 583 | DlExitOnFailure(hr, "Failed to allocate string for resource URI."); |
| 569 | 584 | ||
| 570 | if (wzQueryString && *wzQueryString) | 585 | if (wzQueryString && *wzQueryString) |
| 571 | { | 586 | { |
| 572 | hr = StrAllocConcat(&sczResource, wzQueryString, 0); | 587 | hr = StrAllocConcat(&sczResource, wzQueryString, 0); |
| 573 | ExitOnFailure(hr, "Failed to append query strong to resource from URI."); | 588 | DlExitOnFailure(hr, "Failed to append query strong to resource from URI."); |
| 574 | } | 589 | } |
| 575 | 590 | ||
| 576 | // Open the request and add the header if provided. | 591 | // Open the request and add the header if provided. |
| 577 | hUrl = ::HttpOpenRequestW(hConnect, wzMethod, sczResource, NULL, NULL, DOWNLOAD_ENGINE_ACCEPT_TYPES, dwRequestFlags, NULL); | 592 | hUrl = ::HttpOpenRequestW(hConnect, wzMethod, sczResource, NULL, NULL, DOWNLOAD_ENGINE_ACCEPT_TYPES, dwRequestFlags, NULL); |
| 578 | ExitOnNullWithLastError(hUrl, hr, "Failed to open internet request."); | 593 | DlExitOnNullWithLastError(hUrl, hr, "Failed to open internet request."); |
| 579 | 594 | ||
| 580 | if (wzHeader && *wzHeader) | 595 | if (wzHeader && *wzHeader) |
| 581 | { | 596 | { |
| 582 | if (!::HttpAddRequestHeadersW(hUrl, wzHeader, static_cast<DWORD>(-1), HTTP_ADDREQ_FLAG_COALESCE)) | 597 | if (!::HttpAddRequestHeadersW(hUrl, wzHeader, static_cast<DWORD>(-1), HTTP_ADDREQ_FLAG_COALESCE)) |
| 583 | { | 598 | { |
| 584 | ExitWithLastError(hr, "Failed to add header to HTTP request."); | 599 | DlExitWithLastError(hr, "Failed to add header to HTTP request."); |
| 585 | } | 600 | } |
| 586 | } | 601 | } |
| 587 | 602 | ||
| @@ -618,12 +633,12 @@ static HRESULT SendRequest( | |||
| 618 | // Try to get the HTTP status code and, if good, handle via the switch statement below but if it | 633 | // Try to get the HTTP status code and, if good, handle via the switch statement below but if it |
| 619 | // fails return the error code from the send request above as the result of the function. | 634 | // fails return the error code from the send request above as the result of the function. |
| 620 | HRESULT hrQueryStatusCode = InternetQueryInfoNumber(hUrl, HTTP_QUERY_STATUS_CODE, &lCode); | 635 | HRESULT hrQueryStatusCode = InternetQueryInfoNumber(hUrl, HTTP_QUERY_STATUS_CODE, &lCode); |
| 621 | ExitOnFailure(hrQueryStatusCode, "Failed to get HTTP status code for failed request to URL: %ls", *psczUrl); | 636 | DlExitOnFailure(hrQueryStatusCode, "Failed to get HTTP status code for failed request to URL: %ls", *psczUrl); |
| 622 | } | 637 | } |
| 623 | else // get the http status code. | 638 | else // get the http status code. |
| 624 | { | 639 | { |
| 625 | hr = InternetQueryInfoNumber(hUrl, HTTP_QUERY_STATUS_CODE, &lCode); | 640 | hr = InternetQueryInfoNumber(hUrl, HTTP_QUERY_STATUS_CODE, &lCode); |
| 626 | ExitOnFailure(hr, "Failed to get HTTP status code for request to URL: %ls", *psczUrl); | 641 | DlExitOnFailure(hr, "Failed to get HTTP status code for request to URL: %ls", *psczUrl); |
| 627 | } | 642 | } |
| 628 | 643 | ||
| 629 | switch (lCode) | 644 | switch (lCode) |
| @@ -643,7 +658,7 @@ static HRESULT SendRequest( | |||
| 643 | case 302: __fallthrough; // temporary | 658 | case 302: __fallthrough; // temporary |
| 644 | case 303: // redirect method | 659 | case 303: // redirect method |
| 645 | hr = InternetQueryInfoString(hUrl, HTTP_QUERY_CONTENT_LOCATION, psczUrl); | 660 | hr = InternetQueryInfoString(hUrl, HTTP_QUERY_CONTENT_LOCATION, psczUrl); |
| 646 | ExitOnFailure(hr, "Failed to get redirect url: %ls", *psczUrl); | 661 | DlExitOnFailure(hr, "Failed to get redirect url: %ls", *psczUrl); |
| 647 | 662 | ||
| 648 | *pfRetry = TRUE; | 663 | *pfRetry = TRUE; |
| 649 | break; | 664 | break; |
| @@ -734,7 +749,7 @@ static HRESULT DownloadGetResumePath( | |||
| 734 | HRESULT hr = S_OK; | 749 | HRESULT hr = S_OK; |
| 735 | 750 | ||
| 736 | hr = StrAllocFormatted(psczResumePath, L"%ls.R", wzPayloadWorkingPath); | 751 | hr = StrAllocFormatted(psczResumePath, L"%ls.R", wzPayloadWorkingPath); |
| 737 | ExitOnFailure(hr, "Failed to create resume path."); | 752 | DlExitOnFailure(hr, "Failed to create resume path."); |
| 738 | 753 | ||
| 739 | LExit: | 754 | LExit: |
| 740 | return hr; | 755 | return hr; |
| @@ -769,7 +784,7 @@ static HRESULT DownloadSendProgressCallback( | |||
| 769 | case PROGRESS_CANCEL: __fallthrough; // TODO: should cancel and stop be treated differently? | 784 | case PROGRESS_CANCEL: __fallthrough; // TODO: should cancel and stop be treated differently? |
| 770 | case PROGRESS_STOP: | 785 | case PROGRESS_STOP: |
| 771 | hr = HRESULT_FROM_WIN32(ERROR_INSTALL_USEREXIT); | 786 | hr = HRESULT_FROM_WIN32(ERROR_INSTALL_USEREXIT); |
| 772 | ExitOnRootFailure(hr, "UX aborted on download progress."); | 787 | DlExitOnRootFailure(hr, "UX aborted on download progress."); |
| 773 | 788 | ||
| 774 | case PROGRESS_QUIET: // Not actually an error, just an indication to the caller to stop requesting progress. | 789 | case PROGRESS_QUIET: // Not actually an error, just an indication to the caller to stop requesting progress. |
| 775 | pCallback->pfnProgress = NULL; | 790 | pCallback->pfnProgress = NULL; |
| @@ -778,7 +793,7 @@ static HRESULT DownloadSendProgressCallback( | |||
| 778 | 793 | ||
| 779 | default: | 794 | default: |
| 780 | hr = E_UNEXPECTED; | 795 | hr = E_UNEXPECTED; |
| 781 | ExitOnRootFailure(hr, "Invalid return code from progress routine."); | 796 | DlExitOnRootFailure(hr, "Invalid return code from progress routine."); |
| 782 | } | 797 | } |
| 783 | } | 798 | } |
| 784 | 799 | ||
