working to implement full logging

This commit is contained in:
Jakob 2023-04-03 20:37:11 +02:00
parent adb8a5508b
commit 671824f3cd
4 changed files with 191 additions and 7 deletions

View file

@ -1,12 +1,16 @@
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Security.Policy;
namespace EnvyUpdate namespace EnvyUpdate
{ {
class Debug class Debug
{ {
public static bool isDebug = false; public static bool isFake = false;
public static bool isVerbose = false;
public static string debugFile = Path.Combine(GlobalVars.exedirectory, "envyupdate.log");
public static int LoadFakeIDs(string idType) public static int LoadFakeIDs(string idType)
{ {
@ -38,5 +42,12 @@ namespace EnvyUpdate
{ {
return "Nvidia GeForce RTX 4080 (debug)"; return "Nvidia GeForce RTX 4080 (debug)";
} }
[ConditionalAttribute("DEBUG")]
public static void LogToFile(string content)
{
if (isVerbose)
System.IO.File.AppendAllText(Debug.debugFile, content);
}
} }
} }

View file

@ -25,6 +25,8 @@ namespace EnvyUpdate
private void ButtonWeb_Click(object sender, RoutedEventArgs e) private void ButtonWeb_Click(object sender, RoutedEventArgs e)
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Launching website.");
System.Diagnostics.Process.Start("https://github.com/fyr77/EnvyUpdate/"); System.Diagnostics.Process.Start("https://github.com/fyr77/EnvyUpdate/");
} }
} }

View file

