summaryrefslogtreecommitdiff
path: root/src/libs/dutil/WixToolset.DUtil/fileutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/fileutil.cpp')
-rw-r--r--src/libs/dutil/WixToolset.DUtil/fileutil.cpp156
1 files changed, 0 insertions, 156 deletions
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 @@
22const BYTE UTF8BOM[] = {0xEF, 0xBB, 0xBF}; 22const BYTE UTF8BOM[] = {0xEF, 0xBB, 0xBF};
23const BYTE UTF16BOM[] = {0xFF, 0xFE}; 23const BYTE UTF16BOM[] = {0xFF, 0xFE};
24 24
25const LPCWSTR REGISTRY_PENDING_FILE_RENAME_KEY = L"SYSTEM\\CurrentControlSet\\Control\\Session Manager";
26const LPCWSTR REGISTRY_PENDING_FILE_RENAME_VALUE = L"PendingFileRenameOperations";
27
28 25
29/******************************************************************* 26/*******************************************************************
30FileStripExtension - Strip extension from filename 27FileStripExtension - Strip extension from filename
@@ -527,159 +524,6 @@ extern "C" BOOL DAPI FileExistsEx(
527 524
528 525
529/******************************************************************* 526/*******************************************************************
530 FileExistsAfterRestart - checks that a file exists and will continue
531 to exist after restart.
532
533********************************************************************/
534extern "C" BOOL DAPI FileExistsAfterRestart(
535 __in_z LPCWSTR wzPath,
536 __out_opt DWORD *pdwAttributes
537 )
538{
539 HRESULT hr = S_OK;
540 BOOL fExists = FALSE;
541 HKEY hkPendingFileRename = NULL;
542 LPWSTR* rgsczRenames = NULL;
543 DWORD cRenames = 0;
544 int nCompare = 0;
545
546 fExists = FileExistsEx(wzPath, pdwAttributes);
547 if (fExists)
548 {
549 hr = RegOpen(HKEY_LOCAL_MACHINE, REGISTRY_PENDING_FILE_RENAME_KEY, KEY_QUERY_VALUE, &hkPendingFileRename);
550 if (E_FILENOTFOUND == hr)
551 {
552 ExitFunction1(hr = S_OK);
553 }
554 FileExitOnFailure(hr, "Failed to open pending file rename registry key.");
555
556 hr = RegReadStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, &rgsczRenames, &cRenames);
557 if (E_FILENOTFOUND == hr)
558 {
559 ExitFunction1(hr = S_OK);
560 }
561 FileExitOnFailure(hr, "Failed to read pending file renames.");
562
563 // The pending file renames array is pairs of source and target paths. We only care
564 // about checking the source paths so skip the target paths (i += 2).
565 for (DWORD i = 0; i < cRenames; i += 2)
566 {
567 LPWSTR wzRename = rgsczRenames[i];
568 if (wzRename && *wzRename)
569 {
570 // Skip the long path designator if present.
571 if (L'\\' == wzRename[0] && L'?' == wzRename[1] && L'?' == wzRename[2] && L'\\' == wzRename[3])
572 {
573 wzRename += 4;
574 }
575
576 hr = PathCompare(wzPath, wzRename, &nCompare);
577 FileExitOnFailure(hr, "Failed to compare path from pending file rename to check path.");
578
579 if (CSTR_EQUAL == nCompare)
580 {
581 fExists = FALSE;
582 break;
583 }
584 }
585 }
586 }
587
588LExit:
589 ReleaseStrArray(rgsczRenames, cRenames);
590 ReleaseRegKey(hkPendingFileRename);
591
592 return fExists;
593}
594
595
596/*******************************************************************
597 FileRemoveFromPendingRename - removes the file path from the pending
598 file rename list.
599
600********************************************************************/
601extern "C" HRESULT DAPI FileRemoveFromPendingRename(
602 __in_z LPCWSTR wzPath
603 )
604{
605 HRESULT hr = S_OK;
606 HKEY hkPendingFileRename = NULL;
607 LPWSTR* rgsczRenames = NULL;
608 DWORD cRenames = 0;
609 int nCompare = 0;
610 BOOL fRemoved = FALSE;
611 DWORD cNewRenames = 0;
612
613 hr = RegOpen(HKEY_LOCAL_MACHINE, REGISTRY_PENDING_FILE_RENAME_KEY, KEY_QUERY_VALUE | KEY_SET_VALUE, &hkPendingFileRename);
614 if (E_FILENOTFOUND == hr)
615 {
616 ExitFunction1(hr = S_OK);
617 }
618 FileExitOnFailure(hr, "Failed to open pending file rename registry key.");
619
620 hr = RegReadStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, &rgsczRenames, &cRenames);
621 if (E_FILENOTFOUND == hr)
622 {
623 ExitFunction1(hr = S_OK);
624 }
625 FileExitOnFailure(hr, "Failed to read pending file renames.");
626
627 // The pending file renames array is pairs of source and target paths. We only care
628 // about checking the source paths so skip the target paths (i += 2).
629 for (DWORD i = 0; i < cRenames; i += 2)
630 {
631 LPWSTR wzRename = rgsczRenames[i];
632 if (wzRename && *wzRename)
633 {
634 // Skip the long path designator if present.
635 if (L'\\' == wzRename[0] && L'?' == wzRename[1] && L'?' == wzRename[2] && L'\\' == wzRename[3])
636 {
637 wzRename += 4;
638 }
639
640 hr = PathCompare(wzPath, wzRename, &nCompare);
641 FileExitOnFailure(hr, "Failed to compare path from pending file rename to check path.");
642
643 // If we find our path in the list, null out the source and target slot and
644 // we'll compact the array next.
645 if (CSTR_EQUAL == nCompare)
646 {
647 ReleaseNullStr(rgsczRenames[i]);
648 ReleaseNullStr(rgsczRenames[i + 1]);
649 fRemoved = TRUE;
650 }
651 }
652 }
653
654 if (fRemoved)
655 {
656 // Compact the array by removing any nulls.
657 for (DWORD i = 0; i < cRenames; ++i)
658 {
659 LPWSTR wzRename = rgsczRenames[i];
660 if (wzRename)
661 {
662 rgsczRenames[cNewRenames] = wzRename;
663 ++cNewRenames;
664 }
665 }
666
667 cRenames = cNewRenames; // ignore the pointers on the end of the array since an early index points to them already.
668
669 // Write the new array back to the pending file rename key.
670 hr = RegWriteStringArray(hkPendingFileRename, REGISTRY_PENDING_FILE_RENAME_VALUE, rgsczRenames, cRenames);
671 FileExitOnFailure(hr, "Failed to update pending file renames.");
672 }
673
674LExit:
675 ReleaseStrArray(rgsczRenames, cRenames);
676 ReleaseRegKey(hkPendingFileRename);
677
678 return hr;
679}
680
681
682/*******************************************************************
683 FileRead - read a file into memory 527 FileRead - read a file into memory
684 528
685********************************************************************/ 529********************************************************************/