Skip to content

Commit 027e4b6

Browse files
committed
Robust version checker for Updates
1 parent 2107c5f commit 027e4b6

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

app/UpdatesController.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public void ResolveStatus(List<DriverUpdate> updates, int type, string bios, Can
144144
if (version is null && staged is not null && u.hardwares.Length > 0)
145145
version = MaxVersion(u.hardwares.Where(staged.ContainsKey).Select(h => staged[h]));
146146

147-
if (version is not null && Version.TryParse(u.version, out var sv) && Version.TryParse(version, out var iv))
147+
if (version is not null && TryParseVersion(u.version, out var sv) && TryParseVersion(version, out var iv))
148148
{
149149
u.status = sv > iv ? STATUS_NEW : STATUS_UPTODATE;
150150
u.tip = "Download: " + u.version + "\n" + "Installed: " + version;
@@ -184,20 +184,28 @@ static string[] ParseHardwares(JsonElement hardwares)
184184
return MaxVersion(pool.Select(d => d.version));
185185
}
186186

187-
// no hardware id in the API (Dolby, displayHDR)
187+
// no hardware id in the API (Dolby, displayHDR, Fortemedia) - match by title keyword
188188
var key = item.title.Split(' ')[0];
189189
if (key.Length < 3) return null;
190190
return MaxVersion(inventory.Where(d => d.isExtension && d.entry.Contains(key, StringComparison.OrdinalIgnoreCase)).Select(d => d.version));
191191
}
192192

193-
static int Major(string version) => Version.TryParse(version, out var v) ? v.Major : -1;
193+
static int Major(string version) => TryParseVersion(version, out var v) ? v.Major : -1;
194+
195+
static bool TryParseVersion(string? value, out Version version)
196+
{
197+
version = null!;
198+
if (string.IsNullOrEmpty(value)) return false;
199+
var parts = value.Split('.');
200+
return Version.TryParse(parts.Length > 4 ? string.Join(".", parts.Take(4)) : value, out version!);
201+
}
194202

195203
static string? MaxVersion(IEnumerable<string> versions)
196204
{
197205
Version? best = null;
198206
string? bestString = null;
199207
foreach (var version in versions)
200-
if (Version.TryParse(version, out var v) && (best is null || v > best))
208+
if (TryParseVersion(version, out var v) && (best is null || v > best))
201209
{
202210
best = v;
203211
bestString = version;
@@ -224,7 +232,7 @@ List<LocalDriver> BuildInventory()
224232
{
225233
var desc = PropString(GetDevNodeProperty(devInst, DEVPKEY_Device_DeviceDesc)) ?? "";
226234
foreach (var hwid in PropList(GetDevNodeProperty(devInst, DEVPKEY_Device_HardwareIds)))
227-
list.Add(new LocalDriver { matchId = hwid, version = version, isExtension = false, entry = desc });
235+
list.Add(new LocalDriver { matchId = hwid, version = version, isExtension = hwid.StartsWith("SWC\\", StringComparison.OrdinalIgnoreCase), entry = desc });
228236
}
229237

230238
foreach (var entry in PropList(GetDevNodeProperty(devInst, DEVPKEY_Device_ExtendedConfigurationIds)))

0 commit comments

Comments
 (0)