Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read registry value data on demand #3642

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/AppInstallerSharedLib/GroupPolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,23 @@ namespace AppInstaller::Settings
typename Mapping::value_t items;
for (const auto& value : listKey->Values())
{
auto item = Mapping::ReadAndValidateItem(value);
if (item.has_value())
std::optional<Registry::Value> potentialValue = value.Value();

if (potentialValue)
{
items.emplace_back(std::move(item.value()));
auto item = Mapping::ReadAndValidateItem(potentialValue.value());
if (item.has_value())
{
items.emplace_back(std::move(item.value()));
}
else
{
AICLI_LOG(Core, Warning, << "Failed to read Group Policy list value. Policy [" << Mapping::KeyName << "], Value [" << value.Name() << ']');
}
}
else
{
AICLI_LOG(Core, Warning, << "Failed to read Group Policy list value. Policy [" << Mapping::KeyName << "], Value [" << value.Name() << ']');
AICLI_LOG(Core, Verbose, << "Group Policy list value not found. Policy [" << Mapping::KeyName << "], Value [" << value.Name() << ']');
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/AppInstallerSharedLib/Public/winget/Registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,21 @@ namespace AppInstaller::Registry

struct const_iterator;

struct ValueRef : Value
struct ValueRef
{
friend const_iterator;

// Gets the name of the value.
std::string Name() const;

// Gets the actual value of the value.
// The optional allows for the potential race with the value being removed.
std::optional<Value> Value() const;

private:
ValueRef(std::wstring&& valueName, DWORD type, std::vector<BYTE>&& data);
ValueRef(wil::shared_hkey key, std::wstring&& valueName);

wil::shared_hkey m_key;
std::wstring m_valueName;
};

Expand Down
23 changes: 14 additions & 9 deletions src/AppInstallerSharedLib/Registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,25 @@ namespace AppInstaller::Registry
return m_type == type;
}

ValueList::ValueRef::ValueRef(std::wstring&& valueName, DWORD type, std::vector<BYTE>&& data) : Value(type, std::move(data)), m_valueName(std::move(valueName)) {}
ValueList::ValueRef::ValueRef(wil::shared_hkey key, std::wstring&& valueName) : m_key(std::move(key)), m_valueName(std::move(valueName)) {}

std::string ValueList::ValueRef::Name() const
{
return Utility::ConvertToUTF8(m_valueName);
}

std::optional<Value> ValueList::ValueRef::Value() const
{
DWORD type;
std::vector<BYTE> data;
if (!TryGetRegistryValueData(m_key, m_valueName, type, data))
{
return std::nullopt;
}

return Registry::Value{ type, std::move(data) };
}

ValueList::const_iterator& ValueList::const_iterator::operator++()
{
++m_index;
Expand Down Expand Up @@ -232,14 +244,7 @@ namespace AppInstaller::Registry
return;
}

DWORD type;
std::vector<BYTE> data;
if (!TryGetRegistryValueData(m_key, valueName, type, data))
{
THROW_HR(E_UNEXPECTED);
}

m_value = ValueRef{ std::move(valueName), type, std::move(data) };
m_value = ValueRef{ m_key, std::move(valueName) };
}

const ValueList::ValueRef& ValueList::const_iterator::operator*() const
Expand Down