Skip to content

Commit 8ca8830

Browse files
committed
Made DCH data GPU specific, minor cleanup
1 parent 8e3760a commit 8ca8830

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

TinyNvidiaUpdateChecker/Handlers/ClassHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class OSClass
88
public int id { get; set; }
99
}
1010

11-
public class GPU(string name, string version, string vendorId, string deviceId, bool isValidated, bool isNotebook)
11+
public class GPU(string name, string version, string vendorId, string deviceId, bool isValidated, bool isNotebook, bool isDch)
1212
{
1313
public string name { get; set; } = name;
1414
public string version { get; set; } = version;
@@ -17,6 +17,7 @@ public class GPU(string name, string version, string vendorId, string deviceId,
1717
public int gpuId { get; set; } = 0;
1818
public bool isValidated { get; set; } = isValidated;
1919
public bool isNotebook { get; set; } = isNotebook;
20+
public bool isDch { get; set; } = isDch;
2021
}
2122

2223
public class OSClassRoot : List<OSClass> { }

TinyNvidiaUpdateChecker/MainConsole.cs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ private static void Main(string[] args)
148148

149149
Console.Write("Retrieving GPU information . . . ");
150150

151-
(int gpuId, string gpuVersion, int osId, int isDchDriver, bool isNotebook) = GetDriverMetadata();
152-
var downloadInfo = GetDriverDownloadInfo(gpuId, osId, isDchDriver);
153-
var dlPrefix = ConfigurationHandler.ReadSetting("Download location");
151+
(GPU gpu, int osId) = GetDriverMetadata();
152+
JObject downloadInfo = GetDriverDownloadInfo(gpu.gpuId, osId, gpu.isDch);
153+
string dlPrefix = ConfigurationHandler.ReadSetting("Download location");
154154

155-
OfflineGPUVersion = gpuVersion;
155+
OfflineGPUVersion = gpu.version;
156156
downloadURL = downloadInfo["DownloadURL"].ToString();
157157

158158
// Some GPUs, such as 970M (Win10) URLs (including release notes URL) are HTTP and not HTTPS
@@ -212,9 +212,9 @@ private static void Main(string[] args)
212212
Console.WriteLine();
213213

214214
if (debug) {
215-
Console.WriteLine($"gpuId: {gpuId}");
215+
Console.WriteLine($"gpuId: {gpu.gpuId}");
216216
Console.WriteLine($"osId: {osId}");
217-
Console.WriteLine($"isDchDriver: {isDchDriver}");
217+
Console.WriteLine($"isDchDriver: {gpu.isDch}");
218218
Console.WriteLine($"downloadURL: {downloadURL}");
219219
Console.WriteLine($"pdfURL: {pdfURL}");
220220
Console.WriteLine($"releaseDate: {releaseDate.ToShortDateString()}");
@@ -417,11 +417,11 @@ private static void CheckArgs(string[] args)
417417
/// Finds the GPU, the version and queries up to date information
418418
/// </summary>
419419
///
420-
private static (int, string, int, int, bool) GetDriverMetadata()
420+
private static (GPU, int) GetDriverMetadata()
421421
{
422422
bool isNotebook = false;
423+
bool isDchDriver = false; // TODO rewrite for each GPU
423424
int osId = 0;
424-
int isDchDriver = 0;
425425
var nameRegex = new Regex(@"(?<=NVIDIA )(.*(?= \([A-Z]+\))|.*(?= [0-9]+GB)|.*(?= with Max-Q Design)|.*(?= COLLECTORS EDITION)|.*)");
426426
List<int> notebookChassisTypes = [1, 8, 9, 10, 11, 12, 14, 18, 21, 31, 32];
427427
var gpuList = new List<GPU> { };
@@ -473,7 +473,7 @@ private static (int, string, int, int, bool) GetDriverMetadata()
473473
// TODO do we know if this applies to every GPU?
474474
using (var regKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\nvlddmkm", false)) {
475475
if (regKey != null && regKey.GetValue("DCHUVen") != null) {
476-
isDchDriver = 1;
476+
isDchDriver = true;
477477
}
478478
}
479479

@@ -494,11 +494,11 @@ private static (int, string, int, int, bool) GetDriverMetadata()
494494
string gpuName = nameRegex.Match(rawName).Value.Trim().Replace("Super", "SUPER");
495495
string cleanVersion = rawVersion.Substring(rawVersion.Length - 5, 5).Insert(3, ".");
496496

497-
gpuList.Add(new GPU(gpuName, cleanVersion, vendorID, deviceID, true, isNotebook));
497+
gpuList.Add(new GPU(gpuName, cleanVersion, vendorID, deviceID, true, isNotebook, isDchDriver));
498498

499499
// Name does not match but the vendor is NVIDIA, use API to lookup it's name
500500
} else if (vendorID == "10de") {
501-
gpuList.Add(new GPU(rawName, rawVersion, vendorID, deviceID, false, isNotebook));
501+
gpuList.Add(new GPU(rawName, rawVersion, vendorID, deviceID, false, isNotebook, isDchDriver));
502502
}
503503
}
504504

@@ -545,7 +545,7 @@ private static (int, string, int, int, bool) GetDriverMetadata()
545545

546546
foreach (var gpu in gpuList.Where(x => x.isValidated)) {
547547
if (gpu.gpuId == configGpuId) {
548-
return (gpu.gpuId, gpu.version, osId, isDchDriver, gpu.isNotebook);
548+
return (gpu, osId);
549549
}
550550
}
551551

@@ -555,12 +555,12 @@ private static (int, string, int, int, bool) GetDriverMetadata()
555555

556556
foreach (var gpu in gpuList.Where(x => x.isValidated)) {
557557
if (gpu.gpuId == configGpuId) {
558-
return (gpu.gpuId, gpu.version, osId, isDchDriver, gpu.isNotebook);
558+
return (gpu, osId);
559559
}
560560
}
561561
} else {
562562
GPU gpu = gpuList.Where(x => x.isValidated).First();
563-
return (gpu.gpuId, gpu.version, osId, isDchDriver, gpu.isNotebook);
563+
return (gpu, osId);
564564
}
565565
}
566566

