MCPcopy Create free account
hub / github.com/BeneficialCode/WinArk / FindNextWorker

Method FindNextWorker

WinArk/RegistrySearcher.cpp:68–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66}
67
68bool RegistrySearcher::FindNextWorker(HKEY hKey, const CString& path) {
69 if (WAIT_OBJECT_0 == ::WaitForSingleObject(_hCancelEvent.get(), 0)) {
70 _cancel = true;
71 return false;
72 }
73
74 bool searchValues = (_options & FindOptions::SearchValues) == FindOptions::SearchValues;
75 bool searchKeys = (_options & FindOptions::SearchKeys) == FindOptions::SearchKeys;
76 bool searchData = (_options & FindOptions::SearchData) == FindOptions::SearchData;
77 bool caseSensitive = (_options & FindOptions::MatchCase) == FindOptions::MatchCase;
78 bool wholeWords = (_options & FindOptions::MatchWholeWords) == FindOptions::MatchWholeWords;
79
80 {
81 std::lock_guard locker(_lock);
82 if (!caseSensitive)
83 _searchText.MakeUpper();
84 }
85
86 auto compare = [&](auto& text, auto& search) {
87 int n = text.Find(search);
88 if (n >= 0)
89 return !wholeWords || ((n == 0 || isspace(text[n - 1])
90 && (n + _searchText.GetLength() == text.GetLength() ||
91 isspace(text[n + _searchText.GetLength()]))));
92 return false;
93 };
94
95 if (searchValues || searchData) {
96 Registry::EnumKeyValues(hKey, [&](auto type, auto name, auto size) {
97 if (WAIT_OBJECT_0 == ::WaitForSingleObject(_hCancelEvent.get(), 0)) {
98 _cancel = true;
99 return false;
100 }
101
102 if (searchValues) {
103 CString text(name);
104 if (!caseSensitive)
105 text.MakeUpper();
106
107 if (compare(text, _searchText)) {
108 if (Notify(path, name, nullptr))
109 return false;
110 }
111 }
112 if (searchData) {
113 if (type == REG_SZ || type == REG_EXPAND_SZ) {
114 // just in cast the value is not stored properly in the Registry
115 size += 4 + (size % 2);
116 ATLASSERT(size % 2 == 0);
117 auto buffer = std::make_unique<WCHAR[]>(size / sizeof(WCHAR));
118 if (buffer) {
119 ::ZeroMemory(buffer.get(), size);
120 DWORD bytes = size;
121 if (ERROR_SUCCESS == ::RegQueryValueEx(hKey, name, nullptr, nullptr, (BYTE*)buffer.get(), &bytes)) {
122 CString text(buffer.get());
123 if (!caseSensitive)
124 text.MakeUpper();
125 if (compare(text, _searchText)) {

Callers

nothing calls this directly

Calls 5

FindMethod · 0.80
IsEmptyMethod · 0.80
GetLengthMethod · 0.45
OpenMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected