From b652e93a460b4b822a01382e5992f96f1d805ffe Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Fri, 3 Jun 2022 17:47:54 -0500 Subject: Replace PathCompare with PathCompareCanonicalized. --- src/libs/dutil/WixToolset.DUtil/fileutil.cpp | 156 --------------------------- 1 file changed, 156 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 2fe04de1..9f68ee52 100644 --- a/src/libs/dutil/WixToolset.DUtil/fileutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/fileutil.cpp @@ -22,9 +22,6 @@ const BYTE UTF8BOM[] = {0xEF, 0xBB, 0xBF}; 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"; - /******************************************************************* FileStripExtension - Strip extension from filename @@ -526,159 +523,6 @@ extern "C" BOOL DAPI FileExistsEx( } -/******************************************************************* - FileExistsAfterRestart - checks that a file exists and will continue - to exist after restart. - -********************************************************************/ -extern "C" BOOL DAPI FileExistsAfterRestart( - __in_z LPCWSTR wzPath, - __out_opt DWORD *pdwAttributes - ) -{ - HRESULT hr = S_OK; - BOOL fExists = FALSE; - HKEY hkPendingFileRename = NULL; - LPWSTR* rgsczRenames = NULL; - DWORD cRenames = 0; - int nCompare = 0; - - fExists = FileExistsEx(wzPath, pdwAttributes); - if (fExists) - { - hr = RegOpen(HKEY_LOCAL_MACHINE, REGISTRY_PENDING_FILE_RENAME_KEY, KEY_QUERY_VALUE, &hkPendingFileRename); - if (E_FILENOTFOUND == hr) - { - ExitFunction1(hr = S_OK); - } - FileExitOnFailure(hr, "Failed to open pending file rename registry key."); - - hr = RegReadStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, &rgsczRenames, &cRenames); - if (E_FILENOTFOUND == hr) - { - ExitFunction1(hr = S_OK); - } - FileExitOnFailure(hr, "Failed to read pending file renames."); - - // The pending file renames array is pairs of source and target paths. We only care - // about checking the source paths so skip the target paths (i += 2). - for (DWORD i = 0; i < cRenames; i += 2) - { - LPWSTR wzRename = rgsczRenames[i]; - if (wzRename && *wzRename) - { - // Skip the long path designator if present. - if (L'\\' == wzRename[0] && L'?' == wzRename[1] && L'?' == wzRename[2] && L'\\' == wzRename[3]) - { - wzRename += 4; - } - - hr = PathCompare(wzPath, wzRename, &nCompare); - FileExitOnFailure(hr, "Failed to compare path from pending file rename to check path."); - - if (CSTR_EQUAL == nCompare) - { - fExists = FALSE; - break; - } - } - } - } - -LExit: - ReleaseStrArray(rgsczRenames, cRenames); - ReleaseRegKey(hkPendingFileRename); - - return fExists; -} - - -/******************************************************************* - FileRemoveFromPendingRename - removes the file path from the pending - file rename list. - -********************************************************************/ -extern "C" HRESULT DAPI FileRemoveFromPendingRename( - __in_z LPCWSTR wzPath - ) -{ - HRESULT hr = S_OK; - HKEY hkPendingFileRename = NULL; - LPWSTR* rgsczRenames = NULL; - DWORD cRenames = 0; - int nCompare = 0; - BOOL fRemoved = FALSE; - DWORD cNewRenames = 0; - - hr = RegOpen(HKEY_LOCAL_MACHINE, REGISTRY_PENDING_FILE_RENAME_KEY, KEY_QUERY_VALUE | KEY_SET_VALUE, &hkPendingFileRename); - if (E_FILENOTFOUND == hr) - { - ExitFunction1(hr = S_OK); - } - FileExitOnFailure(hr, "Failed to open pending file rename registry key."); - - hr = RegReadStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, &rgsczRenames, &cRenames); - if (E_FILENOTFOUND == hr) - { - ExitFunction1(hr = S_OK); - } - FileExitOnFailure(hr, "Failed to read pending file renames."); - - // The pending file renames array is pairs of source and target paths. We only care - // about checking the source paths so skip the target paths (i += 2). - for (DWORD i = 0; i < cRenames; i += 2) - { - LPWSTR wzRename = rgsczRenames[i]; - if (wzRename && *wzRename) - { - // Skip the long path designator if present. - if (L'\\' == wzRename[0] && L'?' == wzRename[1] && L'?' == wzRename[2] && L'\\' == wzRename[3]) - { - wzRename += 4; - } - - hr = PathCompare(wzPath, wzRename, &nCompare); - FileExitOnFailure(hr, "Failed to compare path from pending file rename to check path."); - - // If we find our path in the list, null out the source and target slot and - // we'll compact the array next. - if (CSTR_EQUAL == nCompare) - { - ReleaseNullStr(rgsczRenames[i]); - ReleaseNullStr(rgsczRenames[i + 1]); - fRemoved = TRUE; - } - } - } - - if (fRemoved) - { - // Compact the array by removing any nulls. - for (DWORD i = 0; i < cRenames; ++i) - { - LPWSTR wzRename = rgsczRenames[i]; - if (wzRename) - { - rgsczRenames[cNewRenames] = wzRename; - ++cNewRenames; - } - } - - cRenames = cNewRenames; // ignore the pointers on the end of the array since an early index points to them already. - - // Write the new array back to the pending file rename key. - hr = RegWriteStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, rgsczRenames, cRenames); - FileExitOnFailure(hr, "Failed to update pending file renames."); - } - -LExit: - ReleaseStrArray(rgsczRenames, cRenames); - ReleaseRegKey(hkPendingFileRename); - - return hr; -} - - /******************************************************************* FileRead - read a file into memory -- cgit v1.2.3-55-g6feb