Skip to content

Commit

Permalink
Fix NVIDIA driver download when none already present
Browse files Browse the repository at this point in the history
  • Loading branch information
XenHat committed Sep 24, 2020
1 parent fbe09ca commit da37a01
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 34 deletions.
1 change: 1 addition & 0 deletions Src/Components/MotherboardInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace PicoGAUpdate
{
// TODO: Generalize into DeviceInfo
static public class MotherboardInfo
{
private static ManagementObjectSearcher baseboardSearcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_BaseBoard");
Expand Down
83 changes: 49 additions & 34 deletions Src/Components/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using System.Management;
using System.Net;
using System.Net.Http.Headers;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
Expand Down Expand Up @@ -87,29 +88,42 @@ public static string GetChipsetModel()
}

// TODO: Make generic device enumerator that includes other device types
public static string GetCurrentVersion()
// TODO: Make function launch downloader and installer for each device to work around having to stop at the first match
public static void GetCurrentVersion(out string out_vendor, out string out_version)
{
Console.Write(" Finding display adapters...");
// Add fallback value required for math, if driver is missing/not detected.
string currVer = "000.00";

out_version = "000.00";
out_vendor = "";
//ManagementObjectSearcher objSearcher = new ManagementObjectSearcher("Select * from Win32_PnPSignedDriver");
ManagementObjectSearcher DisplaySearcher = new ManagementObjectSearcher("Select * from Win32_PnPSignedDriver where deviceclass = 'DISPLAY'");
ManagementObjectCollection DisplayCollection = DisplaySearcher.Get();
//ManagementObjectSearcher DisplaySearcher = new ManagementObjectSearcher("Select * from Win32_PnPSignedDriver where deviceclass = 'DISPLAY'");
ManagementObjectSearcher AdapterSearcher = new ManagementObjectSearcher("Select * from Win32_videocontroller");
ManagementObjectCollection AdapterCollection = AdapterSearcher.Get();

#if DEBUG
foreach (ManagementObject obj in DisplayCollection)
{
string info = String.Format(" {0}, Driver version '{1}'", obj["DeviceName"], obj["DriverVersion"]);
Console.Out.WriteLine(info);
}
#endif
foreach (var o in DisplayCollection)
// TODO: Handle multiple display adapters. Needs testing.
// try to find devices without drivers.
foreach (ManagementObject obj in AdapterCollection)
{
ManagementObject obj = (ManagementObject)o;
string mfg = obj["Manufacturer"].ToString().ToUpperInvariant();
switch (mfg)
string deviceID = obj["PNPDeviceID"].ToString();
string vendor = deviceID.Split('&').First().Split('\\').ElementAt(1);
//string info = String.Format(" {3} -- {0}, Driver version '{1}'", obj["DeviceName"], obj["DriverVersion"], obj["PNPDeviceID"]);
string info = String.Format(" {0}", vendor);
Console.Out.WriteLine(info);
switch (vendor)
{
case "VEN_10DE": // NVIDIA
out_vendor = "NVIDIA";
break;
}
break;
}
ManagementObjectSearcher DisplaySearcher = new ManagementObjectSearcher("Select * from Win32_PnPSignedDriver where deviceclass = 'DISPLAY'");
ManagementObjectCollection DisplayCollection = DisplaySearcher.Get();
foreach (var obj in DisplayCollection)
{
string mfg = obj["Manufacturer"].ToString().ToUpperInvariant();
switch (mfg)
{
case "NVIDIA":
{
string device = obj["DeviceName"].ToString();
Expand All @@ -119,37 +133,37 @@ public static string GetCurrentVersion()
string[] version = obj["DriverVersion"].ToString().Split('.');
{
string nvidiaVersion = ((version.GetValue(2) + version.GetValue(3)?.ToString()).Substring(1)).Insert(3, ".");
Console.Write("NVIDIA Driver v" + nvidiaVersion);
currVer = nvidiaVersion;
Console.WriteLine(" NVIDIA Driver v" + nvidiaVersion);
out_version = nvidiaVersion;
}
}
out_vendor = "NVIDIA";
}
break;

case "AMD":
{
string device = obj["DeviceName"].ToString();
Console.WriteLine("Found AMD device '" + device + "'");
Console.WriteLine("Sorry, support for AMD graphic cards is not currently implemented.");
Console.WriteLine(" Found AMD device '" + device + "'");
Console.WriteLine(" Sorry, support for AMD graphic cards is not currently implemented.");
}
break;

case "INTEL":
{
string device = obj["DeviceName"].ToString();
Console.WriteLine("Found Intel device '" + device + "'");
Console.WriteLine("Sorry, support for Intel graphic cards is not currently implemented.");
Console.WriteLine(" Found Intel device '" + device + "'");
Console.WriteLine(" Sorry, support for Intel graphic cards is not currently implemented.");
}
break;

default:
// do nothing
break;
}
break;
}
Console.WriteLine();
return currVer;
}
}

