Repository: microsoft/PowerToys
File: src/common/utils/gpo.h (C/C++)

Code before:
            else if (value != 1)
            {
                // Value not found on the path.
                machine_list_found = false;
            }
            else
            {
                // value found and equals to 1 
                machine_list_found = true;
            }
        }

        // read value from machine list
        if (machine_list_found)
        {
            if (auto res = RegOpenKeyExW(POLICIES_SCOPE_MACHINE, registry_list_path.c_str(), 0, KEY_READ, &key); res == ERROR_SUCCESS)
            {

                // If the path exists in the machine, we try to read the value
                DWORD dwType = REG_SZ;
                char string_value[1024];
                DWORD string_value_length = 1024;
                auto resValue = RegQueryValueEx(key, registry_list_value_name.c_str(), NULL, &dwType, reinterpret_cast<LPBYTE>(&string_value), &string_value_length);
                RegCloseKey(key);
                
                if (resValue != ERROR_SUCCESS)
                {
                    // return value from machine list
                    return string_value;
                }
                else
                {
                    // machine list exists; but value doesn't; therefore return empty string.
                    return "";
                }
            }
            else
            {
                // some error; therefore return empty string.
                return "";
            }
        }

        // If list not exist on machine, we need to check user
        bool user_list_found = false;
        if (auto res = RegOpenKeyExW(POLICIES_SCOPE_USER, POLICIES_PATH.c_str(), 0, KEY_READ, &key); res == ERROR_SUCCESS)
        {
            // If the path was found in the user, we need to check if the value for the policy exists.
            auto resValue = RegQueryValueExW(key, registry_list_enabled_value.c_str(), nullptr, nullptr, reinterpret_cast<LPBYTE>(&value), &valueSize);
            RegCloseKey(key);


Review comment (suggestion):
```suggestion
                if (resValue == ERROR_SUCCESS)
```


Code after:
            }
        }

        switch (value)
        {
        case 0:
            return gpo_rule_configured_disabled;
        case 1:
            return gpo_rule_configured_enabled;
        default:
            return gpo_rule_configured_wrong_value;
        }
    }

    inline std::optional<std::wstring> getPolicyListValue(const std::wstring& registry_list_path, const std::wstring& registry_list_value_name)
    {
        // This function returns the value of an entry of an policy list. The user scope is only checked, if the list is not enabled for the machine to not mix the lists.

        HKEY key{};

        // Try to read from the machine list.
        bool machine_list_found = false;
        if (RegOpenKeyExW(POLICIES_SCOPE_MACHINE, registry_list_path.c_str(), 0, KEY_READ, &key) == ERROR_SUCCESS)
        {
            machine_list_found = true;
            RegCloseKey(key);

            // If the path exists in the machine registry, we try to read the value.
            auto regValueData = readRegistryStringValue(POLICIES_SCOPE_MACHINE, registry_list_path, registry_list_value_name);

            if (regValueData.has_value())
            {
                // Return the value from the machine list.
                return *regValueData;
            }
        }

        // If no list exists for machine, we try to read from the user list.
        if (!machine_list_found)
        {
            if (RegOpenKeyExW(POLICIES_SCOPE_USER, registry_list_path.c_str(), 0, KEY_READ, &key) == ERROR_SUCCESS)
            {
                RegCloseKey(key);

                // If the path exists in the user registry, we try to read the value.
                auto regValueData = readRegistryStringValue(POLICIES_SCOPE_USER, registry_list_path, registry_list_value_name);

                if (regValueData.has_value())
                {
                    // Return the value from the user list.
                    return *regValueData;