@ -37,47 +37,82 @@ namespace EnvyUpdate
// This is necessary, since .NET throws an exception if you check for a non-existant arg. // This is necessary, since .NET throws an exception if you check for a non-existant arg.
} }
if (arguments.Contains("/verbose"))
{
Debug.isVerbose = true;
if (!File.Exists(Debug.debugFile))
File.CreateText(Debug.debugFile);
File.AppendAllText(Debug.debugFile, "INFO Starting EnvyUpdate, version " + System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion);
}
// Check if EnvyUpdate is already running // Check if EnvyUpdate is already running
if (Util.IsInstanceOpen("EnvyUpdate")) if (Util.IsInstanceOpen("EnvyUpdate"))
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "FATAL Found another instance, terminating.");
MessageBox.Show(Properties.Resources.instance_already_running); MessageBox.Show(Properties.Resources.instance_already_running);
Environment.Exit(1); Environment.Exit(1);
} }
// Delete installed legacy versions // Delete installed legacy versions
if (Directory.Exists(GlobalVars.appdata)) if (Directory.Exists(GlobalVars.appdata))
{
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Found old appdata installation, uninstalling.");
UninstallAll(); UninstallAll();
}
GlobalVars.isMobile = Util.IsMobile(); GlobalVars.isMobile = Util.IsMobile();
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Mobile: " + GlobalVars.isMobile);
localDriv = Util.GetLocDriv(); localDriv = Util.GetLocDriv();
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Local driver version: " + localDriv);
if (localDriv != null) if (localDriv != null)
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Local driver version already known, updating info without reloading.");
UpdateLocalVer(false); UpdateLocalVer(false);
} }
else else
{ {
if (arguments.Contains("/debug")) if (arguments.Contains("/fake"))
{ {
Debug.isDebug = true; Debug.isFake = true;
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "WARN Faking GPU with debug info.");
} }
else else
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "FATAL No supported GPU found, terminating.");
MessageBox.Show(Properties.Resources.no_compatible_gpu); MessageBox.Show(Properties.Resources.no_compatible_gpu);
Environment.Exit(255); Environment.Exit(255);
} }
} }
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Detecting driver type.");
if (Util.IsDCH()) if (Util.IsDCH())
textblockLocalType.Text = "DCH"; textblockLocalType.Text = "DCH";
else if (Debug.isDebug) else if (Debug.isFake)
textblockLocalType.Text = "DCH (Debug)"; textblockLocalType.Text = "DCH (Debug)";
else else
textblockLocalType.Text = "Standard"; textblockLocalType.Text = "Standard";
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Done detecting driver type.");
// Check for startup shortcut // Check for startup shortcut
if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "EnvyUpdate.lnk"))) if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "EnvyUpdate.lnk")))
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Autostart is enabled.");
chkAutostart.IsChecked = true; chkAutostart.IsChecked = true;
chkAutostart_Click(null, null); //Automatically recreate shortcut to account for moved EXE. chkAutostart_Click(null, null); //Automatically recreate shortcut to account for moved EXE.
} }
@ -85,6 +120,8 @@ namespace EnvyUpdate
//Check if launched as miminized with arg //Check if launched as miminized with arg
if (arguments.Contains("/minimize")) if (arguments.Contains("/minimize"))
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Launching minimized.");
WindowState = WindowState.Minimized; WindowState = WindowState.Minimized;
Hide(); Hide();
} }
@ -94,6 +131,8 @@ namespace EnvyUpdate
// Check for new updates every 5 hours. // Check for new updates every 5 hours.
Dt.Interval = new TimeSpan(5, 0, 0); Dt.Interval = new TimeSpan(5, 0, 0);
Dt.Start(); Dt.Start();
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Started check timer.");
string watchDirPath = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramW6432%"), "NVIDIA Corporation\\Installer2\\InstallerCore"); string watchDirPath = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramW6432%"), "NVIDIA Corporation\\Installer2\\InstallerCore");
if (Directory.Exists(watchDirPath)) if (Directory.Exists(watchDirPath))
@ -112,6 +151,8 @@ namespace EnvyUpdate
driverFileChangedWatcher.Filter = "*.dll"; driverFileChangedWatcher.Filter = "*.dll";
driverFileChangedWatcher.IncludeSubdirectories = false; driverFileChangedWatcher.IncludeSubdirectories = false;
driverFileChangedWatcher.EnableRaisingEvents = true; driverFileChangedWatcher.EnableRaisingEvents = true;
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Started update file system watcher.");
} }
Load(); Load();
@ -124,6 +165,8 @@ namespace EnvyUpdate
private void buttonHelp_Click(object sender, RoutedEventArgs e) private void buttonHelp_Click(object sender, RoutedEventArgs e)
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Showing info window.");
InfoWindow infoWin = new InfoWindow(); InfoWindow infoWin = new InfoWindow();
infoWin.ShowDialog(); infoWin.ShowDialog();
} }
@ -131,15 +174,27 @@ namespace EnvyUpdate
private void Load() private void Load()
{ {
if (Util.GetDTID() == 18) if (Util.GetDTID() == 18)
{
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Found studio driver.");
radioSD.IsChecked = true; radioSD.IsChecked = true;
}
else else
{
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Found standard driver.");
radioGRD.IsChecked = true; radioGRD.IsChecked = true;
}
if (File.Exists(GlobalVars.exedirectory + "skip.envy")) if (File.Exists(GlobalVars.exedirectory + "skip.envy"))
{
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Found version skip config.");
skippedVer = File.ReadLines(GlobalVars.exedirectory + "skip.envy").First(); skippedVer = File.ReadLines(GlobalVars.exedirectory + "skip.envy").First();
}
// This little bool check is necessary for debug mode on systems without an Nvidia GPU. // This little bool check is necessary for debug mode on systems without an Nvidia GPU.
if (Debug.isDebug) if (Debug.isFake)
{ {
localDriv = Debug.LocalDriv(); localDriv = Debug.LocalDriv();
textblockGPU.Text = localDriv; textblockGPU.Text = localDriv;
@ -148,10 +203,14 @@ namespace EnvyUpdate
try try
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Trying to get GPU update URL.");
gpuURL = Util.GetGpuUrl(); gpuURL = Util.GetGpuUrl();
} }
catch (ArgumentException) catch (ArgumentException)
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "WARN Could not get GPU update URL, trying again with standard driver.");
try try
{ {
// disable SD and try with GRD // disable SD and try with GRD
@ -167,6 +226,8 @@ namespace EnvyUpdate
catch (ArgumentException e) catch (ArgumentException e)
{ {
// Now we have a problem. // Now we have a problem.
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "FATAL Invalid API response from Nvidia. Attempted API call: " + e.Message);
MessageBox.Show("ERROR: Invalid API response from Nvidia. Please file an issue on GitHub.\nAttempted API call:\n" + e.Message); MessageBox.Show("ERROR: Invalid API response from Nvidia. Please file an issue on GitHub.\nAttempted API call:\n" + e.Message);
Environment.Exit(10); Environment.Exit(10);
} }
@ -174,18 +235,24 @@ namespace EnvyUpdate
using (var c = new WebClient()) using (var c = new WebClient())
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Trying to get newest driver version.");
string pContent = c.DownloadString(gpuURL); string pContent = c.DownloadString(gpuURL);
var pattern = @"Windows\/\d{3}\.\d{2}"; var pattern = @"Windows\/\d{3}\.\d{2}";
Regex rgx = new Regex(pattern); Regex rgx = new Regex(pattern);
var matches = rgx.Matches(pContent); var matches = rgx.Matches(pContent);
onlineDriv = Regex.Replace(Convert.ToString(matches[0]), "Windows/", ""); onlineDriv = Regex.Replace(Convert.ToString(matches[0]), "Windows/", "");
textblockOnline.Text = onlineDriv; textblockOnline.Text = onlineDriv;
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Got online driver version: " + onlineDriv);
} }
try try
{ {
if (float.Parse(localDriv) < float.Parse(onlineDriv)) if (float.Parse(localDriv) < float.Parse(onlineDriv))
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Local version is older than online. Setting UI...");
textblockOnline.Foreground = Brushes.Red; textblockOnline.Foreground = Brushes.Red;
buttonDL.IsEnabled = true; buttonDL.IsEnabled = true;
if (skippedVer == null) if (skippedVer == null)
@ -195,22 +262,36 @@ namespace EnvyUpdate
} }
else else
buttonSkip.Content = Properties.Resources.ui_skipped; buttonSkip.Content = Properties.Resources.ui_skipped;
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO UI set.");
if (skippedVer != onlineDriv) if (skippedVer != onlineDriv)
{
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Showing update popup notification.");
Notify.ShowDrivUpdatePopup(); Notify.ShowDrivUpdatePopup();
}
} }
else else
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Local version is up to date.");
buttonSkip.IsEnabled = false; buttonSkip.IsEnabled = false;
textblockOnline.Foreground = Brushes.Green; textblockOnline.Foreground = Brushes.Green;
} }
} }
catch (FormatException) catch (FormatException)
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Caught FormatException, assuming locale workaround is necessary.");
//Thank you locales. Some languages need , instead of . for proper parsing //Thank you locales. Some languages need , instead of . for proper parsing
string cLocalDriv = localDriv.Replace('.', ','); string cLocalDriv = localDriv.Replace('.', ',');
string cOnlineDriv = onlineDriv.Replace('.', ','); string cOnlineDriv = onlineDriv.Replace('.', ',');
if (float.Parse(cLocalDriv) < float.Parse(cOnlineDriv)) if (float.Parse(cLocalDriv) < float.Parse(cOnlineDriv))
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Local version is older than online. Setting UI...");
textblockOnline.Foreground = Brushes.Red; textblockOnline.Foreground = Brushes.Red;
buttonDL.IsEnabled = true; buttonDL.IsEnabled = true;
if (skippedVer == null) if (skippedVer == null)
@ -218,10 +299,16 @@ namespace EnvyUpdate
else else
buttonSkip.Content = Properties.Resources.ui_skipped; buttonSkip.Content = Properties.Resources.ui_skipped;
if (skippedVer != onlineDriv) if (skippedVer != onlineDriv)
{
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Showing update popup notification.");
Notify.ShowDrivUpdatePopup(); Notify.ShowDrivUpdatePopup();
}
} }
else else
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Local version is up to date.");
buttonSkip.IsEnabled = false; buttonSkip.IsEnabled = false;
textblockOnline.Foreground = Brushes.Green; textblockOnline.Foreground = Brushes.Green;
} }
@ -230,6 +317,8 @@ namespace EnvyUpdate
//Check for different version than skipped version //Check for different version than skipped version
if (skippedVer != onlineDriv) if (skippedVer != onlineDriv)
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Skipped version is surpassed, deleting setting.");
skippedVer = null; skippedVer = null;
if (File.Exists(GlobalVars.exedirectory + "skip.envy")) if (File.Exists(GlobalVars.exedirectory + "skip.envy"))
File.Delete(GlobalVars.exedirectory + "skip.envy"); File.Delete(GlobalVars.exedirectory + "skip.envy");
@ -240,11 +329,15 @@ namespace EnvyUpdate
private void buttonDL_Click(object sender, RoutedEventArgs e) private void buttonDL_Click(object sender, RoutedEventArgs e)
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Opening download page.");
Process.Start(gpuURL); Process.Start(gpuURL);
} }
private void TaskbarIcon_TrayLeftMouseDown(object sender, RoutedEventArgs e) private void TaskbarIcon_TrayLeftMouseDown(object sender, RoutedEventArgs e)
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Tray was clicked, opening main window.");
Util.ShowMain(); Util.ShowMain();
} }
@ -252,6 +345,8 @@ namespace EnvyUpdate
{ {
if (WindowState == WindowState.Minimized) if (WindowState == WindowState.Minimized)
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Window was minimized, closing to tray.");
Hide(); Hide();
} }
} }
@ -260,20 +355,28 @@ namespace EnvyUpdate
{ {
if (File.Exists(GlobalVars.startup + "\\EnvyUpdate.lnk")) if (File.Exists(GlobalVars.startup + "\\EnvyUpdate.lnk"))
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Deleted startup entry.");
File.Delete(GlobalVars.startup + "\\EnvyUpdate.lnk"); File.Delete(GlobalVars.startup + "\\EnvyUpdate.lnk");
} }
if (File.Exists(GlobalVars.startmenu + "\\EnvyUpdate.lnk")) if (File.Exists(GlobalVars.startmenu + "\\EnvyUpdate.lnk"))
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Deleted start menu entry.");
File.Delete(GlobalVars.startmenu + "\\EnvyUpdate.lnk"); File.Delete(GlobalVars.startmenu + "\\EnvyUpdate.lnk");
} }
if ((GlobalVars.exedirectory == GlobalVars.appdata) && File.Exists(GlobalVars.appdata + "EnvyUpdate.exe")) if ((GlobalVars.exedirectory == GlobalVars.appdata) && File.Exists(GlobalVars.appdata + "EnvyUpdate.exe"))
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Deleting EnvyUpdate appdata and self.");
MessageBox.Show(Properties.Resources.uninstall_legacy_message); MessageBox.Show(Properties.Resources.uninstall_legacy_message);
Util.SelfDelete(); Util.SelfDelete();
} }
else if (Directory.Exists(GlobalVars.appdata)) else if (Directory.Exists(GlobalVars.appdata))
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Deleting EnvyUpdate appdata folder");
Directory.Delete(GlobalVars.appdata, true); Directory.Delete(GlobalVars.appdata, true);
} }
} }
@ -282,17 +385,25 @@ namespace EnvyUpdate
{ {
if (MessageBox.Show(Properties.Resources.exit_confirm, "", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) if (MessageBox.Show(Properties.Resources.exit_confirm, "", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Uninstalling notifications and shutting down.");
ToastNotificationManagerCompat.Uninstall(); // Uninstall notifications to prevent issues with the app being portable. ToastNotificationManagerCompat.Uninstall(); // Uninstall notifications to prevent issues with the app being portable.
Application.Current.Shutdown(); Application.Current.Shutdown();
} }
else else
{
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Application shutdown was cancelled.");
e.Cancel = true; e.Cancel = true;
}
} }
private void radioGRD_Checked(object sender, RoutedEventArgs e) private void radioGRD_Checked(object sender, RoutedEventArgs e)
{ {
if (File.Exists(GlobalVars.exedirectory + "sd.envy")) if (File.Exists(GlobalVars.exedirectory + "sd.envy"))
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Switching to game ready driver.");
File.Delete(GlobalVars.exedirectory + "sd.envy"); File.Delete(GlobalVars.exedirectory + "sd.envy");
Load(); Load();
} }
@ -302,6 +413,8 @@ namespace EnvyUpdate
{ {
if (!File.Exists(GlobalVars.exedirectory + "sd.envy")) if (!File.Exists(GlobalVars.exedirectory + "sd.envy"))
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Switching to studio driver.");
File.Create(GlobalVars.exedirectory + "sd.envy").Close(); File.Create(GlobalVars.exedirectory + "sd.envy").Close();
Load(); Load();
} }
@ -311,16 +424,22 @@ namespace EnvyUpdate
{ {
if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "EnvyUpdate.lnk"))) if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "EnvyUpdate.lnk")))
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Removing autostart entry.");
File.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "EnvyUpdate.lnk")); File.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "EnvyUpdate.lnk"));
} }
if (chkAutostart.IsChecked == true) if (chkAutostart.IsChecked == true)
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Creating autostart entry.");
Util.CreateShortcut("EnvyUpdate", Environment.GetFolderPath(Environment.SpecialFolder.Startup), GlobalVars.exeloc, "NVidia Update Checker", "/minimize"); Util.CreateShortcut("EnvyUpdate", Environment.GetFolderPath(Environment.SpecialFolder.Startup), GlobalVars.exeloc, "NVidia Update Checker", "/minimize");
} }
} }
private void buttonSkip_Click(object sender, RoutedEventArgs e) private void buttonSkip_Click(object sender, RoutedEventArgs e)
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Skipping version.");
skippedVer = onlineDriv; skippedVer = onlineDriv;
File.WriteAllText(GlobalVars.exedirectory + "skip.envy", onlineDriv); File.WriteAllText(GlobalVars.exedirectory + "skip.envy", onlineDriv);
buttonSkip.IsEnabled = false; buttonSkip.IsEnabled = false;
@ -330,8 +449,14 @@ namespace EnvyUpdate
private void UpdateLocalVer(bool reloadLocalDriv = true) private void UpdateLocalVer(bool reloadLocalDriv = true)
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Updating local driver version in UI.");
if (reloadLocalDriv) if (reloadLocalDriv)
{
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Reloading local driver version.");
localDriv = Util.GetLocDriv(); localDriv = Util.GetLocDriv();
}
textblockGPU.Text = localDriv; textblockGPU.Text = localDriv;
if (GlobalVars.isMobile) if (GlobalVars.isMobile)
textblockGPUName.Text = Util.GetGPUName(false) + " (mobile)"; textblockGPUName.Text = Util.GetGPUName(false) + " (mobile)";
@ -341,6 +466,8 @@ namespace EnvyUpdate
void DriverFileChanged(object sender, FileSystemEventArgs e) void DriverFileChanged(object sender, FileSystemEventArgs e)
{ {
if (Debug.isVerbose)
File.AppendAllText(Debug.debugFile, "INFO Watched driver file changed! Reloading data.");
System.Threading.Thread.Sleep(10000); System.Threading.Thread.Sleep(10000);
Application.Current.Dispatcher.Invoke(delegate Application.Current.Dispatcher.Invoke(delegate
{ {

View file

@ -29,6 +29,9 @@ namespace EnvyUpdate
// query local driver version // query local driver version
try try
{ {
if (Debug.isVerbose)
System.IO.File.AppendAllText(Debug.debugFile, "INFO Looking for driver version in ManagementObjects");
foreach (ManagementObject obj in new ManagementObjectSearcher("SELECT * FROM Win32_VideoController").Get()) foreach (ManagementObject obj in new ManagementObjectSearcher("SELECT * FROM Win32_VideoController").Get())
{ {
if (obj["Description"].ToString().ToLower().Contains("nvidia")) if (obj["Description"].ToString().ToLower().Contains("nvidia"))
@ -37,12 +40,18 @@ namespace EnvyUpdate
OfflineGPUVersion = OfflineGPUVersion.Substring(Math.Max(0, OfflineGPUVersion.Length - 5)); OfflineGPUVersion = OfflineGPUVersion.Substring(Math.Max(0, OfflineGPUVersion.Length - 5));
OfflineGPUVersion = OfflineGPUVersion.Substring(0, 3) + "." + OfflineGPUVersion.Substring(3); // add dot OfflineGPUVersion = OfflineGPUVersion.Substring(0, 3) + "." + OfflineGPUVersion.Substring(3); // add dot
foundGpu = true; foundGpu = true;
if (Debug.isVerbose)
System.IO.File.AppendAllText(Debug.debugFile, "INFO Found driver in ManagementObjects.");
break; break;
} }
} }
if (!foundGpu) if (!foundGpu)
{
if (Debug.isVerbose)
System.IO.File.AppendAllText(Debug.debugFile, "WARN Did NOT find driver in ManagementObjects.");
throw new InvalidDataException(); throw new InvalidDataException();
}
return OfflineGPUVersion; return OfflineGPUVersion;
} }
@ -70,6 +79,8 @@ namespace EnvyUpdate
shortcut.Arguments = arguments; shortcut.Arguments = arguments;
shortcut.Description = description; shortcut.Description = description;
shortcut.TargetPath = targetFileLocation; shortcut.TargetPath = targetFileLocation;
if (Debug.isVerbose)
System.IO.File.AppendAllText(Debug.debugFile, "INFO Saving shortcut link.");
shortcut.Save(); shortcut.Save();
} }
/// <summary> /// <summary>
@ -126,10 +137,11 @@ namespace EnvyUpdate
} }
public static int GetIDs(string IDtype) public static int GetIDs(string IDtype)
{ {
// TODO: check for 2 occurences of GPU - if yes ask if mobile!!!
string xmlcontent = null; string xmlcontent = null;
int id = -1; int id = -1;
if (Debug.isVerbose)
System.IO.File.AppendAllText(Debug.debugFile, "INFO Getting Nvidia GPU list...");
using (var wc = new WebClient()) using (var wc = new WebClient())
{ {
switch (IDtype) switch (IDtype)
@ -142,6 +154,16 @@ namespace EnvyUpdate
break; break;
} }
} }
if (Debug.isVerbose)
{
System.IO.File.AppendAllText(Debug.debugFile, "INFO Got Nvidia GPU list.");
if (xmlcontent == null)
{
System.IO.File.AppendAllText(Debug.debugFile, "WARN GPU list is NULL! This is a possible error source.");
}
}
XDocument xDoc = XDocument.Parse(xmlcontent); XDocument xDoc = XDocument.Parse(xmlcontent);
string gpuName = GetGPUName(true); string gpuName = GetGPUName(true);
@ -149,14 +171,22 @@ namespace EnvyUpdate
{ {
case "psid": case "psid":
id = GetValueFromName(xDoc, gpuName, true); id = GetValueFromName(xDoc, gpuName, true);
if (Debug.isVerbose)
System.IO.File.AppendAllText(Debug.debugFile, "INFO Got psid: " + id);
break; break;
case "pfid": case "pfid":
id = GetValueFromName(xDoc, gpuName, false); id = GetValueFromName(xDoc, gpuName, false);
if (Debug.isVerbose)
System.IO.File.AppendAllText(Debug.debugFile, "INFO Got pfid: " + id);
break; break;
case "osid": case "osid":
id = GetOSID(); id = GetOSID();
if (Debug.isVerbose)
System.IO.File.AppendAllText(Debug.debugFile, "INFO Got osid: " + id);
break; break;
default: default:
if (Debug.isVerbose)
System.IO.File.AppendAllText(Debug.debugFile, "WARN GetIDs was called, but nothing was specified.");
break; break;
} }
@ -183,10 +213,15 @@ namespace EnvyUpdate
string sName = name.Value.ToString().ToLower(); string sName = name.Value.ToString().ToLower();
if (sName == query) if (sName == query)
{ {
if (Debug.isVerbose)
System.IO.File.AppendAllText(Debug.debugFile, "DEBUG Matched GetValueFromName query: " + sName);
string cleanResult = null; string cleanResult = null;
if (psid) if (psid)
{ {
if (Debug.isVerbose)
System.IO.File.AppendAllText(Debug.debugFile, "DEBUG Getting psid.");
if (i == 0) if (i == 0)
value1 = int.Parse(name.Parent.FirstAttribute.Value); value1 = int.Parse(name.Parent.FirstAttribute.Value);
else else
@ -194,6 +229,9 @@ namespace EnvyUpdate
} }
else else
{ {
if (Debug.isVerbose)
System.IO.File.AppendAllText(Debug.debugFile, "DEBUG Getting something else than psid.");
string result = name.Parent.Value.ToLower(); string result = name.Parent.Value.ToLower();
int index = result.IndexOf(sName); int index = result.IndexOf(sName);
cleanResult = (index < 0) cleanResult = (index < 0)
@ -226,6 +264,7 @@ namespace EnvyUpdate
} }
} }
return value; return value;
} }
/// <summary> /// <summary>
@ -271,6 +310,9 @@ namespace EnvyUpdate
public static string GetGPUName(bool lower) public static string GetGPUName(bool lower)
{ {
string GPUName = null; string GPUName = null;
if (Debug.isVerbose)
System.IO.File.AppendAllText(Debug.debugFile, "INFO Trying to get GPU name from ManagementObjects...");
foreach (ManagementObject obj in new ManagementObjectSearcher("SELECT * FROM Win32_VideoController").Get()) foreach (ManagementObject obj in new ManagementObjectSearcher("SELECT * FROM Win32_VideoController").Get())
{ {
//if (obj["Description"].ToString().ToLower().Contains("radeon")) //if (obj["Description"].ToString().ToLower().Contains("radeon"))
@ -296,6 +338,8 @@ namespace EnvyUpdate
break; break;
} }
} }
if (Debug.isVerbose)
System.IO.File.AppendAllText(Debug.debugFile, "INFO Found GPU name: " + GPUName);
// This should NEVER return null outside of debugging mode, since EnvyUpdate should refuse to start without and Nvidia GPU. // This should NEVER return null outside of debugging mode, since EnvyUpdate should refuse to start without and Nvidia GPU.
return GPUName; return GPUName;
} }
@ -388,7 +432,7 @@ namespace EnvyUpdate
int dtcid; int dtcid;
int dtid; int dtid;
if (Debug.isDebug) if (Debug.isFake)
{ {
psid = Debug.LoadFakeIDs("psid"); psid = Debug.LoadFakeIDs("psid");
pfid = Debug.LoadFakeIDs("pfid"); pfid = Debug.LoadFakeIDs("pfid");