From 8b6f46af50651e0b1faf7adf94a179c6e16a05b1 Mon Sep 17 00:00:00 2001 From: Sean Hall <r.sean.hall@gmail.com> Date: Thu, 26 May 2022 17:31:36 -0500 Subject: PathEnsureQuoted is not generally useful. --- src/ext/NetFx/ca/netfxca.cpp | 58 ++++++++++++++++++++++++++ src/ext/NetFx/ca/precomp.h | 1 + src/libs/dutil/WixToolset.DUtil/inc/pathutil.h | 10 ----- src/libs/dutil/WixToolset.DUtil/pathutil.cpp | 58 -------------------------- 4 files changed, 59 insertions(+), 68 deletions(-) diff --git a/src/ext/NetFx/ca/netfxca.cpp b/src/ext/NetFx/ca/netfxca.cpp index 1182464e..f0704790 100644 --- a/src/ext/NetFx/ca/netfxca.cpp +++ b/src/ext/NetFx/ca/netfxca.cpp @@ -280,6 +280,64 @@ LExit: return hr; } +// This has netfxca specific functionality, like turning " into "" and leaving an unescaped \ at the end of a directory. +static HRESULT PathEnsureQuoted( + __inout LPWSTR* ppszPath, + __in BOOL fDirectory + ) +{ + Assert(ppszPath && *ppszPath); + + HRESULT hr = S_OK; + size_t cchPath = 0; + + hr = ::StringCchLengthW(*ppszPath, STRSAFE_MAX_CCH, &cchPath); + ExitOnFailure(hr, "Failed to get the length of the path."); + + // Handle simple special cases. + if (0 == cchPath || (1 == cchPath && L'"' == (*ppszPath)[0])) + { + hr = StrAllocString(ppszPath, L"\"\"", 2); + ExitOnFailure(hr, "Failed to allocate a quoted empty string."); + + ExitFunction(); + } + + if (L'"' != (*ppszPath)[0]) + { + hr = StrAllocPrefix(ppszPath, L"\"", 1); + ExitOnFailure(hr, "Failed to allocate an opening quote."); + + // Add a char for the opening quote. + ++cchPath; + } + + if (L'"' != (*ppszPath)[cchPath - 1]) + { + hr = StrAllocConcat(ppszPath, L"\"", 1); + ExitOnFailure(hr, "Failed to allocate a closing quote."); + + // Add a char for the closing quote. + ++cchPath; + } + + if (fDirectory) + { + if (L'\\' != (*ppszPath)[cchPath - 2]) + { + // Change the last char to a backslash and re-append the closing quote. + (*ppszPath)[cchPath - 1] = L'\\'; + + hr = StrAllocConcat(ppszPath, L"\"", 1); + ExitOnFailure(hr, "Failed to allocate another closing quote after the backslash."); + } + } + +LExit: + + return hr; +} + static HRESULT CreateInstallCommand( __out LPWSTR* ppwzCommandLine, __in LPCWSTR pwzNgenPath, diff --git a/src/ext/NetFx/ca/precomp.h b/src/ext/NetFx/ca/precomp.h index 4a83c164..f7b537ed 100644 --- a/src/ext/NetFx/ca/precomp.h +++ b/src/ext/NetFx/ca/precomp.h @@ -4,6 +4,7 @@ #include <windows.h> #include <msiquery.h> +#include <strsafe.h> #include "wcautil.h" #include "fileutil.h" diff --git a/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h b/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h index 00a468ce..44d36568 100644 --- a/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h +++ b/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h @@ -195,16 +195,6 @@ DAPI_(HRESULT) PathConcatCch( __deref_out_z LPWSTR* psczCombined ); -/******************************************************************* - PathEnsureQuoted - ensures that a path is quoted; optionally, - this function also terminates a directory with a backslash - if it is not already. -*******************************************************************/ -DAPI_(HRESULT) PathEnsureQuoted( - __inout LPWSTR* ppszPath, - __in BOOL fDirectory - ); - /******************************************************************* PathCompare - compares the fully expanded path of the two paths using ::CompareStringW(). diff --git a/src/libs/dutil/WixToolset.DUtil/pathutil.cpp b/src/libs/dutil/WixToolset.DUtil/pathutil.cpp index 7bac8ac3..fa07f165 100644 --- a/src/libs/dutil/WixToolset.DUtil/pathutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/pathutil.cpp @@ -875,64 +875,6 @@ LExit: } -DAPI_(HRESULT) PathEnsureQuoted( - __inout LPWSTR* ppszPath, - __in BOOL fDirectory - ) -{ - Assert(ppszPath && *ppszPath); - - HRESULT hr = S_OK; - size_t cchPath = 0; - - hr = ::StringCchLengthW(*ppszPath, STRSAFE_MAX_CCH, &cchPath); - PathExitOnFailure(hr, "Failed to get the length of the path."); - - // Handle simple special cases. - if (0 == cchPath || (1 == cchPath && L'"' == (*ppszPath)[0])) - { - hr = StrAllocString(ppszPath, L"\"\"", 2); - PathExitOnFailure(hr, "Failed to allocate a quoted empty string."); - - ExitFunction(); - } - - if (L'"' != (*ppszPath)[0]) - { - hr = StrAllocPrefix(ppszPath, L"\"", 1); - PathExitOnFailure(hr, "Failed to allocate an opening quote."); - - // Add a char for the opening quote. - ++cchPath; - } - - if (L'"' != (*ppszPath)[cchPath - 1]) - { - hr = StrAllocConcat(ppszPath, L"\"", 1); - PathExitOnFailure(hr, "Failed to allocate a closing quote."); - - // Add a char for the closing quote. - ++cchPath; - } - - if (fDirectory) - { - if (L'\\' != (*ppszPath)[cchPath - 2]) - { - // Change the last char to a backslash and re-append the closing quote. - (*ppszPath)[cchPath - 1] = L'\\'; - - hr = StrAllocConcat(ppszPath, L"\"", 1); - PathExitOnFailure(hr, "Failed to allocate another closing quote after the backslash."); - } - } - -LExit: - - return hr; -} - - DAPI_(HRESULT) PathCompare( __in_z LPCWSTR wzPath1, __in_z LPCWSTR wzPath2, -- cgit v1.2.3-55-g6feb