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

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

        // read value from machine list
        if (user_list_found)
        {
            if (auto res = RegOpenKeyExW(POLICIES_SCOPE_USER, registry_list_path.c_str(), 0, KEY_READ, &key); res == ERROR_SUCCESS)
            {
                // If the path exists in the user, 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 user list
                    return string_value;
                }
                else
                {
                    // user list exists; but value doesn't; therefore return empty string.
                    return "";
                }
            }
            else
            {
                // some error; therefore return empty string.
                return "";
            }
        }

        // No list exists
        return "";
    }

    inline gpo_rule_configured_t getConfiguredAlwaysOnTopEnabledValue() {
        return getConfiguredValue(POLICY_CONFIGURE_ENABLED_ALWAYS_ON_TOP);
    }


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


Code after:
        // No list exists for machine and user, or no value was found in the list, or an error ocurred while reading the value.
        return std::nullopt;
    }

    inline gpo_rule_configured_t getUtilityEnabledValue(const std::wstring& utility_name)
    {
        auto individual_value = getConfiguredValue(utility_name);

        if (individual_value == gpo_rule_configured_disabled || individual_value == gpo_rule_configured_enabled)
        {
            return individual_value;
        }
        else
        {
            return getConfiguredValue(POLICY_CONFIGURE_ENABLED_GLOBAL_ALL_UTILITIES);
        }
    }

    inline gpo_rule_configured_t getConfiguredAlwaysOnTopEnabledValue()
    {
        return getUtilityEnabledValue(POLICY_CONFIGURE_ENABLED_ALWAYS_ON_TOP);
    }

    inline gpo_rule_configured_t getConfiguredAwakeEnabledValue()
    {
        return getUtilityEnabledValue(POLICY_CONFIGURE_ENABLED_AWAKE);
    }

    inline gpo_rule_configured_t getConfiguredColorPickerEnabledValue()
    {
        return getUtilityEnabledValue(POLICY_CONFIGURE_ENABLED_COLOR_PICKER);
    }

    inline gpo_rule_configured_t getConfiguredCropAndLockEnabledValue()
    {
        return getUtilityEnabledValue(POLICY_CONFIGURE_ENABLED_CROP_AND_LOCK);
    }

    inline gpo_rule_configured_t getConfiguredFancyZonesEnabledValue()
    {
        return getUtilityEnabledValue(POLICY_CONFIGURE_ENABLED_FANCYZONES);
    }

    inline gpo_rule_configured_t getConfiguredFileLocksmithEnabledValue()
    {
        return getUtilityEnabledValue(POLICY_CONFIGURE_ENABLED_FILE_LOCKSMITH);
    }

    inline gpo_rule_configured_t getConfiguredSvgPreviewEnabledValue()
    {
        return getUtilityEnabledValue(POLICY_CONFIGURE_ENABLED_SVG_PREVIEW);