std::filesystem::path install_root()

in platforms/Windows/CustomActions/SwiftInstaller/Sources/swift_installer.cc [74:94]


std::filesystem::path install_root() noexcept {
  DWORD cbData = 0;

  if (FAILED(RegGetValueW(HKEY_LOCAL_MACHINE, kits_installed_roots_keypath,
                          kits_root_key, RRF_RT_REG_SZ, nullptr, nullptr,
                          &cbData)))
    return {};

  if (cbData == 0)
    return {};

  std::vector<wchar_t> buffer;
  buffer.resize(cbData);

  if (FAILED(RegGetValueW(HKEY_LOCAL_MACHINE, kits_installed_roots_keypath,
                          kits_root_key, RRF_RT_REG_SZ, nullptr, buffer.data(),
                          &cbData)))
    return {};

  return std::filesystem::path(buffer.data());
}