aboutsummaryrefslogtreecommitdiff
path: root/src/burn/engine/search.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/burn/engine/search.cpp')
-rw-r--r--src/burn/engine/search.cpp89
1 files changed, 40 insertions, 49 deletions
diff --git a/src/burn/engine/search.cpp b/src/burn/engine/search.cpp
index b37dc9bd..a1b6b74a 100644
--- a/src/burn/engine/search.cpp
+++ b/src/burn/engine/search.cpp
@@ -610,6 +610,7 @@ static HRESULT DirectorySearchExists(
610 ) 610 )
611{ 611{
612 HRESULT hr = S_OK; 612 HRESULT hr = S_OK;
613 DWORD er = ERROR_SUCCESS;
613 LPWSTR sczPath = NULL; 614 LPWSTR sczPath = NULL;
614 BOOL fExists = FALSE; 615 BOOL fExists = FALSE;
615 616
@@ -629,21 +630,25 @@ static HRESULT DirectorySearchExists(
629 DWORD dwAttributes = ::GetFileAttributesW(sczPath); 630 DWORD dwAttributes = ::GetFileAttributesW(sczPath);
630 if (INVALID_FILE_ATTRIBUTES == dwAttributes) 631 if (INVALID_FILE_ATTRIBUTES == dwAttributes)
631 { 632 {
632 hr = HRESULT_FROM_WIN32(::GetLastError()); 633 er = ::GetLastError();
633 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) 634 if (ERROR_FILE_NOT_FOUND == er || ERROR_PATH_NOT_FOUND == er)
634 { 635 {
635 hr = S_OK; // didn't find file, fExists still is false. 636 LogStringLine(REPORT_STANDARD, "Directory search: %ls, did not find path: %ls", pSearch->sczKey, pSearch->DirectorySearch.sczPath);
637 }
638 else
639 {
640 ExitOnWin32Error(er, hr, "Directory search: %ls, failed get to directory attributes. '%ls'", pSearch->sczKey, pSearch->DirectorySearch.sczPath);
636 } 641 }
637 } 642 }
638 else if (dwAttributes & FILE_ATTRIBUTE_DIRECTORY) 643 else if (FILE_ATTRIBUTE_DIRECTORY != (dwAttributes & FILE_ATTRIBUTE_DIRECTORY))
644 {
645 LogStringLine(REPORT_STANDARD, "Directory search: %ls, found file at path: %ls", pSearch->sczKey, pSearch->DirectorySearch.sczPath);
646 }
647 else
639 { 648 {
640 fExists = TRUE; 649 fExists = TRUE;
641 } 650 }
642 651
643 // else must have found a file.
644 // What if there is a hidden variable in sczPath?
645 ExitOnFailure(hr, "Failed while searching directory search: %ls, for path: %ls", pSearch->sczKey, sczPath);
646
647 // set variable 652 // set variable
648 hr = VariableSetNumeric(pVariables, pSearch->sczVariable, fExists, FALSE); 653 hr = VariableSetNumeric(pVariables, pSearch->sczVariable, fExists, FALSE);
649 ExitOnFailure(hr, "Failed to set variable."); 654 ExitOnFailure(hr, "Failed to set variable.");
@@ -694,13 +699,12 @@ static HRESULT DirectorySearchPath(
694 hr = E_PATHNOTFOUND; 699 hr = E_PATHNOTFOUND;
695 } 700 }
696 701
697 // What if there is a hidden variable in sczPath?
698 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) 702 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr)
699 { 703 {
700 LogStringLine(REPORT_STANDARD, "Directory search: %ls, did not find path: %ls, reason: 0x%x", pSearch->sczKey, sczPath, hr); 704 LogStringLine(REPORT_STANDARD, "Directory search: %ls, did not find path: %ls, reason: 0x%x", pSearch->sczKey, pSearch->DirectorySearch.sczPath, hr);
701 ExitFunction1(hr = S_OK); 705 ExitFunction1(hr = S_OK);
702 } 706 }
703 ExitOnFailure(hr, "Failed while searching directory search: %ls, for path: %ls", pSearch->sczKey, sczPath); 707 ExitOnFailure(hr, "Failed while searching directory search: %ls, for path: %ls", pSearch->sczKey, pSearch->DirectorySearch.sczPath);
704 708
705LExit: 709LExit:
706#if !defined(_WIN64) 710#if !defined(_WIN64)
@@ -742,15 +746,18 @@ static HRESULT FileSearchExists(
742 er = ::GetLastError(); 746 er = ::GetLastError();
743 if (ERROR_FILE_NOT_FOUND == er || ERROR_PATH_NOT_FOUND == er) 747 if (ERROR_FILE_NOT_FOUND == er || ERROR_PATH_NOT_FOUND == er)
744 { 748 {
745 // What if there is a hidden variable in sczPath? 749 LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, pSearch->FileSearch.sczPath);
746 LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, sczPath);
747 } 750 }
748 else 751 else
749 { 752 {
750 ExitOnWin32Error(er, hr, "Failed get to file attributes. '%ls'", pSearch->FileSearch.sczPath); 753 ExitOnWin32Error(er, hr, "File search: %ls, failed get to file attributes. '%ls'", pSearch->sczKey, pSearch->FileSearch.sczPath);
751 } 754 }
752 } 755 }
753 else if (FILE_ATTRIBUTE_DIRECTORY != (dwAttributes & FILE_ATTRIBUTE_DIRECTORY)) 756 else if (FILE_ATTRIBUTE_DIRECTORY == (dwAttributes & FILE_ATTRIBUTE_DIRECTORY))
757 {
758 LogStringLine(REPORT_STANDARD, "File search: %ls, found directory at path: %ls", pSearch->sczKey, pSearch->FileSearch.sczPath);
759 }
760 else
754 { 761 {
755 fExists = TRUE; 762 fExists = TRUE;
756 } 763 }
@@ -795,8 +802,7 @@ static HRESULT FileSearchVersion(
795 hr = FileVersion(sczPath, &uliVersion.HighPart, &uliVersion.LowPart); 802 hr = FileVersion(sczPath, &uliVersion.HighPart, &uliVersion.LowPart);
796 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) 803 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr)
797 { 804 {
798 // What if there is a hidden variable in sczPath? 805 LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, pSearch->FileSearch.sczPath);
799 LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, sczPath);
800 ExitFunction1(hr = S_OK); 806 ExitFunction1(hr = S_OK);
801 } 807 }
802 ExitOnFailure(hr, "Failed to get file version."); 808 ExitOnFailure(hr, "Failed to get file version.");
@@ -854,13 +860,12 @@ static HRESULT FileSearchPath(
854 ExitOnFailure(hr, "Failed to set variable to file search path."); 860 ExitOnFailure(hr, "Failed to set variable to file search path.");
855 } 861 }
856 862
857 // What if there is a hidden variable in sczPath?
858 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) 863 if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr)
859 { 864 {
860 LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, sczPath); 865 LogStringLine(REPORT_STANDARD, "File search: %ls, did not find path: %ls", pSearch->sczKey, pSearch->FileSearch.sczPath);
861 ExitFunction1(hr = S_OK); 866 ExitFunction1(hr = S_OK);
862 } 867 }
863 ExitOnFailure(hr, "Failed while searching file search: %ls, for path: %ls", pSearch->sczKey, sczPath); 868 ExitOnFailure(hr, "Failed while searching file search: %ls, for path: %ls", pSearch->sczKey, pSearch->FileSearch.sczPath);
864 869
865LExit: 870LExit:
866#if !defined(_WIN64) 871#if !defined(_WIN64)
@@ -891,24 +896,13 @@ static HRESULT RegistrySearchExists(
891 896
892 // open key 897 // open key
893 hr = RegOpenEx(pSearch->RegistrySearch.hRoot, sczKey, KEY_QUERY_VALUE, pSearch->RegistrySearch.fWin64 ? REG_KEY_64BIT : REG_KEY_32BIT, &hKey); 898 hr = RegOpenEx(pSearch->RegistrySearch.hRoot, sczKey, KEY_QUERY_VALUE, pSearch->RegistrySearch.fWin64 ? REG_KEY_64BIT : REG_KEY_32BIT, &hKey);
894 if (SUCCEEDED(hr)) 899 ExitOnPathFailure(hr, fExists, "Failed to open registry key. Key = '%ls'", pSearch->RegistrySearch.sczKey);
895 { 900
896 fExists = TRUE; 901 if (!fExists)
897 }
898 else if (E_FILENOTFOUND == hr)
899 {
900 // What if there is a hidden variable in sczKey?
901 LogStringLine(REPORT_STANDARD, "Registry key not found. Key = '%ls'", sczKey);
902 fExists = FALSE;
903 hr = S_OK;
904 }
905 else
906 { 902 {
907 // What if there is a hidden variable in sczKey? 903 LogStringLine(REPORT_STANDARD, "Registry key not found. Key = '%ls'", pSearch->RegistrySearch.sczKey);
908 ExitOnFailure(hr, "Failed to open registry key. Key = '%ls'", sczKey);
909 } 904 }
910 905 else if (pSearch->RegistrySearch.sczValue)
911 if (fExists && pSearch->RegistrySearch.sczValue)
912 { 906 {
913 // format value string 907 // format value string
914 hr = VariableFormatString(pVariables, pSearch->RegistrySearch.sczValue, &sczValue, NULL); 908 hr = VariableFormatString(pVariables, pSearch->RegistrySearch.sczValue, &sczValue, NULL);
@@ -922,8 +916,7 @@ static HRESULT RegistrySearchExists(
922 fExists = TRUE; 916 fExists = TRUE;
923 break; 917 break;
924 case ERROR_FILE_NOT_FOUND: 918 case ERROR_FILE_NOT_FOUND:
925 // What if there is a hidden variable in sczKey or sczValue? 919 LogStringLine(REPORT_STANDARD, "Registry value not found. Key = '%ls', Value = '%ls'", pSearch->RegistrySearch.sczKey, pSearch->RegistrySearch.sczValue);
926 LogStringLine(REPORT_STANDARD, "Registry value not found. Key = '%ls', Value = '%ls'", sczKey, sczValue);
927 fExists = FALSE; 920 fExists = FALSE;
928 break; 921 break;
929 default: 922 default:
@@ -938,8 +931,7 @@ static HRESULT RegistrySearchExists(
938LExit: 931LExit:
939 if (FAILED(hr)) 932 if (FAILED(hr))
940 { 933 {
941 // What if there is a hidden variable in sczKey? 934 LogStringLine(REPORT_STANDARD, "RegistrySearchExists failed: ID '%ls', HRESULT 0x%x", pSearch->sczKey, hr);
942 LogStringLine(REPORT_STANDARD, "RegistrySearchExists failed: ID '%ls', HRESULT 0x%x", sczKey, hr);
943 } 935 }
944 936
945 StrSecureZeroFreeString(sczKey); 937 StrSecureZeroFreeString(sczKey);
@@ -958,6 +950,7 @@ static HRESULT RegistrySearchValue(
958 LPWSTR sczKey = NULL; 950 LPWSTR sczKey = NULL;
959 LPWSTR sczValue = NULL; 951 LPWSTR sczValue = NULL;
960 HKEY hKey = NULL; 952 HKEY hKey = NULL;
953 BOOL fExists = FALSE;
961 DWORD dwType = 0; 954 DWORD dwType = 0;
962 SIZE_T cbData = 0; 955 SIZE_T cbData = 0;
963 LPBYTE pData = NULL; 956 LPBYTE pData = NULL;
@@ -978,21 +971,20 @@ static HRESULT RegistrySearchValue(
978 971
979 // open key 972 // open key
980 hr = RegOpenEx(pSearch->RegistrySearch.hRoot, sczKey, KEY_QUERY_VALUE, pSearch->RegistrySearch.fWin64 ? REG_KEY_64BIT : REG_KEY_32BIT, &hKey); 973 hr = RegOpenEx(pSearch->RegistrySearch.hRoot, sczKey, KEY_QUERY_VALUE, pSearch->RegistrySearch.fWin64 ? REG_KEY_64BIT : REG_KEY_32BIT, &hKey);
981 if (E_FILENOTFOUND == hr) 974 ExitOnPathFailure(hr, fExists, "Failed to open registry key.");
975
976 if (!fExists)
982 { 977 {
983 // What if there is a hidden variable in sczKey? 978 LogStringLine(REPORT_STANDARD, "Registry key not found. Key = '%ls'", pSearch->RegistrySearch.sczKey);
984 LogStringLine(REPORT_STANDARD, "Registry key not found. Key = '%ls'", sczKey);
985 979
986 ExitFunction1(hr = S_OK); 980 ExitFunction();
987 } 981 }
988 ExitOnFailure(hr, "Failed to open registry key.");
989 982
990 // get value 983 // get value
991 hr = RegReadValue(hKey, sczValue, pSearch->RegistrySearch.fExpandEnvironment, &pData, &cbData, &dwType); 984 hr = RegReadValue(hKey, sczValue, pSearch->RegistrySearch.fExpandEnvironment, &pData, &cbData, &dwType);
992 if (E_FILENOTFOUND == hr) 985 if (E_FILENOTFOUND == hr)
993 { 986 {
994 // What if there is a hidden variable in sczKey or sczValue? 987 LogStringLine(REPORT_STANDARD, "Registry value not found. Key = '%ls', Value = '%ls'", pSearch->RegistrySearch.sczKey, pSearch->RegistrySearch.sczValue);
995 LogStringLine(REPORT_STANDARD, "Registry value not found. Key = '%ls', Value = '%ls'", sczKey, sczValue);
996 988
997 ExitFunction1(hr = S_OK); 989 ExitFunction1(hr = S_OK);
998 } 990 }
@@ -1034,8 +1026,7 @@ static HRESULT RegistrySearchValue(
1034LExit: 1026LExit:
1035 if (FAILED(hr)) 1027 if (FAILED(hr))
1036 { 1028 {
1037 // What if there is a hidden variable in sczKey? 1029 LogStringLine(REPORT_STANDARD, "RegistrySearchValue failed: ID '%ls', HRESULT 0x%x", pSearch->sczKey, hr);
1038 LogStringLine(REPORT_STANDARD, "RegistrySearchValue failed: ID '%ls', HRESULT 0x%x", sczKey, hr);
1039 } 1030 }
1040 1031
1041 StrSecureZeroFreeString(sczKey); 1032 StrSecureZeroFreeString(sczKey);