public async static Task <string> GetBuildStringAsync(this UpdateData update) { try { CExtendedUpdateInfoXml.File deploymentCab = null; foreach (var file in update.Xml.Files.File) { if (file.FileName.EndsWith("desktopdeployment.cab", StringComparison.InvariantCultureIgnoreCase)) { deploymentCab = file; break; } } if (deploymentCab == null) { return(null); } var fileDownloadInfo = await FE3Handler.GetFileUrl(update, deploymentCab.Digest); if (fileDownloadInfo == null) { return(null); } string deploymentCabTemp = Path.GetTempFileName(); await client.DownloadFileTaskAsync(new Uri(fileDownloadInfo.DownloadUrl), deploymentCabTemp); if (fileDownloadInfo.IsEncrypted) { if (!fileDownloadInfo.Decrypt(deploymentCabTemp, deploymentCabTemp + ".decrypted")) { return(null); } File.Delete(deploymentCabTemp); File.Move(deploymentCabTemp + ".decrypted", deploymentCabTemp); } string result = null; try { using (var cabinet = new CabinetHandler(File.OpenRead(deploymentCabTemp))) { foreach (var file in cabinet.Files) { if (file.Equals("UpdateAgent.dll", StringComparison.InvariantCultureIgnoreCase)) { byte[] buffer; using (var dllstream = cabinet.OpenFile(file)) { buffer = new byte[dllstream.Length]; await dllstream.ReadAsync(buffer, 0, (int)dllstream.Length); } result = GetBuildStringFromUpdateAgent(buffer); break; } } } } catch { } var reportedBuildNumberFromService = update.Xml.ExtendedProperties.ReleaseVersion.Split('.')[2]; if (!string.IsNullOrEmpty(result) && result.Count(x => x == '.') >= 2) { var elements = result.Split('.'); elements[2] = reportedBuildNumberFromService; result = string.Join(".", elements); } File.Delete(deploymentCabTemp); return(result); } catch { return(null); } }
private static async Task <HashSet <CompDBXmlClass.CompDB> > GetCompDBs(UpdateData update) { HashSet <CompDBXmlClass.CompDB> neutralCompDB = new HashSet <CompDBXmlClass.CompDB>(); HashSet <CExtendedUpdateInfoXml.File> metadataCabs = new HashSet <CExtendedUpdateInfoXml.File>(); foreach (CExtendedUpdateInfoXml.File file in update.Xml.Files.File) { if (file.PatchingType.Equals("metadata", StringComparison.InvariantCultureIgnoreCase)) { metadataCabs.Add(file); } } if (metadataCabs.Count == 0) { return(neutralCompDB); } if (metadataCabs.Count == 1 && metadataCabs.First().FileName.Contains("metadata", StringComparison.InvariantCultureIgnoreCase)) { // This is the new metadata format where all metadata is in a single cab if (string.IsNullOrEmpty(update.CachedMetadata)) { var fileDownloadInfo = await FE3Handler.GetFileUrl(update, metadataCabs.First().Digest); if (fileDownloadInfo == null) { return(neutralCompDB); } string metadataCabTemp = Path.GetTempFileName(); // Download the file await client.DownloadFileTaskAsync(new Uri(fileDownloadInfo.DownloadUrl), metadataCabTemp); if (fileDownloadInfo.IsEncrypted) { if (!fileDownloadInfo.Decrypt(metadataCabTemp, metadataCabTemp + ".decrypted")) { return(neutralCompDB); } metadataCabTemp += ".decrypted"; } update.CachedMetadata = metadataCabTemp; } using (CabinetHandler cabinet = new CabinetHandler(File.OpenRead(update.CachedMetadata))) { foreach (string file in cabinet.Files) { using (CabinetHandler cabinet2 = new CabinetHandler(cabinet.OpenFile(file))) { string xmlfile = cabinet2.Files.First(); using (Stream xmlstream = cabinet2.OpenFile(xmlfile)) { neutralCompDB.Add(CompDBXmlClass.DeserializeCompDB(xmlstream)); } } } } } else { // This is the old format, each cab is a file in WU foreach (CExtendedUpdateInfoXml.File file in metadataCabs) { var fileDownloadInfo = await FE3Handler.GetFileUrl(update, file.Digest); if (fileDownloadInfo == null) { continue; } string metadataCabTemp = Path.GetTempFileName(); // Download the file await client.DownloadFileTaskAsync(new Uri(fileDownloadInfo.DownloadUrl), metadataCabTemp); if (fileDownloadInfo.IsEncrypted) { if (!fileDownloadInfo.Decrypt(metadataCabTemp, metadataCabTemp + ".decrypted")) { continue; } metadataCabTemp += ".decrypted"; } update.CachedMetadata = metadataCabTemp; using (CabinetHandler cabinet2 = new CabinetHandler(File.OpenRead(update.CachedMetadata))) { string xmlfile = cabinet2.Files.First(); using (Stream xmlstream = cabinet2.OpenFile(xmlfile)) { neutralCompDB.Add(CompDBXmlClass.DeserializeCompDB(xmlstream)); } } } } return(neutralCompDB); }
public static async Task <FileExchangeV3FileDownloadInformation> GetFileUrl(this UpdateData update, string Digest) { return(await FE3Handler.GetFileUrl(update, Digest)); }
public static async Task <AvailableEdition[]> GetAvailableEditions(UpdateData UpdateData, string languagecode) { List <AvailableEdition> availableEditions = new List <AvailableEdition>(); List <CExtendedUpdateInfoXml.File> metadataCabs = new List <CExtendedUpdateInfoXml.File>(); foreach (var file in UpdateData.Xml.Files.File) { if (file.PatchingType.Equals("metadata", StringComparison.InvariantCultureIgnoreCase)) { metadataCabs.Add(file); } } if (metadataCabs.Count == 0) { goto exit; } if (metadataCabs.Count == 1 && metadataCabs[0].FileName.Contains("metadata", StringComparison.InvariantCultureIgnoreCase)) { // This is the new metadata format where all metadata is in a single cab if (string.IsNullOrEmpty(UpdateData.CachedMetadata)) { var fileDownloadInfo = await FE3Handler.GetFileUrl(UpdateData, metadataCabs[0].Digest); if (fileDownloadInfo == null) { goto exit; } string metadataCabTemp = Path.GetTempFileName(); // Download the file WebClient client = new WebClient(); await client.DownloadFileTaskAsync(new Uri(fileDownloadInfo.DownloadUrl), metadataCabTemp); if (fileDownloadInfo.IsEncrypted) { if (!await fileDownloadInfo.DecryptAsync(metadataCabTemp, metadataCabTemp + ".decrypted")) { goto exit; } metadataCabTemp += ".decrypted"; } UpdateData.CachedMetadata = metadataCabTemp; } using (var cabinet = new CabinetHandler(File.OpenRead(UpdateData.CachedMetadata))) { IEnumerable <string> potentialFiles = cabinet.Files.Where(x => x.ToLower().Contains($"desktoptargetcompdb_") && x.ToLower().Contains($"_{languagecode}") && !x.ToLower().Contains("lxp") && !x.ToLower().Contains($"desktoptargetcompdb_{languagecode}")); foreach (var file in potentialFiles) { var edition = file.Split('_').Reverse().Skip(1).First(); if (availableEditions.Any(x => x.Edition == edition)) { continue; } availableEditions.Add(new AvailableEdition() { Edition = edition }); } } } else { IEnumerable <string> potentialFiles = metadataCabs.Select(x => x.FileName).Where(x => x.ToLower().Contains($"desktoptargetcompdb_") && x.ToLower().Contains($"_{languagecode}") && !x.ToLower().Contains("lxp") && !x.ToLower().Contains($"desktoptargetcompdb_{languagecode}")); // This is the old format, each cab is a file in WU foreach (var file in potentialFiles) { var edition = file.Split('_').Reverse().Skip(1).First(); if (availableEditions.Any(x => x.Edition == edition)) { continue; } availableEditions.Add(new AvailableEdition() { Edition = edition }); } } availableEditions.Sort((x, y) => x.Edition.CompareTo(y.Edition)); exit: return(availableEditions.ToArray()); }