improve logging

This commit is contained in:
Jakob 2023-07-09 18:19:33 +02:00
parent 90fc53ce00
commit d347ccefdf
5 changed files with 65 additions and 19 deletions

View file

@ -49,7 +49,6 @@ namespace EnvyUpdate
return "Nvidia GeForce RTX 4080 (debug)"; return "Nvidia GeForce RTX 4080 (debug)";
} }
[ConditionalAttribute("DEBUG")]
public static void LogToFile(string content) public static void LogToFile(string content)
{ {
if (isVerbose) if (isVerbose)

File diff suppressed because one or more lines are too long

View file

@ -21,6 +21,9 @@ namespace EnvyUpdate
labelVer.Content += " " + version; labelVer.Content += " " + version;
if (GlobalVars.monitoringInstall) if (GlobalVars.monitoringInstall)
labelVer.FontStyle = FontStyles.Italic; labelVer.FontStyle = FontStyles.Italic;
if (File.Exists(Path.Combine(GlobalVars.exeloc, "envyupdate.log")))
chkLog.IsChecked = true;
} }
private void ButtonWeb_Click(object sender, RoutedEventArgs e) private void ButtonWeb_Click(object sender, RoutedEventArgs e)
@ -28,5 +31,20 @@ namespace EnvyUpdate
Debug.LogToFile("INFO Launching website."); Debug.LogToFile("INFO Launching website.");
System.Diagnostics.Process.Start("https://github.com/fyr77/EnvyUpdate/"); System.Diagnostics.Process.Start("https://github.com/fyr77/EnvyUpdate/");
} }
private void chkLog_Checked(object sender, RoutedEventArgs e)
{
Debug.isVerbose = true;
Debug.LogToFile("------");
Debug.LogToFile("INFO Enabled logging to file. Restart Application to see full startup log.");
}
private void chkLog_Unchecked(object sender, RoutedEventArgs e)
{
Debug.LogToFile("INFO Disabled logging to file.");
if (File.Exists(Path.Combine(GlobalVars.exeloc, "envyupdate.log")))
File.Move(Path.Combine(GlobalVars.exeloc, "envyupdate.log"), Path.Combine(GlobalVars.exeloc, "envyupdate.old.log"));
Debug.isVerbose = false;
}
} }
} }

View file

@ -37,11 +37,16 @@ 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 (Debug.isVerbose) // Check if Debug file exists
if (File.Exists(Path.Combine(GlobalVars.exedirectory, "envyupdate.log")))
{ {
File.AppendAllText(Debug.debugFile, "INFO Starting EnvyUpdate, version " + System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion); Debug.isVerbose = true;
Debug.LogToFile("------");
Debug.LogToFile("INFO Found log file, will start logging to this.");
} }
Debug.LogToFile("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"))
{ {
@ -95,7 +100,7 @@ namespace EnvyUpdate
else else
textblockLocalType.Text = "Standard"; textblockLocalType.Text = "Standard";
Debug.LogToFile("INFO Done detecting driver type."); Debug.LogToFile("INFO Done detecting driver type: " + textblockLocalType.Text);
// 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")))
@ -189,7 +194,7 @@ namespace EnvyUpdate
} }
catch (ArgumentException) catch (ArgumentException)
{ {
Debug.LogToFile("WARN Could not get GPU update URL, trying again with standard driver."); Debug.LogToFile("WARN Could not get GPU update URL, trying again with non-studio driver.");
try try
{ {
// disable SD and try with GRD // disable SD and try with GRD
@ -202,6 +207,11 @@ namespace EnvyUpdate
MessageBox.Show(Properties.Resources.ui_studionotsupported); MessageBox.Show(Properties.Resources.ui_studionotsupported);
radioGRD.IsChecked = true; radioGRD.IsChecked = true;
} }
catch (ArgumentNullException)
{
MessageBox.Show("ERROR: Could not get list of GPU models from Nvidia, please check your network connection.\nOtherwise, please report this issue on GitHub.");
Environment.Exit(11);
}
catch (ArgumentException e) catch (ArgumentException e)
{ {
// Now we have a problem. // Now we have a problem.

View file

@ -132,7 +132,7 @@ namespace EnvyUpdate
Environment.Exit(2); Environment.Exit(2);
} }
public static int GetIDs(string IDtype) public static int GetIDs(string IDtype, bool retry = true)
{ {
string xmlcontent = null; string xmlcontent = null;
int id = -1; int id = -1;
@ -154,7 +154,6 @@ namespace EnvyUpdate
Debug.LogToFile("INFO Got Nvidia GPU list."); Debug.LogToFile("INFO Got Nvidia GPU list.");
if (xmlcontent == null) if (xmlcontent == null)
{ {
Debug.LogToFile("WARN GPU list is NULL! This is a possible error source.");
switch (IDtype) switch (IDtype)
{ {
case "osid": case "osid":
@ -162,8 +161,22 @@ namespace EnvyUpdate
Debug.LogToFile("WARN Ignore previous warning, just getting osid."); Debug.LogToFile("WARN Ignore previous warning, just getting osid.");
Debug.LogToFile("INFO Got osid: " + id); Debug.LogToFile("INFO Got osid: " + id);
break; break;
case "psid":
case "pfid":
Debug.LogToFile("WARN GPU list is NULL! This is a possible error source.");
if (retry)
{
Debug.LogToFile("WARN Trying to get ID again.");
id = GetIDs(IDtype, false);
}
else
{
Debug.LogToFile("FATAL Could not get GPU list to find IDs.");
throw new ArgumentNullException();
}
break;
default: default:
Debug.LogToFile("WARN GetIDs was called, but nothing was specified."); Debug.LogToFile("WARN GetIDs was called, but nothing was specified. THIS SHOULD NOT HAPPEN!");
break; break;
} }
} }
@ -224,7 +237,7 @@ namespace EnvyUpdate
} }
else else
{ {
Debug.LogToFile("DEBUG Getting something else than psid."); Debug.LogToFile("DEBUG Getting something other than psid.");
string result = name.Parent.Value.ToLower(); string result = name.Parent.Value.ToLower();
int index = result.IndexOf(sName); int index = result.IndexOf(sName);