MCPcopy Create free account
hub / github.com/Kitware/CMake / LoadPackageRegistryWin

Method LoadPackageRegistryWin

Source/cmFindPackageCommand.cxx:2664–2716  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2662}
2663
2664void cmFindPackageCommand::LoadPackageRegistryWin(bool const user,
2665 unsigned int const view,
2666 cmSearchPath& outPaths)
2667{
2668 std::wstring key = L"Software\\Kitware\\CMake\\Packages\\";
2669 key += cmsys::Encoding::ToWide(this->Name);
2670 std::set<std::wstring> bad;
2671 HKEY hKey;
2672 if (RegOpenKeyExW(user ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, key.c_str(),
2673 0, KEY_QUERY_VALUE | view, &hKey) == ERROR_SUCCESS) {
2674 DWORD valueType = REG_NONE;
2675 wchar_t name[16383]; // RegEnumValue docs limit name to 32767 _bytes_
2676 std::vector<wchar_t> data(512);
2677 bool done = false;
2678 DWORD index = 0;
2679 while (!done) {
2680 DWORD nameSize = static_cast<DWORD>(sizeof(name));
2681 DWORD dataSize = static_cast<DWORD>(data.size() * sizeof(data[0]));
2682 switch (RegEnumValueW(hKey, index, name, &nameSize, 0, &valueType,
2683 (BYTE*)&data[0], &dataSize)) {
2684 case ERROR_SUCCESS:
2685 ++index;
2686 if (valueType == REG_SZ) {
2687 data[dataSize] = 0;
2688 if (!this->CheckPackageRegistryEntry(
2689 cmsys::Encoding::ToNarrow(&data[0]), outPaths)) {
2690 // The entry is invalid.
2691 bad.insert(name);
2692 }
2693 }
2694 break;
2695 case ERROR_MORE_DATA:
2696 data.resize((dataSize + sizeof(data[0]) - 1) / sizeof(data[0]));
2697 break;
2698 case ERROR_NO_MORE_ITEMS:
2699 default:
2700 done = true;
2701 break;
2702 }
2703 }
2704 RegCloseKey(hKey);
2705 }
2706
2707 // Remove bad values if possible.
2708 if (user && !bad.empty() &&
2709 RegOpenKeyExW(HKEY_CURRENT_USER, key.c_str(), 0, KEY_SET_VALUE | view,
2710 &hKey) == ERROR_SUCCESS) {
2711 for (std::wstring const& v : bad) {
2712 RegDeleteValueW(hKey, v.c_str());
2713 }
2714 RegCloseKey(hKey);
2715 }
2716}
2717
2718#else
2719void cmFindPackageCommand::LoadPackageRegistryDir(std::string const& dir,

Callers 2

Calls 6

c_strMethod · 0.80
sizeMethod · 0.45
insertMethod · 0.45
resizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected