From 2055e6ce2313bd38b85c36fcf287f531985c9e9d Mon Sep 17 00:00:00 2001
From: realies <5107843+realies@users.noreply.github.com>
Date: Sun, 28 Jul 2024 19:08:11 +0100
Subject: [PATCH] parse and link to latest version release page
---
ChipsetAutoUpdater.xml | 4 +--
MainWindow.xaml.cs | 71 ++++++++++++++++++++++++++------------
Properties/AssemblyInfo.cs | 2 +-
3 files changed, 52 insertions(+), 25 deletions(-)
diff --git a/ChipsetAutoUpdater.xml b/ChipsetAutoUpdater.xml
index f39d1a1..13e071f 100644
--- a/ChipsetAutoUpdater.xml
+++ b/ChipsetAutoUpdater.xml
@@ -47,9 +47,9 @@
A currently installed package version or null.
-
+
- Attempt to fetch the latest release version URL for AMD Chipset Software.
+ Attempt to fetch the latest release page and executable download URL, and parse the latest version for AMD Chipset Software.
Target chipset to check.
The latest release version or null.
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index 5739a19..4114d62 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -15,6 +15,7 @@ namespace ChipsetAutoUpdater
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
+ using System.Windows.Input;
using Microsoft.Win32;
///
@@ -22,10 +23,12 @@ namespace ChipsetAutoUpdater
///
public partial class MainWindow : Window
{
- private string detectedChipset;
- private string installedVersion;
- private string latestVersionUrl;
- private string latestVersion;
+ private string detectedChipsetString;
+ private string installedVersionString;
+ private string latestVersionReleasePageUrl;
+ private string latestVersionDownloadFileUrl;
+ private string latestVersionString;
+
private CancellationTokenSource cancellationTokenSource;
private HttpClient client = new HttpClient();
@@ -45,21 +48,43 @@ async Task InitializeAsync()
this.client.DefaultRequestHeaders.Referrer = new Uri("https://www.amd.com/");
this.client.Timeout = TimeSpan.FromSeconds(1);
- this.detectedChipset = this.ChipsetModelMatcher();
- this.ChipsetModelText.Text = this.detectedChipset ?? "Not Detected";
+ this.detectedChipsetString = this.ChipsetModelMatcher();
+ this.ChipsetModelText.Text = this.detectedChipsetString ?? "Not Detected";
this.SetInstalledVersion();
- if (this.detectedChipset != null)
+ if (this.detectedChipsetString != null)
{
- this.latestVersionUrl = await this.FetchLatestVersionUrl(this.detectedChipset);
- this.latestVersion = this.latestVersionUrl?.Split('_').Last().Replace(".exe", string.Empty);
- if (this.latestVersion != null)
+ var versionData = await this.FetchLatestVersionData(this.detectedChipsetString);
+ this.latestVersionReleasePageUrl = versionData.Item1;
+ this.latestVersionDownloadFileUrl = versionData.Item2;
+ this.latestVersionString = versionData.Item3;
+
+ if (this.latestVersionString != null)
{
this.InstallDriversButton.IsEnabled = true;
}
}
- this.LatestVersionText.Text = this.latestVersion ?? "Error fetching";
+ if (this.latestVersionString != null)
+ {
+ this.LatestVersionText.Text = this.latestVersionString;
+ this.LatestVersionText.TextDecorations = TextDecorations.Underline;
+ this.LatestVersionText.Cursor = Cursors.Hand;
+ this.LatestVersionText.MouseLeftButtonDown += (s, e) =>
+ {
+ if (this.latestVersionReleasePageUrl != null)
+ {
+ Process.Start(new ProcessStartInfo(this.latestVersionReleasePageUrl) { UseShellExecute = true });
+ }
+ };
+ }
+ else
+ {
+ this.LatestVersionText.Text = "Error fetching";
+ this.LatestVersionText.TextDecorations = null;
+ this.LatestVersionText.Cursor = Cursors.Arrow;
+ this.LatestVersionText.MouseLeftButtonDown -= (s, e) => { };
+ }
}
_ = InitializeAsync();
@@ -122,11 +147,11 @@ public string GetInstalledAMDChipsetVersion()
}
///
- /// Attempt to fetch the latest release version URL for AMD Chipset Software.
+ /// Attempt to fetch the latest release page and executable download URL, and parse the latest version for AMD Chipset Software.
///
/// Target chipset to check.
/// The latest release version or null.
- public async Task FetchLatestVersionUrl(string chipset)
+ public async Task> FetchLatestVersionData(string chipset)
{
try
{
@@ -137,11 +162,13 @@ public async Task FetchLatestVersionUrl(string chipset)
if (driversUrlMatch.Success)
{
string chipsetPageContent = await this.client.GetStringAsync(driversUrlMatch.Value);
- string chipsetUrlPattern = $@"https://[^""]+\.exe";
- Match chipsetUrlMatch = Regex.Match(chipsetPageContent, chipsetUrlPattern, RegexOptions.IgnoreCase);
- if (chipsetUrlMatch.Success)
+ string chipsetDownloadFileUrlPattern = $@"https://[^""]+\.exe";
+ Match chipsetDownloadFileUrlMatch = Regex.Match(chipsetPageContent, chipsetDownloadFileUrlPattern, RegexOptions.IgnoreCase);
+ string chispetReleasePageUrlPattrern = $@"/en/resources/support-articles/release-notes/.*chipset[^""]+";
+ Match chipsetRelasePageUrlMatch = Regex.Match(chipsetPageContent, chispetReleasePageUrlPattrern, RegexOptions.IgnoreCase);
+ if (chipsetDownloadFileUrlMatch.Success && chipsetRelasePageUrlMatch.Success)
{
- return chipsetUrlMatch.Value;
+ return Tuple.Create($@"https://www.amd.com{chipsetRelasePageUrlMatch.Value}", chipsetDownloadFileUrlMatch.Value, chipsetDownloadFileUrlMatch.Value.Split('_').Last().Replace(".exe", string.Empty));
}
}
}
@@ -149,12 +176,12 @@ public async Task FetchLatestVersionUrl(string chipset)
{
}
- return null;
+ return Tuple.Create(null, null, null);
}
private async void InstallDrivers_Click(object sender, RoutedEventArgs e)
{
- string localFilePath = Path.Combine(Path.GetTempPath(), $"amd_chipset_software_{this.latestVersion}.exe");
+ string localFilePath = Path.Combine(Path.GetTempPath(), $"amd_chipset_software_{this.latestVersionString}.exe");
try
{
this.InstallDriversButton.IsEnabled = false;
@@ -163,7 +190,7 @@ private async void InstallDrivers_Click(object sender, RoutedEventArgs e)
this.CancelButton.Visibility = Visibility.Visible;
this.cancellationTokenSource = new CancellationTokenSource();
- await this.DownloadFileAsync(this.latestVersionUrl, localFilePath, this.cancellationTokenSource.Token);
+ await this.DownloadFileAsync(this.latestVersionDownloadFileUrl, localFilePath, this.cancellationTokenSource.Token);
if (this.cancellationTokenSource.Token.IsCancellationRequested)
{
@@ -277,8 +304,8 @@ private async Task MonitorProcess(Process process)
private void SetInstalledVersion()
{
- this.installedVersion = this.GetInstalledAMDChipsetVersion();
- this.InstalledVersionText.Text = this.installedVersion ?? "Not Installed";
+ this.installedVersionString = this.GetInstalledAMDChipsetVersion();
+ this.InstalledVersionText.Text = this.installedVersionString ?? "Not Installed";
}
private void CleanUpFile(string destinationFilePath)
diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs
index 59e1517..8ed1dbe 100644
--- a/Properties/AssemblyInfo.cs
+++ b/Properties/AssemblyInfo.cs
@@ -47,4 +47,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.0.0")]
-[assembly: AssemblyFileVersion("0.0.3.0")]
+[assembly: AssemblyFileVersion("0.0.4.0")]