void Formatter::WriteInternal()

in src/vswhere.lib/Formatter.cpp [194:278]


void Formatter::WriteInternal(_In_ ISetupInstance* pInstance)
{
    _ASSERTE(pInstance);

    StartObject();

    wstring specified = Args().get_Property();
    variant_t vtValue;
    bool found = false;

    for (const auto& property : m_properties)
    {
        if (specified.empty() || PropertyEqual(specified, property))
        {
            found = true;

            auto hr = property.second(pInstance, vtValue.GetAddress());
            if (SUCCEEDED(hr))
            {
                WriteProperty(property.first, vtValue);
            }
        }
    }

    if (specified.empty() || !found)
    {
        found = WriteProperties(pInstance);

        // Output catalog information.
        if (specified.empty() || !found)
        {
            ISetupInstanceCatalogPtr instanceCatalog;

            auto hr = pInstance->QueryInterface(&instanceCatalog);
            if (SUCCEEDED(hr))
            {
                ISetupPropertyStorePtr store;

                hr = instanceCatalog->GetCatalogInfo(&store);
                if (SUCCEEDED(hr) && !!store)
                {
                    wstring name(L"catalog");
                    StartObject(name);

                    found = WriteProperties(store, name);

                    EndObject();
                }
            }
        }

        // Output custom properties.
        if (specified.empty() || !found)
        {
            ISetupInstance2Ptr instance2;

            auto hr = pInstance->QueryInterface(&instance2);
            if (SUCCEEDED(hr))
            {
                ISetupPropertyStorePtr store;

                hr = instance2->GetProperties(&store);
                if (SUCCEEDED(hr) && !!store)
                {
                    wstring name(L"properties");
                    StartObject(name);

                    found = WriteProperties(store, name);

                    EndObject();
                }
            }
        }

        if (Args().get_IncludePackages() && SupportsPackages())
        {
            if (specified.empty() || s_comparer(specified, L"packages"))
            {
                WritePackages(pInstance);
            }
        }
    }

    EndObject();
}