It appears that the WUApi
exposes IUpdate
which holds multiple levels of bundleUpdates
. Before, I was simply retrieving the top level of bundleUpdates
which by doing so, made certain updates fail due to missing content required by the update; most windows updates have more than 1 level of bundles.
For example, imagine this tree like structure for 1 Update (aka IUpdate):
Update 1
---> Bundle 1
*URL 1
*URL 2
----> Bundle 1A
*URL 1
*URL 2
*URL 3
---> Bundle 2
*URL 1
----> Bundle 2A
*URL 1
*URL 2
----> Bundle 2B
*URL 1
----> Bundle 3
*URL 1
----> Bundle 3A
*URL 1
*URL 2
My Solution was to create a Recursive function to parse each update individually and keep all URIs in a dictionary of key type "bundleName
" and list of value
s that will hold all URIs for that particular bundle.
Like So:
Dictionary<string, List<string>>
The Recursive function is the following:
private static Dictionary<string, List<string>> GetAllUpdates(IUpdate iUpdate)
{
var bundleDict = new Dictionary<string, List<string>>();
foreach (IUpdate bundle in iUpdate.BundledUpdates)
{
foreach (IUpdateDownloadContent udc in bundle.DownloadContents)
{
var downloadContents = new List<string>();
if (String.IsNullOrEmpty(udc.DownloadUrl))
continue;
var url = udc.DownloadUrl;
downloadContents.Add(url);
if (!bundleDict.ContainsKey(bundle.Title))
bundleDict.Add(bundle.Title, downloadContents);
}
if (bundle.BundledUpdates.Count > 0)
{
var valuesReturned = GetAllUpdates(bundle);
foreach (var data in valuesReturned)
{
if(!bundleDict.ContainsKey(data.Key))
bundleDict.Add(data.Key, data.Value);
}
}
}
return bundleDict;
}