diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2022-06-03 17:48:57 -0500 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2022-06-07 19:44:36 -0500 |
| commit | 648f370f7966b2738c1446601057d888bbd2c70f (patch) | |
| tree | 9022566b1016f94127dfb7e84c9b4dfa057993cd /src/libs/dutil/WixToolset.DUtil/pathutil.cpp | |
| parent | 6b0f2d978504da82070523eb6adb0b59f9812e93 (diff) | |
| download | wix-648f370f7966b2738c1446601057d888bbd2c70f.tar.gz wix-648f370f7966b2738c1446601057d888bbd2c70f.tar.bz2 wix-648f370f7966b2738c1446601057d888bbd2c70f.zip | |
Make PathGetSystemPath return an array of paths ordered by preference.
Diffstat (limited to '')
| -rw-r--r-- | src/libs/dutil/WixToolset.DUtil/pathutil.cpp | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/pathutil.cpp b/src/libs/dutil/WixToolset.DUtil/pathutil.cpp index 1ac76626..dc33e656 100644 --- a/src/libs/dutil/WixToolset.DUtil/pathutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/pathutil.cpp | |||
| @@ -923,12 +923,14 @@ LExit: | |||
| 923 | } | 923 | } |
| 924 | 924 | ||
| 925 | 925 | ||
| 926 | DAPI_(HRESULT) PathGetSystemTempPath( | 926 | DAPI_(HRESULT) PathGetSystemTempPaths( |
| 927 | __out_z LPWSTR* psczSystemTempPath | 927 | __inout_z LPWSTR** prgsczSystemTempPaths, |
| 928 | __inout DWORD* pcSystemTempPaths | ||
| 928 | ) | 929 | ) |
| 929 | { | 930 | { |
| 930 | HRESULT hr = S_OK; | 931 | HRESULT hr = S_OK; |
| 931 | HKEY hKey = NULL; | 932 | HKEY hKey = NULL; |
| 933 | LPWSTR sczTemp = NULL; | ||
| 932 | WCHAR wzTempPath[MAX_PATH + 1] = { }; | 934 | WCHAR wzTempPath[MAX_PATH + 1] = { }; |
| 933 | DWORD cch = 0; | 935 | DWORD cch = 0; |
| 934 | 936 | ||
| @@ -940,26 +942,36 @@ DAPI_(HRESULT) PathGetSystemTempPath( | |||
| 940 | 942 | ||
| 941 | // Follow documented precedence rules for TMP/TEMP from ::GetTempPath. | 943 | // Follow documented precedence rules for TMP/TEMP from ::GetTempPath. |
| 942 | // TODO: values will be expanded with the current environment variables instead of the system environment variables. | 944 | // TODO: values will be expanded with the current environment variables instead of the system environment variables. |
| 943 | hr = RegReadString(hKey, L"TMP", psczSystemTempPath); | 945 | hr = RegReadString(hKey, L"TMP", &sczTemp); |
| 944 | if (E_FILENOTFOUND != hr) | 946 | if (E_FILENOTFOUND != hr) |
| 945 | { | 947 | { |
| 946 | PathExitOnFailure(hr, "Failed to get system TMP value."); | 948 | PathExitOnFailure(hr, "Failed to get system TMP value."); |
| 947 | 949 | ||
| 948 | hr = PathBackslashTerminate(psczSystemTempPath); | 950 | hr = PathBackslashTerminate(&sczTemp); |
| 949 | PathExitOnFailure(hr, "Failed to backslash terminate system TMP value."); | 951 | PathExitOnFailure(hr, "Failed to backslash terminate system TMP value."); |
| 950 | 952 | ||
| 951 | ExitFunction(); | 953 | hr = MemEnsureArraySizeForNewItems(reinterpret_cast<LPVOID*>(prgsczSystemTempPaths), *pcSystemTempPaths, 1, sizeof(LPWSTR), 3); |
| 954 | PathExitOnFailure(hr, "Failed to ensure array size for system TMP value."); | ||
| 955 | |||
| 956 | (*prgsczSystemTempPaths)[*pcSystemTempPaths] = sczTemp; | ||
| 957 | sczTemp = NULL; | ||
| 958 | *pcSystemTempPaths += 1; | ||
| 952 | } | 959 | } |
| 953 | 960 | ||
| 954 | hr = RegReadString(hKey, L"TEMP", psczSystemTempPath); | 961 | hr = RegReadString(hKey, L"TEMP", &sczTemp); |
| 955 | if (E_FILENOTFOUND != hr) | 962 | if (E_FILENOTFOUND != hr) |
| 956 | { | 963 | { |
| 957 | PathExitOnFailure(hr, "Failed to get system TEMP value."); | 964 | PathExitOnFailure(hr, "Failed to get system TEMP value."); |
| 958 | 965 | ||
| 959 | hr = PathBackslashTerminate(psczSystemTempPath); | 966 | hr = PathBackslashTerminate(&sczTemp); |
| 960 | PathExitOnFailure(hr, "Failed to backslash terminate system TEMP value."); | 967 | PathExitOnFailure(hr, "Failed to backslash terminate system TEMP value."); |
| 961 | 968 | ||
| 962 | ExitFunction(); | 969 | hr = MemEnsureArraySizeForNewItems(reinterpret_cast<LPVOID*>(prgsczSystemTempPaths), *pcSystemTempPaths, 1, sizeof(LPWSTR), 2); |
| 970 | PathExitOnFailure(hr, "Failed to ensure array size for system TEMP value."); | ||
| 971 | |||
| 972 | (*prgsczSystemTempPaths)[*pcSystemTempPaths] = sczTemp; | ||
| 973 | sczTemp = NULL; | ||
| 974 | *pcSystemTempPaths += 1; | ||
| 963 | } | 975 | } |
| 964 | } | 976 | } |
| 965 | 977 | ||
| @@ -973,11 +985,19 @@ DAPI_(HRESULT) PathGetSystemTempPath( | |||
| 973 | PathExitWithRootFailure(hr, E_INSUFFICIENT_BUFFER, "Windows directory path too long."); | 985 | PathExitWithRootFailure(hr, E_INSUFFICIENT_BUFFER, "Windows directory path too long."); |
| 974 | } | 986 | } |
| 975 | 987 | ||
| 976 | hr = PathConcat(wzTempPath, L"TEMP\\", psczSystemTempPath); | 988 | hr = PathConcat(wzTempPath, L"TEMP\\", &sczTemp); |
| 977 | PathExitOnFailure(hr, "Failed to concat Temp directory on Windows directory path."); | 989 | PathExitOnFailure(hr, "Failed to concat Temp directory on Windows directory path."); |
| 978 | 990 | ||
| 991 | hr = MemEnsureArraySizeForNewItems(reinterpret_cast<LPVOID*>(prgsczSystemTempPaths), *pcSystemTempPaths, 1, sizeof(LPWSTR), 1); | ||
| 992 | PathExitOnFailure(hr, "Failed to ensure array size for Windows\\TEMP value."); | ||
| 993 | |||
| 994 | (*prgsczSystemTempPaths)[*pcSystemTempPaths] = sczTemp; | ||
| 995 | sczTemp = NULL; | ||
| 996 | *pcSystemTempPaths += 1; | ||
| 997 | |||
| 979 | LExit: | 998 | LExit: |
| 980 | ReleaseRegKey(hKey); | 999 | ReleaseRegKey(hKey); |
| 1000 | ReleaseStr(sczTemp); | ||
| 981 | 1001 | ||
| 982 | return hr; | 1002 | return hr; |
| 983 | } | 1003 | } |
