in src/vswhere/Program.cpp [14:131]
int wmain(_In_ int argc, _In_ LPCWSTR argv[])
{
CommandArgs args;
Console console(args);
Module queryModule;
console.Initialize();
try
{
CoInitializer init;
// Create the query object early to print version in logo.
ISetupConfigurationPtr query;
auto hr = query.CreateInstance(__uuidof(SetupConfiguration));
if (FAILED(hr))
{
if (REGDB_E_CLASSNOTREG != hr)
{
throw win32_error(hr);
}
}
// Try to get information about the query module for later.
queryModule.FromIUnknown(static_cast<IUnknown*>(query));
args.Parse(argc, argv);
if (args.get_Help())
{
WriteLogo(args, console, queryModule);
args.Usage(console);
return ERROR_SUCCESS;
}
// Attempt to get the ISetupHelper.
ISetupHelperPtr helper;
if (query)
{
query->QueryInterface(&helper);
}
// Fall back to a copy of the current implementation.
else
{
helper.Attach(new VersionRange);
}
vector<ISetupInstancePtr> instances;
if (args.get_Path().empty())
{
IEnumSetupInstancesPtr e;
GetEnumerator(args, query, e);
InstanceSelector selector(args, helper);
instances = std::move(selector.Select(e));
}
else
{
auto path = GetFullPath(args.get_Path());
ISetupInstancePtr instance;
hr = query->GetInstanceForPath(path.c_str(), &instance);
if (SUCCEEDED(hr))
{
instances.push_back(instance);
}
}
// Create the formatter and optionally show the logo.
auto formatter = Formatter::Create(args.get_Format(), args, console);
if (formatter->ShowLogo())
{
WriteLogo(args, console, queryModule);
}
if (args.get_Find().length())
{
formatter->WriteFiles(instances);
}
else
{
formatter->Write(instances);
}
return ERROR_SUCCESS;
}
catch (const system_error& ex)
{
const auto code = ex.code().value();
if (ERROR_INVALID_PARAMETER == code)
{
WriteLogo(args, console, queryModule);
}
console.Write(L"%ls 0x%x: ", ResourceManager::GetString(IDS_ERROR).c_str(), code);
const auto* err = dynamic_cast<const win32_error*>(&ex);
if (err)
{
console.WriteLine(L"%ls", err->wwhat());
}
else
{
console.WriteLine(L"%hs", ex.what());
}
return ex.code().value();
}
catch (const exception& ex)
{
console.WriteLine(L"%ls: %hs", ResourceManager::GetString(IDS_ERROR).c_str(), ex.what());
}
catch (...)
{
console.WriteLine(L"%ls: %ls", ResourceManager::GetString(IDS_ERROR).c_str(), ResourceManager::GetString(IDS_E_UNKNOWN).c_str());
}
return E_FAIL;
}