diff options
Diffstat (limited to '')
| -rw-r--r-- | src/libs/dutil/WixToolset.DUtil/guidutil.cpp | 4 | ||||
| -rw-r--r-- | src/libs/dutil/WixToolset.DUtil/inc/pathutil.h | 9 | ||||
| -rw-r--r-- | src/libs/dutil/WixToolset.DUtil/pathutil.cpp | 38 | ||||
| -rw-r--r-- | src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp | 28 |
4 files changed, 64 insertions, 15 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/guidutil.cpp b/src/libs/dutil/WixToolset.DUtil/guidutil.cpp index 204c9af2..946c256f 100644 --- a/src/libs/dutil/WixToolset.DUtil/guidutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/guidutil.cpp | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #define GuidExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__) | 9 | #define GuidExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__) |
| 10 | #define GuidExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__) | 10 | #define GuidExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__) |
| 11 | #define GuidExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__) | 11 | #define GuidExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__) |
| 12 | #define GuidExitWithRootFailure(x, e, s, ...) ExitWithRootFailureSource(DUTIL_SOURCE_GUIDUTIL, x, e, s, __VA_ARGS__) | ||
| 12 | #define GuidExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__) | 13 | #define GuidExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_GUIDUTIL, x, s, __VA_ARGS__) |
| 13 | #define GuidExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_GUIDUTIL, p, x, e, s, __VA_ARGS__) | 14 | #define GuidExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_GUIDUTIL, p, x, e, s, __VA_ARGS__) |
| 14 | #define GuidExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_GUIDUTIL, p, x, s, __VA_ARGS__) | 15 | #define GuidExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_GUIDUTIL, p, x, s, __VA_ARGS__) |
| @@ -29,8 +30,7 @@ extern "C" HRESULT DAPI GuidFixedCreate( | |||
| 29 | 30 | ||
| 30 | if (!::StringFromGUID2(guid, wzGuid, GUID_STRING_LENGTH)) | 31 | if (!::StringFromGUID2(guid, wzGuid, GUID_STRING_LENGTH)) |
| 31 | { | 32 | { |
| 32 | hr = E_OUTOFMEMORY; | 33 | GuidExitWithRootFailure(hr, E_OUTOFMEMORY, "Failed to convert guid into string."); |
| 33 | GuidExitOnRootFailure(hr, "Failed to convert guid into string."); | ||
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | LExit: | 36 | LExit: |
diff --git a/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h b/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h index 727318f2..875cfafb 100644 --- a/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h +++ b/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h | |||
| @@ -205,11 +205,12 @@ DAPI_(HRESULT) PathGetTempPath( | |||
| 205 | ); | 205 | ); |
| 206 | 206 | ||
| 207 | /******************************************************************* | 207 | /******************************************************************* |
| 208 | PathGetSystemTempPath - returns the path to the system temp folder | 208 | PathGetSystemTempPaths - returns the paths to system temp folders |
| 209 | that is backslash terminated. | 209 | that are backslash terminated with higher preference first. |
| 210 | *******************************************************************/ | 210 | *******************************************************************/ |
| 211 | DAPI_(HRESULT) PathGetSystemTempPath( | 211 | DAPI_(HRESULT) PathGetSystemTempPaths( |
| 212 | __out_z LPWSTR* psczSystemTempPath | 212 | __inout_z LPWSTR** prgsczSystemTempPaths, |
| 213 | __inout DWORD* pcSystemTempPaths | ||
| 213 | ); | 214 | ); |
| 214 | 215 | ||
| 215 | /******************************************************************* | 216 | /******************************************************************* |
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 | } |
diff --git a/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp b/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp index d1d304d3..e9ef1047 100644 --- a/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp +++ b/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp | |||
| @@ -800,6 +800,34 @@ namespace DutilTests | |||
| 800 | } | 800 | } |
| 801 | 801 | ||
| 802 | [Fact] | 802 | [Fact] |
| 803 | void PathGetSystemTempPathsTest() | ||
| 804 | { | ||
| 805 | HRESULT hr = S_OK; | ||
| 806 | LPWSTR* rgsczPaths = NULL; | ||
| 807 | DWORD cPaths = 0; | ||
| 808 | DWORD cPathsOriginal = 0; | ||
| 809 | |||
| 810 | try | ||
| 811 | { | ||
| 812 | hr = PathGetSystemTempPaths(&rgsczPaths, &cPaths); | ||
| 813 | NativeAssert::Succeeded(hr, "PathGetSystemTempPaths failed."); | ||
| 814 | |||
| 815 | Assert::InRange<DWORD>(cPaths, 1, 3); | ||
| 816 | WixAssert::StringEqual(Environment::ExpandEnvironmentVariables("%windir%\\temp\\"), gcnew String(rgsczPaths[cPaths - 1]), true); | ||
| 817 | |||
| 818 | cPathsOriginal = cPaths; | ||
| 819 | |||
| 820 | hr = PathGetSystemTempPaths(&rgsczPaths, &cPaths); | ||
| 821 | NativeAssert::Succeeded(hr, "PathGetSystemTempPaths failed."); | ||
| 822 | Assert::Equal(cPathsOriginal * 2, cPaths); | ||
| 823 | } | ||
| 824 | finally | ||
| 825 | { | ||
| 826 | ReleaseStrArray(rgsczPaths, cPaths); | ||
| 827 | } | ||
| 828 | } | ||
| 829 | |||
| 830 | [Fact] | ||
| 803 | void PathNormalizeSlashesFixedTest() | 831 | void PathNormalizeSlashesFixedTest() |
| 804 | { | 832 | { |
| 805 | HRESULT hr = S_OK; | 833 | HRESULT hr = S_OK; |