@@ -574,14 +574,13 @@ private static (int, string, int, int, bool) GetDriverMetadata()
574574
}
575575

576576
callExit(1);
577-
return (0, null, 0, 0, false);
577+
return (null, 0);
578578
}
579579

580-
private static JObject GetDriverDownloadInfo(int gpuId, int osId, int isDchDriver) {
580+
private static JObject GetDriverDownloadInfo(int gpuId, int osId, bool isDchDriver) {
581581
try {
582582
var ajaxDriverLink = "https://gfwsl.geforce.com/services_toolkit/services/com/nvidia/services/AjaxDriverService.php?func=DriverManualLookup";
583-
ajaxDriverLink += $"&pfid={gpuId}&osID={osId}&dch={isDchDriver}";
584-
583+
ajaxDriverLink += $"&pfid={gpuId}&osID={osId}&dch={(isDchDriver ? 1 : 0)}";
585584
// Driver type (upCRD)
586585
// - 0 is Game Ready Driver (GRD)
587586
// - 1 is Studio Driver (SD)
@@ -595,7 +594,7 @@ private static JObject GetDriverDownloadInfo(int gpuId, int osId, int isDchDrive
595594

596595
// If the operating system has support for DCH drivers, and DCH drivers are currently not installed, then serach for DCH drivers too.
597596
// Non-DCH drivers are discontinued. Not searching for DCH drivers will result in users having outdated graphics drivers, and we don't want that.
598-
if (Environment.Version.Build > 10240 && isDchDriver == 0) {
597+
if (Environment.Version.Build > 10240 && !isDchDriver) {
599598
ajaxDriverLink = ajaxDriverLink.Substring(0, ajaxDriverLink.Length - 1) + "1";
600599
JObject driverObjDCH = JObject.Parse(ReadURL(ajaxDriverLink));
601600

0 commit comments

Comments
 (0)