From 082eceed9af2ef6ade113568d4c24e7b3dbed23f Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Thu, 7 Sep 2023 13:44:31 +0200 Subject: [PATCH] Update checker --- app/Settings.cs | 1 + app/Updates.Designer.cs | 24 +++++++++++++----------- app/Updates.cs | 38 ++++++++++++++++++++++++++------------ app/Updates.resx | 2 +- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/app/Settings.cs b/app/Settings.cs index e54b38ab..d62ee718 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -543,6 +543,7 @@ namespace GHelper Invoke(delegate { comboMatrixRunning.SelectedIndex = mode; + if (comboMatrix.SelectedIndex == 0) comboMatrix.SelectedIndex = 3; }); } diff --git a/app/Updates.Designer.cs b/app/Updates.Designer.cs index 689c3705..af653966 100644 --- a/app/Updates.Designer.cs +++ b/app/Updates.Designer.cs @@ -54,16 +54,17 @@ namespace GHelper // tableBios.AutoSize = true; tableBios.AutoSizeMode = AutoSizeMode.GrowAndShrink; - tableBios.ColumnCount = 3; - tableBios.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); - tableBios.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); + tableBios.ColumnCount = 4; + tableBios.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 20F)); + tableBios.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 40F)); + tableBios.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 15F)); tableBios.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); tableBios.Dock = DockStyle.Top; tableBios.Location = new Point(20, 20); tableBios.Margin = new Padding(4); - tableBios.MinimumSize = new Size(1100, 0); + tableBios.MinimumSize = new Size(1300, 0); tableBios.Name = "tableBios"; - tableBios.Size = new Size(1216, 0); + tableBios.Size = new Size(1300, 0); tableBios.TabIndex = 0; // // labelBIOS @@ -105,7 +106,7 @@ namespace GHelper // labelUpdates.Anchor = AnchorStyles.Top | AnchorStyles.Right; labelUpdates.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); - labelUpdates.Location = new Point(941, 23); + labelUpdates.Location = new Point(810, 23); labelUpdates.Name = "labelUpdates"; labelUpdates.Size = new Size(245, 32); labelUpdates.TabIndex = 4; @@ -156,16 +157,17 @@ namespace GHelper // tableDrivers.AutoSize = true; tableDrivers.AutoSizeMode = AutoSizeMode.GrowAndShrink; - tableDrivers.ColumnCount = 3; - tableDrivers.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); - tableDrivers.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); + tableDrivers.ColumnCount = 4; + tableDrivers.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 20F)); + tableDrivers.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 40F)); + tableDrivers.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 15F)); tableDrivers.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); tableDrivers.Dock = DockStyle.Top; tableDrivers.Location = new Point(20, 20); tableDrivers.Margin = new Padding(4); - tableDrivers.MinimumSize = new Size(1100, 0); + tableDrivers.MinimumSize = new Size(1300, 0); tableDrivers.Name = "tableDrivers"; - tableDrivers.Size = new Size(1216, 0); + tableDrivers.Size = new Size(1300, 0); tableDrivers.TabIndex = 0; // // panelDriversTitle diff --git a/app/Updates.cs b/app/Updates.cs index d1138153..41e044fd 100644 --- a/app/Updates.cs +++ b/app/Updates.cs @@ -9,6 +9,9 @@ namespace GHelper public partial class Updates : RForm { + const int DRIVER_NOT_FOUND = 2; + const int DRIVER_NEWER = 1; + //static int rowCount = 0; static string model; static string bios; @@ -21,6 +24,7 @@ namespace GHelper public string title; public string version; public string downloadUrl; + public string date; public JsonElement hardwares; } private void LoadUpdates(bool force = false) @@ -156,7 +160,8 @@ namespace GHelper table.RowStyles.Add(new RowStyle(SizeType.AutoSize)); table.Controls.Add(new Label { Text = driver.categoryName, Anchor = AnchorStyles.Left, Dock = DockStyle.Fill, Padding = new Padding(5, 5, 5, 5) }, 0, table.RowCount); table.Controls.Add(new Label { Text = driver.title, Anchor = AnchorStyles.Left, Dock = DockStyle.Fill, Padding = new Padding(5, 5, 5, 5) }, 1, table.RowCount); - table.Controls.Add(versionLabel, 2, table.RowCount); + table.Controls.Add(new Label { Text = driver.date, Anchor = AnchorStyles.Left, Dock = DockStyle.Fill, Padding = new Padding(5, 5, 5, 5) }, 2, table.RowCount); + table.Controls.Add(versionLabel, 3, table.RowCount); table.RowCount++; }); } @@ -171,15 +176,21 @@ namespace GHelper }); } - public void VisualiseNewDriver(int position, TableLayoutPanel table) + public void VisualiseNewDriver(int position, int newer, TableLayoutPanel table) { - var label = table.GetControlFromPosition(2, position) as Label; + var label = table.GetControlFromPosition(3, position) as Label; if (label != null) { Invoke(delegate { - label.Font = new Font(label.Font, FontStyle.Underline | FontStyle.Bold); - label.ForeColor = colorTurbo; + if (newer == DRIVER_NEWER) + { + label.Font = new Font(label.Font, FontStyle.Underline | FontStyle.Bold); + label.ForeColor = colorTurbo; + } + + if (newer == DRIVER_NOT_FOUND) label.ForeColor = Color.Gray; + }); } } @@ -237,6 +248,7 @@ namespace GHelper driver.version = file.GetProperty("Version").ToString().Replace("V", ""); driver.downloadUrl = file.GetProperty("DownloadUrl").GetProperty("Global").ToString(); driver.hardwares = file.GetProperty("HardwareInfoList"); + driver.date = file.GetProperty("ReleaseDate").ToString(); drivers.Add(driver); VisualiseDriver(driver, table); @@ -257,26 +269,28 @@ namespace GHelper int count = 0; foreach (var driver in drivers) { - int newer = -2; + int newer = DRIVER_NOT_FOUND; if (type == 0 && driver.hardwares.ToString().Length > 0) for (int k = 0; k < driver.hardwares.GetArrayLength(); k++) { var deviceID = driver.hardwares[k].GetProperty("hardwareid").ToString(); - var localVersion = devices.Where(p => p.Key.Contains(deviceID)).Select(p => p.Value).FirstOrDefault(); - if (localVersion is not null) + var localVersions = devices.Where(p => p.Key.Contains(deviceID)).Select(p => p.Value); + foreach (var localVersion in localVersions) { - newer = new Version(driver.version).CompareTo(new Version(localVersion)); - break; + newer = Math.Min(newer, new Version(driver.version).CompareTo(new Version(localVersion))); + Logger.WriteLine(driver.title + " " + driver.version + " vs " + localVersion + " = " + newer); } + } if (type == 1) newer = Int32.Parse(driver.version) > Int32.Parse(bios) ? 1 : -1; - if (newer > 0) + VisualiseNewDriver(count, newer, table); + + if (newer == DRIVER_NEWER) { updatesCount++; - VisualiseNewDriver(count, table); VisualiseNewCount(updatesCount, table); } diff --git a/app/Updates.resx b/app/Updates.resx index a395bffc..af32865e 100644 --- a/app/Updates.resx +++ b/app/Updates.resx @@ -18,7 +18,7 @@ System.Resources.ResXResourceReader, System.Windows.Forms, ... System.Resources.ResXResourceWriter, System.Windows.Forms, ... this is my long stringthis is a comment - Blue + Blue [base64 mime encoded serialized .NET Framework object]