aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2021-08-03 15:41:02 -0500
committerSean Hall <r.sean.hall@gmail.com>2021-08-04 10:03:57 -0500
commited57d171f6fb6bb4e180696cc12caa568599566a (patch)
treec1e6cbe61440d44f3f11160512e12042ce7ddd2a
parent5815688519a60e63e18c13dfe0908d76757cbc53 (diff)
downloadwix-ed57d171f6fb6bb4e180696cc12caa568599566a.tar.gz
wix-ed57d171f6fb6bb4e180696cc12caa568599566a.tar.bz2
wix-ed57d171f6fb6bb4e180696cc12caa568599566a.zip
Get system TEMP path from the registry.
Also, correctly handle return codes from related path APIs.
-rw-r--r--src/burn/engine/cache.cpp23
-rw-r--r--src/burn/engine/variable.cpp1
-rw-r--r--src/libs/dutil/WixToolset.DUtil/inc/pathutil.h16
-rw-r--r--src/libs/dutil/WixToolset.DUtil/pathutil.cpp87
4 files changed, 112 insertions, 15 deletions
diff --git a/src/burn/engine/cache.cpp b/src/burn/engine/cache.cpp
index 61416aed..a35b83bc 100644
--- a/src/burn/engine/cache.cpp
+++ b/src/burn/engine/cache.cpp
@@ -1281,7 +1281,7 @@ static HRESULT CalculateWorkingFolder(
1281 HRESULT hr = S_OK; 1281 HRESULT hr = S_OK;
1282 RPC_STATUS rs = RPC_S_OK; 1282 RPC_STATUS rs = RPC_S_OK;
1283 BOOL fElevated = FALSE; 1283 BOOL fElevated = FALSE;
1284 WCHAR wzTempPath[MAX_PATH] = { }; 1284 LPWSTR sczTempPath = NULL;
1285 UUID guid = {}; 1285 UUID guid = {};
1286 WCHAR wzGuid[39]; 1286 WCHAR wzGuid[39];
1287 1287
@@ -1291,20 +1291,13 @@ static HRESULT CalculateWorkingFolder(
1291 1291
1292 if (fElevated) 1292 if (fElevated)
1293 { 1293 {
1294 if (!::GetWindowsDirectoryW(wzTempPath, countof(wzTempPath))) 1294 hr = PathGetSystemTempPath(&sczTempPath);
1295 { 1295 ExitOnFailure(hr, "Failed to get system temp folder path for working folder.");
1296 ExitWithLastError(hr, "Failed to get windows path for working folder.");
1297 }
1298
1299 hr = PathFixedBackslashTerminate(wzTempPath, countof(wzTempPath));
1300 ExitOnFailure(hr, "Failed to ensure windows path for working folder ended in backslash.");
1301
1302 hr = ::StringCchCatW(wzTempPath, countof(wzTempPath), L"Temp\\");
1303 ExitOnFailure(hr, "Failed to concat Temp directory on windows path for working folder.");
1304 } 1296 }
1305 else if (0 == ::GetTempPathW(countof(wzTempPath), wzTempPath)) 1297 else
1306 { 1298 {
1307 ExitWithLastError(hr, "Failed to get temp path for working folder."); 1299 hr = PathGetTempPath(&sczTempPath);
1300 ExitOnFailure(hr, "Failed to get temp folder path for working folder.");
1308 } 1301 }
1309 1302
1310 rs = ::UuidCreate(&guid); 1303 rs = ::UuidCreate(&guid);
@@ -1317,7 +1310,7 @@ static HRESULT CalculateWorkingFolder(
1317 ExitOnRootFailure(hr, "Failed to convert working folder guid into string."); 1310 ExitOnRootFailure(hr, "Failed to convert working folder guid into string.");
1318 } 1311 }
1319 1312
1320 hr = StrAllocFormatted(&vsczWorkingFolder, L"%ls%ls\\", wzTempPath, wzGuid); 1313 hr = StrAllocFormatted(&vsczWorkingFolder, L"%ls%ls\\", sczTempPath, wzGuid);
1321 ExitOnFailure(hr, "Failed to append bundle id on to temp path for working folder."); 1314 ExitOnFailure(hr, "Failed to append bundle id on to temp path for working folder.");
1322 } 1315 }
1323 1316
@@ -1325,6 +1318,8 @@ static HRESULT CalculateWorkingFolder(
1325 ExitOnFailure(hr, "Failed to copy working folder path."); 1318 ExitOnFailure(hr, "Failed to copy working folder path.");
1326 1319
1327LExit: 1320LExit:
1321 ReleaseStr(sczTempPath);
1322
1328 return hr; 1323 return hr;
1329} 1324}
1330 1325
diff --git a/src/burn/engine/variable.cpp b/src/burn/engine/variable.cpp
index e2b1f1f2..e7391a9f 100644
--- a/src/burn/engine/variable.cpp
+++ b/src/burn/engine/variable.cpp
@@ -1916,7 +1916,6 @@ static HRESULT InitializeVariableTempFolder(
1916 HRESULT hr = S_OK; 1916 HRESULT hr = S_OK;
1917 WCHAR wzPath[MAX_PATH] = { }; 1917 WCHAR wzPath[MAX_PATH] = { };
1918 1918
1919 // get volume path name
1920 if (!::GetTempPathW(MAX_PATH, wzPath)) 1919 if (!::GetTempPathW(MAX_PATH, wzPath))
1921 { 1920 {
1922 ExitWithLastError(hr, "Failed to get temp path."); 1921 ExitWithLastError(hr, "Failed to get temp path.");
diff --git a/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h b/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h
index 579b8454..0ae9f437 100644
--- a/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h
+++ b/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h
@@ -151,6 +151,22 @@ DAPI_(HRESULT) PathCreateTempDirectory(
151 ); 151 );
152 152
153/******************************************************************* 153/*******************************************************************
154 PathGetTempPath - returns the path to the temp folder
155 that is backslash terminated.
156*******************************************************************/
157DAPI_(HRESULT) PathGetTempPath(
158 __out_z LPWSTR* psczTempPath
159 );
160
161/*******************************************************************
162 PathGetSystemTempPath - returns the path to the system temp folder
163 that is backslash terminated.
164*******************************************************************/
165DAPI_(HRESULT) PathGetSystemTempPath(
166 __out_z LPWSTR* psczSystemTempPath
167 );
168
169/*******************************************************************
154 PathGetKnownFolder - returns the path to a well-known shell folder 170 PathGetKnownFolder - returns the path to a well-known shell folder
155 171
156*******************************************************************/ 172*******************************************************************/
diff --git a/src/libs/dutil/WixToolset.DUtil/pathutil.cpp b/src/libs/dutil/WixToolset.DUtil/pathutil.cpp
index 7c3cfe06..5fad519b 100644
--- a/src/libs/dutil/WixToolset.DUtil/pathutil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/pathutil.cpp
@@ -9,6 +9,7 @@
9#define PathExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__) 9#define PathExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__)
10#define PathExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__) 10#define PathExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__)
11#define PathExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__) 11#define PathExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__)
12#define PathExitWithRootFailure(x, e, s, ...) ExitWithRootFailureSource(DUTIL_SOURCE_PATHUTIL, x, e, s, __VA_ARGS__)
12#define PathExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__) 13#define PathExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_PATHUTIL, x, s, __VA_ARGS__)
13#define PathExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_PATHUTIL, p, x, e, s, __VA_ARGS__) 14#define PathExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_PATHUTIL, p, x, e, s, __VA_ARGS__)
14#define PathExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_PATHUTIL, p, x, s, __VA_ARGS__) 15#define PathExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_PATHUTIL, p, x, s, __VA_ARGS__)
@@ -814,6 +815,92 @@ LExit:
814} 815}
815 816
816 817
818DAPI_(HRESULT) PathGetTempPath(
819 __out_z LPWSTR* psczTempPath
820 )
821{
822 HRESULT hr = S_OK;
823 WCHAR wzTempPath[MAX_PATH + 1] = { };
824 DWORD cch = 0;
825
826 cch = ::GetTempPathW(countof(wzTempPath), wzTempPath);
827 if (!cch)
828 {
829 PathExitWithLastError(hr, "Failed to GetTempPath.");
830 }
831 else if (cch >= countof(wzTempPath))
832 {
833 PathExitWithRootFailure(hr, E_INSUFFICIENT_BUFFER, "TEMP directory path too long.");
834 }
835
836 hr = StrAllocString(psczTempPath, wzTempPath, cch);
837 PathExitOnFailure(hr, "Failed to copy TEMP directory path.");
838
839LExit:
840 return hr;
841}
842
843
844DAPI_(HRESULT) PathGetSystemTempPath(
845 __out_z LPWSTR* psczSystemTempPath
846 )
847{
848 HRESULT hr = S_OK;
849 HKEY hKey = NULL;
850 WCHAR wzTempPath[MAX_PATH + 1] = { };
851 DWORD cch = 0;
852
853 // There is no documented API to get system environment variables, so read them from the registry.
854 hr = RegOpen(HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\Session Manager\\Environment", KEY_READ, &hKey);
855 if (E_FILENOTFOUND != hr)
856 {
857 PathExitOnFailure(hr, "Failed to open system environment registry key.");
858
859 // Follow documented precedence rules for TMP/TEMP from ::GetTempPath.
860 // TODO: values will be expanded with the current environment variables instead of the system environment variables.
861 hr = RegReadString(hKey, L"TMP", psczSystemTempPath);
862 if (E_FILENOTFOUND != hr)
863 {
864 PathExitOnFailure(hr, "Failed to get system TMP value.");
865
866 hr = PathBackslashTerminate(psczSystemTempPath);
867 PathExitOnFailure(hr, "Failed to backslash terminate system TMP value.");
868
869 ExitFunction();
870 }
871
872 hr = RegReadString(hKey, L"TEMP", psczSystemTempPath);
873 if (E_FILENOTFOUND != hr)
874 {
875 PathExitOnFailure(hr, "Failed to get system TEMP value.");
876
877 hr = PathBackslashTerminate(psczSystemTempPath);
878 PathExitOnFailure(hr, "Failed to backslash terminate system TEMP value.");
879
880 ExitFunction();
881 }
882 }
883
884 cch = ::GetSystemWindowsDirectoryW(wzTempPath, countof(wzTempPath));
885 if (!cch)
886 {
887 PathExitWithLastError(hr, "Failed to get Windows directory path.");
888 }
889 else if (cch >= countof(wzTempPath))
890 {
891 PathExitWithRootFailure(hr, E_INSUFFICIENT_BUFFER, "Windows directory path too long.");
892 }
893
894 hr = PathConcat(wzTempPath, L"TEMP\\", psczSystemTempPath);
895 PathExitOnFailure(hr, "Failed to concat Temp directory on Windows directory path.");
896
897LExit:
898 ReleaseRegKey(hKey);
899
900 return hr;
901}
902
903
817DAPI_(HRESULT) PathGetKnownFolder( 904DAPI_(HRESULT) PathGetKnownFolder(
818 __in int csidl, 905 __in int csidl,
819 __out LPWSTR* psczKnownFolder 906 __out LPWSTR* psczKnownFolder