From 8a4d03207633e9fdc364aaed82bd167f844679f9 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Fri, 3 Jun 2022 17:47:31 -0500 Subject: Resolve paths while parsing them from the command line. The current directory is a process wide setting that can potentially be changed by any thread. Remove fileutil methods that had equivalent pathutil methods. --- src/libs/dutil/WixToolset.DUtil/fileutil.cpp | 118 --------------------------- 1 file changed, 118 deletions(-) (limited to 'src/libs/dutil/WixToolset.DUtil/fileutil.cpp') 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}; const LPCWSTR REGISTRY_PENDING_FILE_RENAME_KEY = L"SYSTEM\\CurrentControlSet\\Control\\Session Manager"; const LPCWSTR REGISTRY_PENDING_FILE_RENAME_VALUE = L"PendingFileRenameOperations"; -/******************************************************************* - FileFromPath - returns a pointer to the file part of the path - -********************************************************************/ -extern "C" LPWSTR DAPI FileFromPath( - __in_z LPCWSTR wzPath - ) -{ - if (!wzPath) - return NULL; - - LPWSTR wzFile = const_cast(wzPath); - for (LPWSTR wz = wzFile; *wz; ++wz) - { - // valid delineators - // \ => Windows path - // / => unix and URL path - // : => relative path from mapped root - if (L'\\' == *wz || L'/' == *wz || L':' == *wz) - wzFile = wz + 1; - } - - return wzFile; -} - - -/******************************************************************* - FileResolvePath - gets the full path to a file resolving environment - variables along the way. - -********************************************************************/ -extern "C" HRESULT DAPI FileResolvePath( - __in_z LPCWSTR wzRelativePath, - __out LPWSTR *ppwzFullPath - ) -{ - Assert(wzRelativePath && *wzRelativePath); - - HRESULT hr = S_OK; - DWORD cch = 0; - LPWSTR pwzExpandedPath = NULL; - DWORD cchExpandedPath = 0; - - LPWSTR pwzFullPath = NULL; - DWORD cchFullPath = 0; - - LPWSTR wzFileName = NULL; - - // - // First, expand any environment variables. - // - cchExpandedPath = MAX_PATH; - hr = StrAlloc(&pwzExpandedPath, cchExpandedPath); - FileExitOnFailure(hr, "Failed to allocate space for expanded path."); - - cch = ::ExpandEnvironmentStringsW(wzRelativePath, pwzExpandedPath, cchExpandedPath); - if (0 == cch) - { - FileExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath); - } - else if (cchExpandedPath < cch) - { - cchExpandedPath = cch; - hr = StrAlloc(&pwzExpandedPath, cchExpandedPath); - FileExitOnFailure(hr, "Failed to re-allocate more space for expanded path."); - - cch = ::ExpandEnvironmentStringsW(wzRelativePath, pwzExpandedPath, cchExpandedPath); - if (0 == cch) - { - FileExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath); - } - else if (cchExpandedPath < cch) - { - hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); - FileExitOnRootFailure(hr, "Failed to allocate buffer for expanded path."); - } - } - - // - // Second, get the full path. - // - cchFullPath = MAX_PATH; - hr = StrAlloc(&pwzFullPath, cchFullPath); - FileExitOnFailure(hr, "Failed to allocate space for full path."); - - cch = ::GetFullPathNameW(pwzExpandedPath, cchFullPath, pwzFullPath, &wzFileName); - if (0 == cch) - { - FileExitWithLastError(hr, "Failed to get full path for string: %ls", pwzExpandedPath); - } - else if (cchFullPath < cch) - { - cchFullPath = cch; - hr = StrAlloc(&pwzFullPath, cchFullPath); - FileExitOnFailure(hr, "Failed to re-allocate more space for full path."); - - cch = ::GetFullPathNameW(pwzExpandedPath, cchFullPath, pwzFullPath, &wzFileName); - if (0 == cch) - { - FileExitWithLastError(hr, "Failed to get full path for string: %ls", pwzExpandedPath); - } - else if (cchFullPath < cch) - { - hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); - FileExitOnRootFailure(hr, "Failed to allocate buffer for full path."); - } - } - - *ppwzFullPath = pwzFullPath; - pwzFullPath = NULL; - -LExit: - ReleaseStr(pwzFullPath); - ReleaseStr(pwzExpandedPath); - - return hr; -} - /******************************************************************* FileStripExtension - Strip extension from filename -- cgit v1.2.3-55-g6feb