diff options
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil')
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/cabcutil.cpp | 8 | ||||
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/cabutil.cpp | 4 | ||||
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/dirutil.cpp | 55 | ||||
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/fileutil.cpp | 118 | ||||
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/inc/dirutil.h | 3 | ||||
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/inc/fileutil.h | 7 | ||||
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/inc/pathutil.h | 10 | ||||
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/logutil.cpp | 15 | ||||
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/pathutil.cpp | 104 | ||||
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/sceutil.cpp | 7 |
10 files changed, 149 insertions, 182 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/cabcutil.cpp b/src/libs/dutil/WixToolset.DUtil/cabcutil.cpp index 9cc45a83..d1edc54d 100644 --- a/src/libs/dutil/WixToolset.DUtil/cabcutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/cabcutil.cpp | |||
@@ -503,7 +503,7 @@ extern "C" HRESULT DAPI CabCFinish( | |||
503 | } | 503 | } |
504 | else | 504 | else |
505 | { | 505 | { |
506 | LPCWSTR pwzTemp = FileFromPath(fileInfo.wzSourcePath); | 506 | LPCWSTR pwzTemp = PathFile(fileInfo.wzSourcePath); |
507 | hr = StrAnsiAllocString(&pszFileToken, pwzTemp, 0, CP_ACP); | 507 | hr = StrAnsiAllocString(&pszFileToken, pwzTemp, 0, CP_ACP); |
508 | CabcExitOnFailure(hr, "failed to convert file name to ANSI: %ls", pwzTemp); | 508 | CabcExitOnFailure(hr, "failed to convert file name to ANSI: %ls", pwzTemp); |
509 | } | 509 | } |
@@ -538,7 +538,7 @@ extern "C" HRESULT DAPI CabCFinish( | |||
538 | } | 538 | } |
539 | else | 539 | else |
540 | { | 540 | { |
541 | LPCWSTR pwzTemp = FileFromPath(fileInfo.wzSourcePath); | 541 | LPCWSTR pwzTemp = PathFile(fileInfo.wzSourcePath); |
542 | hr = StrAnsiAllocString(&pszFileToken, pwzTemp, 0, CP_ACP); | 542 | hr = StrAnsiAllocString(&pszFileToken, pwzTemp, 0, CP_ACP); |
543 | CabcExitOnFailure(hr, "failed to convert duplicate file name to ANSI: %ls", pwzTemp); | 543 | CabcExitOnFailure(hr, "failed to convert duplicate file name to ANSI: %ls", pwzTemp); |
544 | } | 544 | } |
@@ -1386,7 +1386,7 @@ static __callback BOOL DIAMONDAPI CabCGetNextCabinet( | |||
1386 | if (pccab->iCab == 1) | 1386 | if (pccab->iCab == 1) |
1387 | { | 1387 | { |
1388 | pcd->wzFirstCabinetName[0] = '\0'; | 1388 | pcd->wzFirstCabinetName[0] = '\0'; |
1389 | LPCWSTR pwzCabinetName = FileFromPath(pcd->wzCabinetPath); | 1389 | LPCWSTR pwzCabinetName = PathFile(pcd->wzCabinetPath); |
1390 | size_t len = wcsnlen(pwzCabinetName, sizeof(pwzCabinetName)); | 1390 | size_t len = wcsnlen(pwzCabinetName, sizeof(pwzCabinetName)); |
1391 | if (len > 4) | 1391 | if (len > 4) |
1392 | { | 1392 | { |
@@ -1439,7 +1439,7 @@ static __callback BOOL DIAMONDAPI CabCGetNextCabinet( | |||
1439 | else | 1439 | else |
1440 | { | 1440 | { |
1441 | LPCWSTR wzSourcePath = pcd->prgFiles[0].pwzSourcePath; | 1441 | LPCWSTR wzSourcePath = pcd->prgFiles[0].pwzSourcePath; |
1442 | pwzFileToken = FileFromPath(wzSourcePath); | 1442 | pwzFileToken = PathFile(wzSourcePath); |
1443 | } | 1443 | } |
1444 | 1444 | ||
1445 | // The call back to Binder to Add File Transfer for new Cab and add new Cab to Media table | 1445 | // The call back to Binder to Add File Transfer for new Cab and add new Cab to Media table |
diff --git a/src/libs/dutil/WixToolset.DUtil/cabutil.cpp b/src/libs/dutil/WixToolset.DUtil/cabutil.cpp index 5d77e483..f3629d57 100644 --- a/src/libs/dutil/WixToolset.DUtil/cabutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/cabutil.cpp | |||
@@ -106,7 +106,7 @@ static HANDLE OpenFileWithRetry( | |||
106 | __in LPCWSTR wzPath, | 106 | __in LPCWSTR wzPath, |
107 | __in DWORD dwDesiredAccess, | 107 | __in DWORD dwDesiredAccess, |
108 | __in DWORD dwCreationDisposition | 108 | __in DWORD dwCreationDisposition |
109 | ) | 109 | ) |
110 | { | 110 | { |
111 | HANDLE hFile = INVALID_HANDLE_VALUE; | 111 | HANDLE hFile = INVALID_HANDLE_VALUE; |
112 | 112 | ||
@@ -286,7 +286,7 @@ static HRESULT DAPI CabOperation( | |||
286 | // | 286 | // |
287 | // split the cabinet full path into directory and filename and convert to multi-byte (ick!) | 287 | // split the cabinet full path into directory and filename and convert to multi-byte (ick!) |
288 | // | 288 | // |
289 | pwz = FileFromPath(sczCabinet); | 289 | pwz = PathFile(sczCabinet); |
290 | CabExitOnNull(pwz, hr, E_INVALIDARG, "failed to process cabinet path: %ls", wzCabinet); | 290 | CabExitOnNull(pwz, hr, E_INVALIDARG, "failed to process cabinet path: %ls", wzCabinet); |
291 | 291 | ||
292 | if (!::WideCharToMultiByte(CP_UTF8, 0, pwz, -1, szCabFile, countof(szCabFile), NULL, NULL)) | 292 | if (!::WideCharToMultiByte(CP_UTF8, 0, pwz, -1, szCabFile, countof(szCabFile), NULL, NULL)) |
diff --git a/src/libs/dutil/WixToolset.DUtil/dirutil.cpp b/src/libs/dutil/WixToolset.DUtil/dirutil.cpp index ae2c5e1c..c106a467 100644 --- a/src/libs/dutil/WixToolset.DUtil/dirutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/dirutil.cpp | |||
@@ -9,6 +9,7 @@ | |||
9 | #define DirExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__) | 9 | #define DirExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__) |
10 | #define DirExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__) | 10 | #define DirExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__) |
11 | #define DirExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__) | 11 | #define DirExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__) |
12 | #define DirExitWithRootFailure(x, e, s, ...) ExitWithRootFailureSource(DUTIL_SOURCE_DIRUTIL, x, e, s, __VA_ARGS__) | ||
12 | #define DirExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__) | 13 | #define DirExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_DIRUTIL, x, s, __VA_ARGS__) |
13 | #define DirExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_DIRUTIL, p, x, e, s, __VA_ARGS__) | 14 | #define DirExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_DIRUTIL, p, x, e, s, __VA_ARGS__) |
14 | #define DirExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_DIRUTIL, p, x, s, __VA_ARGS__) | 15 | #define DirExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_DIRUTIL, p, x, s, __VA_ARGS__) |
@@ -388,32 +389,58 @@ LExit: | |||
388 | 389 | ||
389 | *******************************************************************/ | 390 | *******************************************************************/ |
390 | extern "C" HRESULT DAPI DirGetCurrent( | 391 | extern "C" HRESULT DAPI DirGetCurrent( |
391 | __deref_out_z LPWSTR* psczCurrentDirectory | 392 | __deref_out_z LPWSTR* psczCurrentDirectory, |
393 | __out_opt SIZE_T* pcch | ||
392 | ) | 394 | ) |
393 | { | 395 | { |
396 | Assert(psczCurrentDirectory); | ||
397 | |||
394 | HRESULT hr = S_OK; | 398 | HRESULT hr = S_OK; |
395 | SIZE_T cch = 0; | 399 | SIZE_T cchMax = 0; |
400 | DWORD cch = 0; | ||
401 | DWORD cchBuffer = 0; | ||
402 | DWORD dwAttempts = 0; | ||
403 | const DWORD dwMaxAttempts = 10; | ||
396 | 404 | ||
397 | if (psczCurrentDirectory && *psczCurrentDirectory) | 405 | if (*psczCurrentDirectory) |
398 | { | 406 | { |
399 | hr = StrMaxLength(*psczCurrentDirectory, &cch); | 407 | hr = StrMaxLength(*psczCurrentDirectory, &cchMax); |
400 | DirExitOnFailure(hr, "Failed to determine size of current directory."); | 408 | DirExitOnFailure(hr, "Failed to get max length of input buffer."); |
401 | } | ||
402 | 409 | ||
403 | DWORD cchRequired = ::GetCurrentDirectoryW((DWORD)min(DWORD_MAX, cch), 0 == cch ? NULL : *psczCurrentDirectory); | 410 | cchBuffer = (DWORD)min(DWORD_MAX, cchMax); |
404 | if (0 == cchRequired) | 411 | } |
412 | else | ||
405 | { | 413 | { |
406 | DirExitWithLastError(hr, "Failed to get current directory."); | 414 | cchBuffer = MAX_PATH + 1; |
415 | |||
416 | hr = StrAlloc(psczCurrentDirectory, cchBuffer); | ||
417 | DirExitOnFailure(hr, "Failed to allocate space for current directory."); | ||
407 | } | 418 | } |
408 | else if (cch < cchRequired) | 419 | |
420 | for (; dwAttempts < dwMaxAttempts; ++dwAttempts) | ||
409 | { | 421 | { |
410 | hr = StrAlloc(psczCurrentDirectory, cchRequired); | 422 | cch = ::GetCurrentDirectoryW(cchBuffer, *psczCurrentDirectory); |
411 | DirExitOnFailure(hr, "Failed to allocate string for current directory."); | 423 | DirExitOnNullWithLastError(cch, hr, "Failed to get current directory."); |
412 | 424 | ||
413 | if (!::GetCurrentDirectoryW(cchRequired, *psczCurrentDirectory)) | 425 | if (cch < cchBuffer) |
414 | { | 426 | { |
415 | DirExitWithLastError(hr, "Failed to get current directory using allocated string."); | 427 | break; |
416 | } | 428 | } |
429 | |||
430 | hr = StrAlloc(psczCurrentDirectory, cch); | ||
431 | DirExitOnFailure(hr, "Failed to reallocate space for current directory."); | ||
432 | |||
433 | cchBuffer = cch; | ||
434 | } | ||
435 | |||
436 | if (dwMaxAttempts == dwAttempts) | ||
437 | { | ||
438 | DirExitWithRootFailure(hr, E_INSUFFICIENT_BUFFER, "GetCurrentDirectoryW results never converged."); | ||
439 | } | ||
440 | |||
441 | if (pcch) | ||
442 | { | ||
443 | *pcch = cch; | ||
417 | } | 444 | } |
418 | 445 | ||
419 | LExit: | 446 | LExit: |
diff --git a/src/libs/dutil/WixToolset.DUtil/fileutil.cpp b/src/libs/dutil/WixToolset.DUtil/fileutil.cpp index 1822727a..2fe04de1 100644 --- a/src/libs/dutil/WixToolset.DUtil/fileutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/fileutil.cpp | |||
@@ -25,124 +25,6 @@ const BYTE UTF16BOM[] = {0xFF, 0xFE}; | |||
25 | const LPCWSTR REGISTRY_PENDING_FILE_RENAME_KEY = L"SYSTEM\\CurrentControlSet\\Control\\Session Manager"; | 25 | const LPCWSTR REGISTRY_PENDING_FILE_RENAME_KEY = L"SYSTEM\\CurrentControlSet\\Control\\Session Manager"; |
26 | const LPCWSTR REGISTRY_PENDING_FILE_RENAME_VALUE = L"PendingFileRenameOperations"; | 26 | const LPCWSTR REGISTRY_PENDING_FILE_RENAME_VALUE = L"PendingFileRenameOperations"; |
27 | 27 | ||
28 | /******************************************************************* | ||
29 | FileFromPath - returns a pointer to the file part of the path | ||
30 | |||
31 | ********************************************************************/ | ||
32 | extern "C" LPWSTR DAPI FileFromPath( | ||
33 | __in_z LPCWSTR wzPath | ||
34 | ) | ||
35 | { | ||
36 | if (!wzPath) | ||
37 | return NULL; | ||
38 | |||
39 | LPWSTR wzFile = const_cast<LPWSTR>(wzPath); | ||
40 | for (LPWSTR wz = wzFile; *wz; ++wz) | ||
41 | { | ||
42 | // valid delineators | ||
43 | // \ => Windows path | ||
44 | // / => unix and URL path | ||
45 | // : => relative path from mapped root | ||
46 | if (L'\\' == *wz || L'/' == *wz || L':' == *wz) | ||
47 | wzFile = wz + 1; | ||
48 | } | ||
49 | |||
50 | return wzFile; | ||
51 | } | ||
52 | |||
53 | |||
54 | /******************************************************************* | ||
55 | FileResolvePath - gets the full path to a file resolving environment | ||
56 | variables along the way. | ||
57 | |||
58 | ********************************************************************/ | ||
59 | extern "C" HRESULT DAPI FileResolvePath( | ||
60 | __in_z LPCWSTR wzRelativePath, | ||
61 | __out LPWSTR *ppwzFullPath | ||
62 | ) | ||
63 | { | ||
64 | Assert(wzRelativePath && *wzRelativePath); | ||
65 | |||
66 | HRESULT hr = S_OK; | ||
67 | DWORD cch = 0; | ||
68 | LPWSTR pwzExpandedPath = NULL; | ||
69 | DWORD cchExpandedPath = 0; | ||
70 | |||
71 | LPWSTR pwzFullPath = NULL; | ||
72 | DWORD cchFullPath = 0; | ||
73 | |||
74 | LPWSTR wzFileName = NULL; | ||
75 | |||
76 | // | ||
77 | // First, expand any environment variables. | ||
78 | // | ||
79 | cchExpandedPath = MAX_PATH; | ||
80 | hr = StrAlloc(&pwzExpandedPath, cchExpandedPath); | ||
81 | FileExitOnFailure(hr, "Failed to allocate space for expanded path."); | ||
82 | |||
83 | cch = ::ExpandEnvironmentStringsW(wzRelativePath, pwzExpandedPath, cchExpandedPath); | ||
84 | if (0 == cch) | ||
85 | { | ||
86 | FileExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath); | ||
87 | } | ||
88 | else if (cchExpandedPath < cch) | ||
89 | { | ||
90 | cchExpandedPath = cch; | ||
91 | hr = StrAlloc(&pwzExpandedPath, cchExpandedPath); | ||
92 | FileExitOnFailure(hr, "Failed to re-allocate more space for expanded path."); | ||
93 | |||
94 | cch = ::ExpandEnvironmentStringsW(wzRelativePath, pwzExpandedPath, cchExpandedPath); | ||
95 | if (0 == cch) | ||
96 | { | ||
97 | FileExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath); | ||
98 | } | ||
99 | else if (cchExpandedPath < cch) | ||
100 | { | ||
101 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); | ||
102 | FileExitOnRootFailure(hr, "Failed to allocate buffer for expanded path."); | ||
103 | } | ||
104 | } | ||
105 | |||
106 | // | ||
107 | // Second, get the full path. | ||
108 | // | ||
109 | cchFullPath = MAX_PATH; | ||
110 | hr = StrAlloc(&pwzFullPath, cchFullPath); | ||
111 | FileExitOnFailure(hr, "Failed to allocate space for full path."); | ||
112 | |||
113 | cch = ::GetFullPathNameW(pwzExpandedPath, cchFullPath, pwzFullPath, &wzFileName); | ||
114 | if (0 == cch) | ||
115 | { | ||
116 | FileExitWithLastError(hr, "Failed to get full path for string: %ls", pwzExpandedPath); | ||
117 | } | ||
118 | else if (cchFullPath < cch) | ||
119 | { | ||
120 | cchFullPath = cch; | ||
121 | hr = StrAlloc(&pwzFullPath, cchFullPath); | ||
122 | FileExitOnFailure(hr, "Failed to re-allocate more space for full path."); | ||
123 | |||
124 | cch = ::GetFullPathNameW(pwzExpandedPath, cchFullPath, pwzFullPath, &wzFileName); | ||
125 | if (0 == cch) | ||
126 | { | ||
127 | FileExitWithLastError(hr, "Failed to get full path for string: %ls", pwzExpandedPath); | ||
128 | } | ||
129 | else if (cchFullPath < cch) | ||
130 | { | ||
131 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); | ||
132 | FileExitOnRootFailure(hr, "Failed to allocate buffer for full path."); | ||
133 | } | ||
134 | } | ||
135 | |||
136 | *ppwzFullPath = pwzFullPath; | ||
137 | pwzFullPath = NULL; | ||
138 | |||
139 | LExit: | ||
140 | ReleaseStr(pwzFullPath); | ||
141 | ReleaseStr(pwzExpandedPath); | ||
142 | |||
143 | return hr; | ||
144 | } | ||
145 | |||
146 | 28 | ||
147 | /******************************************************************* | 29 | /******************************************************************* |
148 | FileStripExtension - Strip extension from filename | 30 | FileStripExtension - Strip extension from filename |
diff --git a/src/libs/dutil/WixToolset.DUtil/inc/dirutil.h b/src/libs/dutil/WixToolset.DUtil/inc/dirutil.h index 539b3a73..42268a16 100644 --- a/src/libs/dutil/WixToolset.DUtil/inc/dirutil.h +++ b/src/libs/dutil/WixToolset.DUtil/inc/dirutil.h | |||
@@ -46,7 +46,8 @@ DWORD DAPI DirDeleteEmptyDirectoriesToRoot( | |||
46 | ); | 46 | ); |
47 | 47 | ||
48 | HRESULT DAPI DirGetCurrent( | 48 | HRESULT DAPI DirGetCurrent( |
49 | __deref_out_z LPWSTR* psczCurrentDirectory | 49 | __deref_out_z LPWSTR* psczCurrentDirectory, |
50 | __out_opt SIZE_T* pcch | ||
50 | ); | 51 | ); |
51 | 52 | ||
52 | HRESULT DAPI DirSetCurrent( | 53 | HRESULT DAPI DirSetCurrent( |
diff --git a/src/libs/dutil/WixToolset.DUtil/inc/fileutil.h b/src/libs/dutil/WixToolset.DUtil/inc/fileutil.h index d3e326f7..868312dc 100644 --- a/src/libs/dutil/WixToolset.DUtil/inc/fileutil.h +++ b/src/libs/dutil/WixToolset.DUtil/inc/fileutil.h | |||
@@ -34,13 +34,6 @@ typedef enum FILE_ENCODING | |||
34 | } FILE_ENCODING; | 34 | } FILE_ENCODING; |
35 | 35 | ||
36 | 36 | ||
37 | LPWSTR DAPI FileFromPath( | ||
38 | __in_z LPCWSTR wzPath | ||
39 | ); | ||
40 | HRESULT DAPI FileResolvePath( | ||
41 | __in_z LPCWSTR wzRelativePath, | ||
42 | __out LPWSTR *ppwzFullPath | ||
43 | ); | ||
44 | HRESULT DAPI FileStripExtension( | 37 | HRESULT DAPI FileStripExtension( |
45 | __in_z LPCWSTR wzFileName, | 38 | __in_z LPCWSTR wzFileName, |
46 | __out LPWSTR *ppwzFileNameNoExtension | 39 | __out LPWSTR *ppwzFileNameNoExtension |
diff --git a/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h b/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h index 941793f8..871e706b 100644 --- a/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h +++ b/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h | |||
@@ -68,6 +68,16 @@ DAPI_(HRESULT) PathExpand( | |||
68 | ); | 68 | ); |
69 | 69 | ||
70 | /******************************************************************* | 70 | /******************************************************************* |
71 | PathGetFullPathName - wrapper around GetFullPathNameW. | ||
72 | *******************************************************************/ | ||
73 | DAPI_(HRESULT) PathGetFullPathName( | ||
74 | __in_z LPCWSTR wzPath, | ||
75 | __deref_out_z LPWSTR* psczFullPath, | ||
76 | __inout_z_opt LPCWSTR* pwzFileName, | ||
77 | __out_opt SIZE_T* pcch | ||
78 | ); | ||
79 | |||
80 | /******************************************************************* | ||
71 | PathPrefix - prefixes a full path with \\?\ or \\?\UNC as | 81 | PathPrefix - prefixes a full path with \\?\ or \\?\UNC as |
72 | appropriate. | 82 | appropriate. |
73 | ********************************************************************/ | 83 | ********************************************************************/ |
diff --git a/src/libs/dutil/WixToolset.DUtil/logutil.cpp b/src/libs/dutil/WixToolset.DUtil/logutil.cpp index bd21098c..94c21374 100644 --- a/src/libs/dutil/WixToolset.DUtil/logutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/logutil.cpp | |||
@@ -117,6 +117,7 @@ extern "C" HRESULT DAPI LogOpen( | |||
117 | { | 117 | { |
118 | HRESULT hr = S_OK; | 118 | HRESULT hr = S_OK; |
119 | BOOL fEnteredCriticalSection = FALSE; | 119 | BOOL fEnteredCriticalSection = FALSE; |
120 | LPWSTR sczCombined = NULL; | ||
120 | LPWSTR sczLogDirectory = NULL; | 121 | LPWSTR sczLogDirectory = NULL; |
121 | 122 | ||
122 | ::EnterCriticalSection(&LogUtil_csLog); | 123 | ::EnterCriticalSection(&LogUtil_csLog); |
@@ -129,9 +130,20 @@ extern "C" HRESULT DAPI LogOpen( | |||
129 | } | 130 | } |
130 | else | 131 | else |
131 | { | 132 | { |
132 | hr = PathConcat(wzDirectory, wzLog, &LogUtil_sczLogPath); | 133 | hr = PathConcat(wzDirectory, wzLog, &sczCombined); |
133 | LoguExitOnFailure(hr, "Failed to combine the log path."); | 134 | LoguExitOnFailure(hr, "Failed to combine the log path."); |
134 | 135 | ||
136 | if (!PathIsFullyQualified(sczCombined, NULL)) | ||
137 | { | ||
138 | hr = PathExpand(&LogUtil_sczLogPath, sczCombined, PATH_EXPAND_FULLPATH); | ||
139 | LoguExitOnFailure(hr, "Failed to expand the log path."); | ||
140 | } | ||
141 | else | ||
142 | { | ||
143 | LogUtil_sczLogPath = sczCombined; | ||
144 | sczCombined = NULL; | ||
145 | } | ||
146 | |||
135 | hr = PathGetDirectory(LogUtil_sczLogPath, &sczLogDirectory); | 147 | hr = PathGetDirectory(LogUtil_sczLogPath, &sczLogDirectory); |
136 | LoguExitOnFailure(hr, "Failed to get log directory."); | 148 | LoguExitOnFailure(hr, "Failed to get log directory."); |
137 | 149 | ||
@@ -176,6 +188,7 @@ LExit: | |||
176 | ::LeaveCriticalSection(&LogUtil_csLog); | 188 | ::LeaveCriticalSection(&LogUtil_csLog); |
177 | } | 189 | } |
178 | 190 | ||
191 | ReleaseStr(sczCombined); | ||
179 | ReleaseStr(sczLogDirectory); | 192 | ReleaseStr(sczLogDirectory); |
180 | 193 | ||
181 | return hr; | 194 | return hr; |
diff --git a/src/libs/dutil/WixToolset.DUtil/pathutil.cpp b/src/libs/dutil/WixToolset.DUtil/pathutil.cpp index 99be003c..a9a19b9f 100644 --- a/src/libs/dutil/WixToolset.DUtil/pathutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/pathutil.cpp | |||
@@ -157,11 +157,12 @@ DAPI_(HRESULT) PathExpand( | |||
157 | __in DWORD dwResolveFlags | 157 | __in DWORD dwResolveFlags |
158 | ) | 158 | ) |
159 | { | 159 | { |
160 | Assert(wzRelativePath && *wzRelativePath); | 160 | Assert(wzRelativePath); |
161 | 161 | ||
162 | HRESULT hr = S_OK; | 162 | HRESULT hr = S_OK; |
163 | DWORD cch = 0; | 163 | DWORD cch = 0; |
164 | LPWSTR sczExpandedPath = NULL; | 164 | LPWSTR sczExpandedPath = NULL; |
165 | SIZE_T cchWritten = 0; | ||
165 | DWORD cchExpandedPath = 0; | 166 | DWORD cchExpandedPath = 0; |
166 | SIZE_T cbSize = 0; | 167 | SIZE_T cbSize = 0; |
167 | 168 | ||
@@ -221,37 +222,12 @@ DAPI_(HRESULT) PathExpand( | |||
221 | // | 222 | // |
222 | if (dwResolveFlags & PATH_EXPAND_FULLPATH) | 223 | if (dwResolveFlags & PATH_EXPAND_FULLPATH) |
223 | { | 224 | { |
224 | LPWSTR wzFileName = NULL; | ||
225 | LPCWSTR wzPath = sczExpandedPath ? sczExpandedPath : wzRelativePath; | 225 | LPCWSTR wzPath = sczExpandedPath ? sczExpandedPath : wzRelativePath; |
226 | DWORD cchFullPath = max(PATH_GOOD_ENOUGH, cchExpandedPath); | ||
227 | 226 | ||
228 | hr = StrAlloc(&sczFullPath, cchFullPath); | 227 | hr = PathGetFullPathName(wzPath, &sczFullPath, NULL, &cchWritten); |
229 | PathExitOnFailure(hr, "Failed to allocate space for full path."); | 228 | PathExitOnFailure(hr, "Failed to get full path for string: %ls", wzPath); |
230 | |||
231 | cch = ::GetFullPathNameW(wzPath, cchFullPath, sczFullPath, &wzFileName); | ||
232 | if (0 == cch) | ||
233 | { | ||
234 | PathExitWithLastError(hr, "Failed to get full path for string: %ls", wzPath); | ||
235 | } | ||
236 | else if (cchFullPath < cch) | ||
237 | { | ||
238 | cchFullPath = cch < MAX_PATH ? cch : cch + 7; // ensure space for "\\?\UNC" prefix if needed | ||
239 | hr = StrAlloc(&sczFullPath, cchFullPath); | ||
240 | PathExitOnFailure(hr, "Failed to re-allocate more space for full path."); | ||
241 | 229 | ||
242 | cch = ::GetFullPathNameW(wzPath, cchFullPath, sczFullPath, &wzFileName); | 230 | if (MAX_PATH < cchWritten) |
243 | if (0 == cch) | ||
244 | { | ||
245 | PathExitWithLastError(hr, "Failed to get full path for string: %ls", wzPath); | ||
246 | } | ||
247 | else if (cchFullPath < cch) | ||
248 | { | ||
249 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); | ||
250 | PathExitOnRootFailure(hr, "Failed to allocate buffer for full path."); | ||
251 | } | ||
252 | } | ||
253 | |||
254 | if (MAX_PATH < cch) | ||
255 | { | 231 | { |
256 | hr = PathPrefix(&sczFullPath); | 232 | hr = PathPrefix(&sczFullPath); |
257 | PathExitOnFailure(hr, "Failed to prefix long path after expanding."); | 233 | PathExitOnFailure(hr, "Failed to prefix long path after expanding."); |
@@ -263,7 +239,7 @@ DAPI_(HRESULT) PathExpand( | |||
263 | sczExpandedPath = NULL; | 239 | sczExpandedPath = NULL; |
264 | } | 240 | } |
265 | 241 | ||
266 | hr = StrAllocString(psczFullPath, sczFullPath? sczFullPath : wzRelativePath, 0); | 242 | hr = StrAllocString(psczFullPath, sczFullPath ? sczFullPath : wzRelativePath, 0); |
267 | PathExitOnFailure(hr, "Failed to copy relative path into full path."); | 243 | PathExitOnFailure(hr, "Failed to copy relative path into full path."); |
268 | 244 | ||
269 | LExit: | 245 | LExit: |
@@ -274,6 +250,74 @@ LExit: | |||
274 | } | 250 | } |
275 | 251 | ||
276 | 252 | ||
253 | DAPI_(HRESULT) PathGetFullPathName( | ||
254 | __in_z LPCWSTR wzPath, | ||
255 | __deref_out_z LPWSTR* psczFullPath, | ||
256 | __inout_z_opt LPCWSTR* pwzFileName, | ||
257 | __out_opt SIZE_T* pcch | ||
258 | ) | ||
259 | { | ||
260 | HRESULT hr = S_OK; | ||
261 | SIZE_T cchMax = 0; | ||
262 | DWORD cchBuffer = 0; | ||
263 | DWORD cch = 0; | ||
264 | DWORD dwAttempts = 0; | ||
265 | const DWORD dwMaxAttempts = 10; | ||
266 | |||
267 | if (!wzPath || !*wzPath) | ||
268 | { | ||
269 | hr = DirGetCurrent(psczFullPath, pcch); | ||
270 | PathExitOnFailure(hr, "Failed to get current directory."); | ||
271 | |||
272 | ExitFunction(); | ||
273 | } | ||
274 | |||
275 | if (*psczFullPath) | ||
276 | { | ||
277 | hr = StrMaxLength(*psczFullPath, &cchMax); | ||
278 | PathExitOnFailure(hr, "Failed to get max length of input buffer."); | ||
279 | |||
280 | cchBuffer = (DWORD)min(DWORD_MAX, cchMax); | ||
281 | } | ||
282 | else | ||
283 | { | ||
284 | cchBuffer = MAX_PATH + 1; | ||
285 | |||
286 | hr = StrAlloc(psczFullPath, cchBuffer); | ||
287 | PathExitOnFailure(hr, "Failed to allocate space for full path."); | ||
288 | } | ||
289 | |||
290 | for (; dwAttempts < dwMaxAttempts; ++dwAttempts) | ||
291 | { | ||
292 | cch = ::GetFullPathNameW(wzPath, cchBuffer, *psczFullPath, const_cast<LPWSTR*>(pwzFileName)); | ||
293 | PathExitOnNullWithLastError(cch, hr, "Failed to get full path for string: %ls", wzPath); | ||
294 | |||
295 | if (cch < cchBuffer) | ||
296 | { | ||
297 | break; | ||
298 | } | ||
299 | |||
300 | hr = StrAlloc(psczFullPath, cch); | ||
301 | PathExitOnFailure(hr, "Failed to reallocate space for full path."); | ||
302 | |||
303 | cchBuffer = cch; | ||
304 | } | ||
305 | |||
306 | if (dwMaxAttempts == dwAttempts) | ||
307 | { | ||
308 | PathExitWithRootFailure(hr, E_INSUFFICIENT_BUFFER, "GetFullPathNameW results never converged."); | ||
309 | } | ||
310 | |||
311 | if (pcch) | ||
312 | { | ||
313 | *pcch = cch; | ||
314 | } | ||
315 | |||
316 | LExit: | ||
317 | return hr; | ||
318 | } | ||
319 | |||
320 | |||
277 | DAPI_(HRESULT) PathPrefix( | 321 | DAPI_(HRESULT) PathPrefix( |
278 | __inout LPWSTR *psczFullPath | 322 | __inout LPWSTR *psczFullPath |
279 | ) | 323 | ) |
diff --git a/src/libs/dutil/WixToolset.DUtil/sceutil.cpp b/src/libs/dutil/WixToolset.DUtil/sceutil.cpp index cdb1623b..4eede74f 100644 --- a/src/libs/dutil/WixToolset.DUtil/sceutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/sceutil.cpp | |||
@@ -1491,11 +1491,8 @@ static HRESULT CreateSqlCe( | |||
1491 | // If that failed, fallback to loading from current path | 1491 | // If that failed, fallback to loading from current path |
1492 | if (NULL == *phSqlCeDll) | 1492 | if (NULL == *phSqlCeDll) |
1493 | { | 1493 | { |
1494 | hr = DirGetCurrent(&sczDirectory); | 1494 | hr = PathGetFullPathName(wzSqlCeDllPath, &sczDllFullPath, NULL, NULL); |
1495 | ExitOnFailure(hr, "Failed to get current directory"); | 1495 | ExitOnFailure(hr, "Failed to get full path for DLL"); |
1496 | |||
1497 | hr = PathConcat(sczDirectory, wzSqlCeDllPath, &sczDllFullPath); | ||
1498 | ExitOnFailure(hr, "Failed to concatenate current directory and DLL filename"); | ||
1499 | 1496 | ||
1500 | *phSqlCeDll = ::LoadLibraryW(sczDllFullPath); | 1497 | *phSqlCeDll = ::LoadLibraryW(sczDllFullPath); |
1501 | ExitOnNullWithLastError(*phSqlCeDll, hr, "Failed to open Sql CE DLL: %ls", sczDllFullPath); | 1498 | ExitOnNullWithLastError(*phSqlCeDll, hr, "Failed to open Sql CE DLL: %ls", sczDllFullPath); |