diff --git a/PSModules/Cloud.Ready.Software.NAV/Upgrade/Get-NAVCumulativeUpdateFile.ps1 b/PSModules/Cloud.Ready.Software.NAV/Upgrade/Get-NAVCumulativeUpdateFile.ps1 index e64a35b..2ec9dda 100644 --- a/PSModules/Cloud.Ready.Software.NAV/Upgrade/Get-NAVCumulativeUpdateFile.ps1 +++ b/PSModules/Cloud.Ready.Software.NAV/Upgrade/Get-NAVCumulativeUpdateFile.ps1 @@ -210,17 +210,22 @@ function Get-NAVCumulativeUpdateFile { $Page = Invoke-WebRequest -Uri $VersionSettings.url $parsedPage = $page.ParsedHtml + $headerExists = (($parsedPage.getElementById('supArticleContent').getElementsByTagName('thead')).length -gt 0) $rows = $parsedPage.getElementById('supArticleContent').getElementsByTagName('tbody').item(0).rows + $HeaderRead = $headerExists foreach ($row in $rows) { - $html = $row.getElementsByTagName('td')[0].innerHTML - $Link = $html.Substring($html.IndexOf('"') + 1, $html.LastIndexOf('"') - ($html.IndexOf('"') + 1)) + if ($HeaderRead) { + $html = $row.getElementsByTagName('td')[0].innerHTML + $Link = $html.Substring($html.IndexOf('"') + 1, $html.LastIndexOf('"') - ($html.IndexOf('"') + 1)) - $Description = $row.getElementsByTagName('td')[1].innerText - $CU = ((([regex]::Matches($Description, $regex, [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)).Groups[1].Value).Split('.') | Select-Object -Last 1).PadLeft(2, '0') + $Description = $row.getElementsByTagName('td')[1].innerText + $CU = ((([regex]::Matches($Description, $regex, [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)).Groups[1].Value).Split('.') | Select-Object -Last 1).PadLeft(2, '0') - Write-Verbose("$CU`t$Link") + Write-Verbose("$CU`t$Link") - $CULinkMatches.Add($CU, $Link) + $CULinkMatches.Add($CU, $Link) + } + $HeaderRead = $true } $Page.Dispose() $Page = $null @@ -345,6 +350,7 @@ function Get-NAVCumulativeUpdateFile { 'BC16' { $Edition = '16.0'; break; } 'BC17' { $Edition = '17.0'; break; } 'BC18' { $Edition = '18.0'; break; } + 'BC19' { $Edition = '19.0'; break; } Default { $Edition = ([regex]::Match($Version, '[0-9]{1,2}')).Value + ".0" } } if ($padEdition) { @@ -362,7 +368,7 @@ function Get-NAVCumulativeUpdateFile { Write-Verbose 'Update downloaded' } else { - Write-Error "File $([io.path]::GetFileName($filenameJSON)) already exists. Nothing downloaded!" + Write-Warning "File $([io.path]::GetFileName($filenameJSON)) already exists. Nothing downloaded!" } } @@ -376,7 +382,7 @@ function Get-NAVCumulativeUpdateFile { $null = $result | Add-Member -MemberType NoteProperty -Name CountryCode -Value $DownloadLink.Code $null = $result | Add-Member -MemberType NoteProperty -Name CUNo -Value "$CUNo" $null = $result | Add-Member -MemberType NoteProperty -Name Build -Value $Build - $null = $result | Add-Member -MemberType NoteProperty -Name KBUrl -Value "$kbLink" + $null = $result | Add-Member -MemberType NoteProperty -Name KBUrl -Value "$updateLink" $null = $result | Add-Member -MemberType NoteProperty -Name ProductID -Value "$ProductID" $null = $result | Add-Member -MemberType NoteProperty -Name DownloadURL -Value $DownloadLink.DownloadUrl $null = $result | Add-Member -MemberType NoteProperty -Name filename -Value "$filename" diff --git a/PSModules/Cloud.Ready.Software.NAV/Upgrade/Load-NAVCumulativeUpdateHelper.ps1 b/PSModules/Cloud.Ready.Software.NAV/Upgrade/Load-NAVCumulativeUpdateHelper.ps1 index e385c84..a1ddfdf 100644 --- a/PSModules/Cloud.Ready.Software.NAV/Upgrade/Load-NAVCumulativeUpdateHelper.ps1 +++ b/PSModules/Cloud.Ready.Software.NAV/Upgrade/Load-NAVCumulativeUpdateHelper.ps1 @@ -51,6 +51,7 @@ namespace MicrosoftDownload public static class MicrosoftDownloadParser { private const String urlTemplate = "https://www.microsoft.com/{0}/download/confirmation.aspx?id={1}"; + private const String downloadTemplate = "https://www.microsoft.com/{0}/download/details.aspx?id={1}"; private const String cdataStartTag = "*/"; private const String downloadStartTag = "downloadData={"; @@ -61,13 +62,28 @@ namespace MicrosoftDownload { //Console.WriteLine(productID); - var XMLDoc = XDocument.Load("https://www.microsoft.com/en-us/download/details.aspx?id=" + productID); + XDocument XMLDoc = new XDocument(); + string[] locales = { "en-us", "en-gb" }; + string locale = ""; + foreach (string localeTest in locales) + { + try + { + locale = localeTest; + XMLDoc = XDocument.Load(string.Format(downloadTemplate, locale, productID)); + } + catch + { + locale = ""; + continue; + } + } IEnumerable users = (from el in XMLDoc.Descendants() where (string)el.Attribute("name") == "newlocale" select el); if ((users == null) || (users.Count() == 0)) - { - foreach (var detail in GetDownloadDetail(productID, "en-US")) + { + foreach (var detail in GetDownloadDetail(productID, locale)) yield return detail; } else @@ -76,8 +92,8 @@ namespace MicrosoftDownload foreach (var detail in GetDownloadDetail(productID, item.Attribute("value").Value)) yield return detail; } - - + + } public static IEnumerable GetDownloadDetail(Int32 productID, String language) @@ -85,7 +101,7 @@ namespace MicrosoftDownload //Console.WriteLine(productID + " - " + language); using (WebClient client = new WebClient()) - { + { var pageData = client.DownloadString(String.Format(urlTemplate, language, productID)); var CData = FetchSubString(pageData, cdataStartTag, cdataEndTag); var downloadData = FetchSubString(CData, downloadStartTag, downloadEndTag); @@ -109,10 +125,10 @@ namespace MicrosoftDownload langCode = url.Substring(url.Length - 6, 2); } else - { + { langCode = url.Substring(url.Length - 10, 2); } - + yield return new NAVDownload(productID, language, langCode, url); } } @@ -123,7 +139,7 @@ namespace MicrosoftDownload { var startPos = source.IndexOf(startTag) + startTag.Length; return source.Substring(startPos, source.IndexOf(endTag, startPos) - startPos); - } + } } public class NAVDownload @@ -145,7 +161,6 @@ namespace MicrosoftDownload } } } - "@ } diff --git a/PSModules/Cloud.Ready.Software.NAV/Upgrade/Versions.json b/PSModules/Cloud.Ready.Software.NAV/Upgrade/Versions.json index 3018007..da5a890 100644 --- a/PSModules/Cloud.Ready.Software.NAV/Upgrade/Versions.json +++ b/PSModules/Cloud.Ready.Software.NAV/Upgrade/Versions.json @@ -1,6 +1,6 @@ { "DefaultDownloadURL" : "https://support.microsoft.com", - "BuildRegex" : "\\(Build ([\\d\\.]+)\\)|Platform Build (\\d+\\.?\\d+\\.?\\d+)\\.?\\d?\\)", + "BuildRegex" : "\\(Build ([\\d\\.]+)\\)|Platform Build (\\d+\\.?\\d+\\.?\\d+)\\.?\\d*\\)", "CountryCodeRegex" : "\\.([A-Z]{2}|W1).DVD|(?:\\.)?([A-Z]{2}|W1)\\.ZIP", "CUNoRegex" : "(?:Cumulative )?Update (\\d\\d?\\.?\\d{0,2})", "downloadLinkRegex" : "(https?\\:\\\/\\\/www\\.microsoft\\.com\\\/(?:[a-z]{2}-[a-z]{2}\\\/)?download\\\/details.aspx\\?(?:familyid=([\\da-zA-Z]{8}-(?:[\\da-zA-Z]{4}-){3}[\\da-zA-Z]{12})|id(?:%3d|=)?(\\d+)))", @@ -83,10 +83,17 @@ "downloadLinkRegex" : "" }, { - "version": "BC17", - "url": "https://support.microsoft.com/en-gb/help/4583507", + "version": "BC18", + "url": "https://support.microsoft.com/en-us/help/5003500", + "fileNamePrefix" : "BC", + "CUNoRegex" : "", + "downloadLinkRegex" : "" + }, + { + "version": "BC19", + "url": "https://support.microsoft.com/en-us/help/5007780", "fileNamePrefix" : "BC", - "CULinkRegex" : "", + "CUNoRegex" : "", "downloadLinkRegex" : "" } ],