void RegistryQuery::ProcessRuntimeFiles()

in library/src/RegistryQuery.cpp [112:147]


void RegistryQuery::ProcessRuntimeFiles(Device& device, wstring_view key, bool isWow64)
{
	try
	{
		// Determine whether we are adding runtime files to the device's System32 list or SysWOW64 list
		auto& list = (isWow64) ? device.RuntimeFilesWow64 : device.RuntimeFiles;
		
		// Attempt to open the specified registry key and enumerate its REG_MULTI_SZ values
		unique_hkey registryKey = RegistryQuery::OpenKeyFromString(device.DriverRegistryKey + L"\\" + wstring(key));
		auto files = RegistryQuery::EnumerateMultiStringValues(registryKey);
		for (const auto& pair : files)
		{
			if (!pair.second.empty())
			{
				// Construct a RuntimeFile from the string values
				RuntimeFile newFile(pair.second[0], ((pair.second.size() == 2) ? pair.second[1] : L""));
				
				// Check whether the destination filename for the runtime file clashes with an existing file
				auto existing = std::find_if(list.begin(), list.end(), [newFile](RuntimeFile f) {
					return f.DestinationFilename == newFile.DestinationFilename;
				});
				
				// Only add the new runtime file to the list if there's no clash
				if (existing == list.end()) {
					list.push_back(newFile);
				}
				else {
					LOG(L"{}: ignoring runtime file with duplicate destination filename {}", key, newFile.DestinationFilename);
				}
			}
		}
	}
	catch (const DeviceDiscoveryError& err) {
		LOG(L"Could not enumerate runtime files for the {} key: {}", key, err.message);
	}
}