std::wstring FromConfiguration()

in src/VSIXBootstrapper.Shared/VSIXBootstrapper.h [125:176]


std::wstring FromConfiguration() noexcept
{
    try
    {
        CoInitializer<_Traits> init;

        ISetupConfiguration2Ptr query;
        IEnumSetupInstancesPtr e;
        ISetupInstance* pInstances[1];

        auto hr = query.CreateInstance(__uuidof(SetupConfiguration));
        if (FAILED(hr))
        {
            throw win32_error(hr);
        }

        hr = query->EnumAllInstances(&e);
        if (FAILED(hr))
        {
            throw win32_error(hr);
        }

        ULONG fetched = 0;
        hr = e->Next(1, pInstances, &fetched);
        while (SUCCEEDED(hr) && 1 == fetched)
        {
            auto* pInstance = pInstances[0];
            ISetupInstance2Ptr instance(pInstance);

            pInstance->Release();

            bstr_t enginePath;
            hr = instance->GetEnginePath(enginePath.GetAddress());
            if (SUCCEEDED(hr))
            {
                path path = (LPWSTR)enginePath;
                if (!path.empty() && _Traits::IOFileExists(path.append(g_wszFileName).c_str()))
                {
                    return (LPWSTR)enginePath;
                }
            }

            hr = e->Next(1, pInstances, &fetched);
        }
    }
    catch (...)
    {
        // TODO: Consider tracing errors.
    }

    return std::wstring();
}