Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V18 changes required #71

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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!"

}
}
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<![CDATA[*/var " + "baseProductId";
private const String cdataEndTag = "/*]]>*/";
private const String downloadStartTag = "downloadData={";
Expand All @@ -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<XElement> 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
Expand All @@ -76,16 +92,16 @@ namespace MicrosoftDownload
foreach (var detail in GetDownloadDetail(productID, item.Attribute("value").Value))
yield return detail;
}


}

public static IEnumerable<NAVDownload> GetDownloadDetail(Int32 productID, String language)
{
//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);
Expand All @@ -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);
}
}
Expand All @@ -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
Expand All @@ -145,7 +161,6 @@ namespace MicrosoftDownload
}
}
}


"@
}
Expand Down
15 changes: 11 additions & 4 deletions PSModules/Cloud.Ready.Software.NAV/Upgrade/Versions.json
Original file line number Diff line number Diff line change
@@ -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+)))",
Expand Down Expand Up @@ -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" : ""
}
],
Expand Down