aboutsummaryrefslogtreecommitdiff
path: root/src/dutil/rexutil.cpp
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2021-03-02 14:19:14 -0600
committerSean Hall <r.sean.hall@gmail.com>2021-03-02 15:40:02 -0600
commit10ebf674da5df9224e4eddd3545518434c5b455b (patch)
treeea1f4063edd46e9942eab94dd7adb2f75c6c589e /src/dutil/rexutil.cpp
parent3bbf1347b900ec115a12faf8f46965c9b7649696 (diff)
downloadwix-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/rexutil.cpp')
-rw-r--r--src/dutil/rexutil.cpp59
1 files changed, 37 insertions, 22 deletions
diff --git a/src/dutil/rexutil.cpp b/src/dutil/rexutil.cpp
index 73500630..155ca714 100644
--- a/src/dutil/rexutil.cpp
+++ b/src/dutil/rexutil.cpp
@@ -3,6 +3,21 @@
3#include "precomp.h" 3#include "precomp.h"
4#include "rexutil.h" 4#include "rexutil.h"
5 5
6
7// Exit macros
8#define RexExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_REXUTIL, x, s, __VA_ARGS__)
9#define RexExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_REXUTIL, x, s, __VA_ARGS__)
10#define RexExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_REXUTIL, x, s, __VA_ARGS__)
11#define RexExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_REXUTIL, x, s, __VA_ARGS__)
12#define RexExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_REXUTIL, x, s, __VA_ARGS__)
13#define RexExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_REXUTIL, x, s, __VA_ARGS__)
14#define RexExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_REXUTIL, p, x, e, s, __VA_ARGS__)
15#define RexExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_REXUTIL, p, x, s, __VA_ARGS__)
16#define RexExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_REXUTIL, p, x, e, s, __VA_ARGS__)
17#define RexExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_REXUTIL, p, x, s, __VA_ARGS__)
18#define RexExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_REXUTIL, e, x, s, __VA_ARGS__)
19#define RexExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_REXUTIL, g, x, s, __VA_ARGS__)
20
6// 21//
7// static globals 22// static globals
8// 23//
@@ -60,7 +75,7 @@ extern "C" HRESULT RexInitialize()
60 if (!vhfdi) 75 if (!vhfdi)
61 { 76 {
62 hr = E_FAIL; 77 hr = E_FAIL;
63 ExitOnFailure(hr, "failed to initialize cabinet.dll"); // TODO: put verf info in trace message here 78 RexExitOnFailure(hr, "failed to initialize cabinet.dll"); // TODO: put verf info in trace message here
64 } 79 }
65 80
66 ::ZeroMemory(vrgffFileTable, sizeof(vrgffFileTable)); 81 ::ZeroMemory(vrgffFileTable, sizeof(vrgffFileTable));
@@ -123,12 +138,12 @@ extern "C" HRESULT RexExtract(
123 // load the cabinet resource 138 // load the cabinet resource
124 // 139 //
125 hResInfo = ::FindResourceExA(NULL, RT_RCDATA, szResource, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)); 140 hResInfo = ::FindResourceExA(NULL, RT_RCDATA, szResource, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
126 ExitOnNullWithLastError(hResInfo, hr, "Failed to find resource."); 141 RexExitOnNullWithLastError(hResInfo, hr, "Failed to find resource.");
127 //hResInfo = ::FindResourceW(NULL, wzResource, /*RT_RCDATA*/MAKEINTRESOURCEW(10)); 142 //hResInfo = ::FindResourceW(NULL, wzResource, /*RT_RCDATA*/MAKEINTRESOURCEW(10));
128 //ExitOnNullWithLastError(hResInfo, hr, "failed to load resource info"); 143 //ExitOnNullWithLastError(hResInfo, hr, "failed to load resource info");
129 144
130 hRes = ::LoadResource(NULL, hResInfo); 145 hRes = ::LoadResource(NULL, hResInfo);
131 ExitOnNullWithLastError(hRes, hr, "failed to load resource"); 146 RexExitOnNullWithLastError(hRes, hr, "failed to load resource");
132 147
133 vcbRes = ::SizeofResource(NULL, hResInfo); 148 vcbRes = ::SizeofResource(NULL, hResInfo);
134 vpbRes = (const BYTE*)::LockResource(hRes); 149 vpbRes = (const BYTE*)::LockResource(hRes);
@@ -140,11 +155,11 @@ extern "C" HRESULT RexExtract(
140 // 155 //
141 //if (!::WideCharToMultiByte(CP_ACP, 0, wzResource, -1, vszResource, countof(vszResource), NULL, NULL)) 156 //if (!::WideCharToMultiByte(CP_ACP, 0, wzResource, -1, vszResource, countof(vszResource), NULL, NULL))
142 //{ 157 //{
143 // ExitOnLastError(hr, "failed to convert cabinet resource name to ASCII: %ls", wzResource); 158 // RexExitOnLastError(hr, "failed to convert cabinet resource name to ASCII: %ls", wzResource);
144 //} 159 //}
145 160
146 hr = ::StringCchCopyA(vszResource, countof(vszResource), szResource); 161 hr = ::StringCchCopyA(vszResource, countof(vszResource), szResource);
147 ExitOnFailure(hr, "Failed to copy resource name to global."); 162 RexExitOnFailure(hr, "Failed to copy resource name to global.");
148 163
149 // 164 //
150 // iterate through files in cabinet extracting them to the callback function 165 // iterate through files in cabinet extracting them to the callback function
@@ -193,7 +208,7 @@ static __callback INT_PTR FAR DIAMONDAPI RexOpen(__in_z char FAR *pszFile, int o
193 if ((oflag != (/*_O_BINARY*/ 0x8000 | /*_O_RDONLY*/ 0x0000)) || (pmode != (_S_IREAD | _S_IWRITE))) 208 if ((oflag != (/*_O_BINARY*/ 0x8000 | /*_O_RDONLY*/ 0x0000)) || (pmode != (_S_IREAD | _S_IWRITE)))
194 { 209 {
195 hr = E_OUTOFMEMORY; 210 hr = E_OUTOFMEMORY;
196 ExitOnFailure(hr, "FDI asked for to create a scratch file, which is unusual"); 211 RexExitOnFailure(hr, "FDI asked for to create a scratch file, which is unusual");
197 } 212 }
198 213
199 // find an empty spot in the fake file table 214 // find an empty spot in the fake file table
@@ -209,7 +224,7 @@ static __callback INT_PTR FAR DIAMONDAPI RexOpen(__in_z char FAR *pszFile, int o
209 if (FILETABLESIZE <= i) 224 if (FILETABLESIZE <= i)
210 { 225 {
211 hr = E_OUTOFMEMORY; 226 hr = E_OUTOFMEMORY;
212 ExitOnFailure(hr, "File table exceeded"); 227 RexExitOnFailure(hr, "File table exceeded");
213 } 228 }
214 229
215 if (0 == lstrcmpA(vszResource, pszFile)) 230 if (0 == lstrcmpA(vszResource, pszFile))
@@ -225,7 +240,7 @@ static __callback INT_PTR FAR DIAMONDAPI RexOpen(__in_z char FAR *pszFile, int o
225 hFile = ::CreateFileA(pszFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 240 hFile = ::CreateFileA(pszFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
226 if (INVALID_HANDLE_VALUE == hFile) 241 if (INVALID_HANDLE_VALUE == hFile)
227 { 242 {
228 ExitWithLastError(hr, "failed to open file: %s", pszFile); 243 RexExitWithLastError(hr, "failed to open file: %s", pszFile);
229 } 244 }
230 245
231 vrgffFileTable[i].fUsed = TRUE; 246 vrgffFileTable[i].fUsed = TRUE;
@@ -267,7 +282,7 @@ static __callback UINT FAR DIAMONDAPI RexRead(INT_PTR hf, __out_bcount(cb) void
267 282
268 if (!::ReadFile(vrgffFileTable[hf].hFile, pv, cb, &cbRead, NULL)) 283 if (!::ReadFile(vrgffFileTable[hf].hFile, pv, cb, &cbRead, NULL))
269 { 284 {
270 ExitWithLastError(hr, "failed to read during cabinet extraction"); 285 RexExitWithLastError(hr, "failed to read during cabinet extraction");
271 } 286 }
272 } 287 }
273 288
@@ -292,7 +307,7 @@ static __callback UINT FAR DIAMONDAPI RexWrite(INT_PTR hf, __in_bcount(cb) void
292 Assert(vrgffFileTable[hf].hFile && vrgffFileTable[hf].hFile != INVALID_HANDLE_VALUE); 307 Assert(vrgffFileTable[hf].hFile && vrgffFileTable[hf].hFile != INVALID_HANDLE_VALUE);
293 if (!::WriteFile(reinterpret_cast<HANDLE>(vrgffFileTable[hf].hFile), pv, cb, &cbWrite, NULL)) 308 if (!::WriteFile(reinterpret_cast<HANDLE>(vrgffFileTable[hf].hFile), pv, cb, &cbWrite, NULL))
294 { 309 {
295 ExitWithLastError(hr, "failed to write during cabinet extraction"); 310 RexExitWithLastError(hr, "failed to write during cabinet extraction");
296 } 311 }
297 312
298 // call the writer callback if defined 313 // call the writer callback if defined
@@ -333,7 +348,7 @@ static __callback long FAR DIAMONDAPI RexSeek(INT_PTR hf, long dist, int seektyp
333 default : 348 default :
334 dwMoveMethod = 0; 349 dwMoveMethod = 0;
335 hr = E_UNEXPECTED; 350 hr = E_UNEXPECTED;
336 ExitOnFailure(hr, "unexpected seektype in FDISeek(): %d", seektype); 351 RexExitOnFailure(hr, "unexpected seektype in FDISeek(): %d", seektype);
337 } 352 }
338 353
339 if (MEMORY_FILE == vrgffFileTable[hf].fftType) 354 if (MEMORY_FILE == vrgffFileTable[hf].fftType)
@@ -362,7 +377,7 @@ static __callback long FAR DIAMONDAPI RexSeek(INT_PTR hf, long dist, int seektyp
362 lMove = ::SetFilePointer(vrgffFileTable[hf].hFile, dist, NULL, dwMoveMethod); 377 lMove = ::SetFilePointer(vrgffFileTable[hf].hFile, dist, NULL, dwMoveMethod);
363 if (0xFFFFFFFF == lMove) 378 if (0xFFFFFFFF == lMove)
364 { 379 {
365 ExitWithLastError(hr, "failed to move file pointer %d bytes", dist); 380 RexExitWithLastError(hr, "failed to move file pointer %d bytes", dist);
366 } 381 }
367 } 382 }
368 383
@@ -394,7 +409,7 @@ __callback int FAR DIAMONDAPI RexClose(INT_PTR hf)
394 409
395 if (!::CloseHandle(vrgffFileTable[hf].hFile)) 410 if (!::CloseHandle(vrgffFileTable[hf].hFile))
396 { 411 {
397 ExitWithLastError(hr, "failed to close file during cabinet extraction"); 412 RexExitWithLastError(hr, "failed to close file during cabinet extraction");
398 } 413 }
399 414
400 vrgffFileTable[hf].hFile = INVALID_HANDLE_VALUE; 415 vrgffFileTable[hf].hFile = INVALID_HANDLE_VALUE;
@@ -440,7 +455,7 @@ static __callback INT_PTR DIAMONDAPI RexCallback(FDINOTIFICATIONTYPE iNotificati
440 sz = static_cast<LPCSTR>(pFDINotify->psz1); 455 sz = static_cast<LPCSTR>(pFDINotify->psz1);
441 if (!::MultiByteToWideChar(CP_ACP, 0, sz, -1, wz, countof(wz))) 456 if (!::MultiByteToWideChar(CP_ACP, 0, sz, -1, wz, countof(wz)))
442 { 457 {
443 ExitWithLastError(hr, "failed to convert cabinet file id to unicode: %s", sz); 458 RexExitWithLastError(hr, "failed to convert cabinet file id to unicode: %s", sz);
444 } 459 }
445 460
446 if (prcs->pfnProgress) 461 if (prcs->pfnProgress)
@@ -457,25 +472,25 @@ static __callback INT_PTR DIAMONDAPI RexCallback(FDINOTIFICATIONTYPE iNotificati
457 // get the created date for the resource in the cabinet 472 // get the created date for the resource in the cabinet
458 if (!::DosDateTimeToFileTime(pFDINotify->date, pFDINotify->time, &ft)) 473 if (!::DosDateTimeToFileTime(pFDINotify->date, pFDINotify->time, &ft))
459 { 474 {
460 ExitWithLastError(hr, "failed to get time for resource: %ls", wz); 475 RexExitWithLastError(hr, "failed to get time for resource: %ls", wz);
461 } 476 }
462 477
463 WCHAR wzPath[MAX_PATH]; 478 WCHAR wzPath[MAX_PATH];
464 479
465 hr = ::StringCchCopyW(wzPath, countof(wzPath), prcs->pwzExtractDir); 480 hr = ::StringCchCopyW(wzPath, countof(wzPath), prcs->pwzExtractDir);
466 ExitOnFailure(hr, "failed to copy extract directory: %ls for file: %ls", prcs->pwzExtractDir, wz); 481 RexExitOnFailure(hr, "failed to copy extract directory: %ls for file: %ls", prcs->pwzExtractDir, wz);
467 482
468 if (L'*' == *prcs->pwzExtract) 483 if (L'*' == *prcs->pwzExtract)
469 { 484 {
470 hr = ::StringCchCatW(wzPath, countof(wzPath), wz); 485 hr = ::StringCchCatW(wzPath, countof(wzPath), wz);
471 ExitOnFailure(hr, "failed to concat onto path: %ls file: %ls", wzPath, wz); 486 RexExitOnFailure(hr, "failed to concat onto path: %ls file: %ls", wzPath, wz);
472 } 487 }
473 else 488 else
474 { 489 {
475 Assert(*prcs->pwzExtractName); 490 Assert(*prcs->pwzExtractName);
476 491
477 hr = ::StringCchCatW(wzPath, countof(wzPath), prcs->pwzExtractName); 492 hr = ::StringCchCatW(wzPath, countof(wzPath), prcs->pwzExtractName);
478 ExitOnFailure(hr, "failed to concat onto path: %ls file: %ls", wzPath, prcs->pwzExtractName); 493 RexExitOnFailure(hr, "failed to concat onto path: %ls file: %ls", wzPath, prcs->pwzExtractName);
479 } 494 }
480 495
481 // Quickly chop off the file name part of the path to ensure the path exists 496 // Quickly chop off the file name part of the path to ensure the path exists
@@ -486,7 +501,7 @@ static __callback INT_PTR DIAMONDAPI RexCallback(FDINOTIFICATIONTYPE iNotificati
486 *wzFile = L'\0'; 501 *wzFile = L'\0';
487 502
488 hr = DirEnsureExists(wzPath, NULL); 503 hr = DirEnsureExists(wzPath, NULL);
489 ExitOnFailure(hr, "failed to ensure directory: %ls", wzPath); 504 RexExitOnFailure(hr, "failed to ensure directory: %ls", wzPath);
490 505
491 hr = S_OK; 506 hr = S_OK;
492 507
@@ -505,14 +520,14 @@ static __callback INT_PTR DIAMONDAPI RexCallback(FDINOTIFICATIONTYPE iNotificati
505 if (FILETABLESIZE <= i) 520 if (FILETABLESIZE <= i)
506 { 521 {
507 hr = E_OUTOFMEMORY; 522 hr = E_OUTOFMEMORY;
508 ExitOnFailure(hr, "File table exceeded"); 523 RexExitOnFailure(hr, "File table exceeded");
509 } 524 }
510 525
511 // open the file 526 // open the file
512 hFile = ::CreateFileW(wzPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 527 hFile = ::CreateFileW(wzPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
513 if (INVALID_HANDLE_VALUE == hFile) 528 if (INVALID_HANDLE_VALUE == hFile)
514 { 529 {
515 ExitWithLastError(hr, "failed to open file: %ls", wzPath); 530 RexExitWithLastError(hr, "failed to open file: %ls", wzPath);
516 } 531 }
517 532
518 vrgffFileTable[i].fUsed = TRUE; 533 vrgffFileTable[i].fUsed = TRUE;
@@ -545,7 +560,7 @@ static __callback INT_PTR DIAMONDAPI RexCallback(FDINOTIFICATIONTYPE iNotificati
545 sz = static_cast<LPCSTR>(pFDINotify->psz1); 560 sz = static_cast<LPCSTR>(pFDINotify->psz1);
546 if (!::MultiByteToWideChar(CP_ACP, 0, sz, -1, wz, countof(wz))) 561 if (!::MultiByteToWideChar(CP_ACP, 0, sz, -1, wz, countof(wz)))
547 { 562 {
548 ExitWithLastError(hr, "failed to convert cabinet file id to unicode: %s", sz); 563 RexExitWithLastError(hr, "failed to convert cabinet file id to unicode: %s", sz);
549 } 564 }
550 565
551 RexClose(pFDINotify->hf); 566 RexClose(pFDINotify->hf);