public static void RollingOutput(string data, bool clearRestOfLine = false)
{
Expand Down Expand Up @@ -549,12 +563,13 @@ private static void Main(string[] args)
Console.WriteLine("Press any key to quit...");
Console.ReadKey();
#endif
Console.WriteLine();
}

private static bool GetLatestDriverVersion(out LinkItem latestVersion)
{
// FIXME: This shouldn't run unless we have to...
Console.Write(" Finding latest Nvidia Driver Version... ");
Console.Write(" Finding latest Driver Version... ");

int textEndCursorPos = Console.CursorLeft;
WebClient w = new WebClient();
Expand Down Expand Up @@ -619,9 +634,9 @@ private static void MainProgramLoop(string[] args)
break;
}
Console.WriteLine("* Graphic Adapter(s)");
string currentDriverVersion = GetCurrentVersion();
LinkItem latestDriver;
bool success = GetLatestDriverVersion(out latestDriver);
// TODOL Deprecate this code path and chain-load download and installation inside getCurrentVersion (and rename it...)
GetCurrentVersion(out string currentDriverVendor, out string currentDriverVersion);
bool success = GetLatestDriverVersion(out LinkItem latestDriver);
// TODO: Make installer work without network connection
if (success)
{
Expand All @@ -632,26 +647,26 @@ private static void MainProgramLoop(string[] args)
bool currentIsOutOfDate = StringToFloat(currentDriverVersion) < StringToFloat(latestDriver.Version);
if (currentIsOutOfDate)
{
Console.WriteLine("A new driver version is available! ({0} => {1})", currentDriverVersion, latestDriver.Version);
Console.WriteLine(" A new driver version is available! ({0} => {1})", currentDriverVersion, latestDriver.Version);
}
else if (OptionContainer.ForceDownload)
{
Console.WriteLine("Downloading driver as requested.");
Console.WriteLine(" Downloading driver as requested.");
}
else if (!OptionContainer.ForceInstall)
{
Console.WriteLine("Your driver is up-to-date! Well done!");
Console.WriteLine(" Your driver is up-to-date! Well done!");
}
if (!File.Exists(downloadedFile) || OptionContainer.ForceDownload || (currentIsOutOfDate && OptionContainer.ForceInstall && (!Directory.Exists(NvidiaExtractedPath))))
{
dirty = DownloadDriver(latestDriver.dlurl, latestDriver.Version, downloadedFile);
}
// TODO: Run on extracted path if present instead of relying on file version
if (currentIsOutOfDate || OptionContainer.ForceInstall) // TODO: Run on extracted path if present instead of relying on file version
StripDriver(downloadedFile, latestDriver.Version);

// TODO: Add ExtractDriver step
// }
if (OptionContainer.ForceInstall || (dirty && !OptionContainer.DownloadOnly))
if ((OptionContainer.ForceInstall || currentIsOutOfDate) && !OptionContainer.DownloadOnly)
{
dirty = InstallDriver(downloadedFile, latestDriver.Version);
}
Expand Down

0 comments on commit da37a01

Please sign in to comment.