Better error logging. MessageBoxAlertAdmin to make it easier for users to report errors

This commit is contained in:
Robert McRackan 2021-07-20 14:27:27 -04:00
parent 1ba54a74af
commit c49edbc77b
13 changed files with 348 additions and 33 deletions

View File

@ -259,7 +259,11 @@ namespace FileManager
var endingContents = JsonConvert.SerializeObject(jObj, Formatting.Indented); var endingContents = JsonConvert.SerializeObject(jObj, Formatting.Indented);
if (startingContents != endingContents) if (startingContents != endingContents)
{
try { Serilog.Log.Logger.Information("Libation files changed {@DebugInfo}", new { APPSETTINGS_JSON, LIBATION_FILES_KEY, directory }); }
catch { }
File.WriteAllText(APPSETTINGS_JSON, endingContents); File.WriteAllText(APPSETTINGS_JSON, endingContents);
}
return true; return true;

View File

@ -13,7 +13,7 @@
<!-- <PublishSingleFile>true</PublishSingleFile> --> <!-- <PublishSingleFile>true</PublishSingleFile> -->
<RuntimeIdentifier>win-x64</RuntimeIdentifier> <RuntimeIdentifier>win-x64</RuntimeIdentifier>
<Version>5.2.0.3</Version> <Version>5.2.0.13</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -310,13 +310,15 @@ namespace LibationLauncher
private static void checkForUpdate(Configuration config) private static void checkForUpdate(Configuration config)
{ {
string zipUrl;
string selectedPath;
try try
{ {
var gitHubClient = new Octokit.GitHubClient(new Octokit.ProductHeaderValue("Libation")); // timed out
var latest = getLatestRelease(TimeSpan.FromSeconds(30));
// https://octokitnet.readthedocs.io/en/latest/releases/ if (latest is null)
var releases = gitHubClient.Repository.Release.GetAll("rmcrackan", "Libation").GetAwaiter().GetResult(); return;
var latest = releases.First(r => !r.Draft && !r.Prerelease);
var latestVersionString = latest.TagName.Trim('v'); var latestVersionString = latest.TagName.Trim('v');
if (!Version.TryParse(latestVersionString, out var latestRelease)) if (!Version.TryParse(latestVersionString, out var latestRelease))
@ -328,21 +330,27 @@ namespace LibationLauncher
// we have an update // we have an update
var zip = latest.Assets.FirstOrDefault(a => a.BrowserDownloadUrl.EndsWith(".zip")); var zip = latest.Assets.FirstOrDefault(a => a.BrowserDownloadUrl.EndsWith(".zip"));
var zipUrl = zip?.BrowserDownloadUrl; zipUrl = zip?.BrowserDownloadUrl;
if (zipUrl is null) if (zipUrl is null)
{ {
MessageBox.Show(latest.HtmlUrl, "New version available"); MessageBox.Show(latest.HtmlUrl, "New version available");
return; return;
} }
var result = MessageBox.Show($"New version available @ {latest.HtmlUrl}\r\nDownload the zip file?", "New version available", MessageBoxButtons.YesNo, MessageBoxIcon.Information); var result = MessageBox.Show($"New version available @ {latest.HtmlUrl}\r\nDownload the zip file?", "New version available", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result != DialogResult.Yes) if (result != DialogResult.Yes)
return; return;
using var fileSelector = new SaveFileDialog { FileName = zip.Name, Filter = "Zip Files (*.zip)|*.zip|All files (*.*)|*.*" }; using var fileSelector = new SaveFileDialog { FileName = zip.Name, Filter = "Zip Files (*.zip)|*.zip|All files (*.*)|*.*" };
if (fileSelector.ShowDialog() != DialogResult.OK) if (fileSelector.ShowDialog() != DialogResult.OK)
return; return;
var selectedPath = fileSelector.FileName; selectedPath = fileSelector.FileName;
}
catch (Exception ex)
{
MessageBoxAlertAdmin.Show("Error checking for update", "Error checking for update", ex);
return;
}
try try
{ {
@ -350,19 +358,25 @@ namespace LibationLauncher
} }
catch (Exception ex) catch (Exception ex)
{ {
Error(ex, "Error downloading update"); MessageBoxAlertAdmin.Show("Error downloading update", "Error downloading update", ex);
}
}
catch (Exception ex)
{
Error(ex, "Error checking for update");
} }
} }
private static void Error(Exception ex, string message) private static Octokit.Release getLatestRelease(TimeSpan timeout)
{ {
Log.Logger.Error(ex, message); var task = System.Threading.Tasks.Task.Run(() => getLatestRelease());
MessageBox.Show($"{message}\r\nSee log for details"); if (task.Wait(timeout))
return task.Result;
return null;
}
private static Octokit.Release getLatestRelease()
{
var gitHubClient = new Octokit.GitHubClient(new Octokit.ProductHeaderValue("Libation"));
// https://octokitnet.readthedocs.io/en/latest/releases/
var releases = gitHubClient.Repository.Release.GetAll("rmcrackan", "Libation").GetAwaiter().GetResult();
var latest = releases.First(r => !r.Draft && !r.Prerelease);
return latest;
} }
private static void logStartupState(Configuration config) private static void logStartupState(Configuration config)

View File

@ -125,7 +125,7 @@ namespace LibationWinForms.Dialogs
} }
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show($"Error: {ex.Message}", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxAlertAdmin.Show("Error attempting to save accounts", "Error saving accounts", ex);
} }
} }

View File

@ -35,9 +35,10 @@ namespace LibationWinForms.Dialogs
} }
catch (Exception ex) catch (Exception ex)
{ {
var msg = "Error importing library. Please try again. If this still happens after 2 or 3 tries, stop and contact administrator"; MessageBoxAlertAdmin.Show(
Serilog.Log.Logger.Error(ex, msg); "Error importing library. Please try again. If this still happens after 2 or 3 tries, stop and contact administrator",
MessageBox.Show(msg, "Error importing library", MessageBoxButtons.OK, MessageBoxIcon.Error); "Error importing library",
ex);
} }
} }

View File

@ -35,7 +35,7 @@ namespace LibationWinForms.Dialogs
if (!System.IO.Directory.Exists(libationDir)) if (!System.IO.Directory.Exists(libationDir))
{ {
MessageBox.Show("Not saving change to Libation Files location. This folder does not exist:\r\n" + libationDir); MessageBox.Show("Not saving change to Libation Files location. This folder does not exist:\r\n" + libationDir, "Folder does not exist", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }

View File

@ -0,0 +1,155 @@

namespace LibationWinForms.Dialogs
{
partial class MessageBoxAlertAdminDialog
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MessageBoxAlertAdminDialog));
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.descriptionLbl = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.githubLink = new System.Windows.Forms.LinkLabel();
this.okBtn = new System.Windows.Forms.Button();
this.logsLink = new System.Windows.Forms.LinkLabel();
this.exceptionTb = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(12, 12);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(64, 64);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// descriptionLbl
//
this.descriptionLbl.AutoSize = true;
this.descriptionLbl.Location = new System.Drawing.Point(82, 12);
this.descriptionLbl.Name = "descriptionLbl";
this.descriptionLbl.Size = new System.Drawing.Size(89, 45);
this.descriptionLbl.TabIndex = 0;
this.descriptionLbl.Text = "[Error message]\r\n[Error message]\r\n[Error message]";
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 244);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(269, 90);
this.label1.TabIndex = 2;
this.label1.Text = resources.GetString("label1.Text");
//
// githubLink
//
this.githubLink.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.githubLink.AutoSize = true;
this.githubLink.Location = new System.Drawing.Point(271, 274);
this.githubLink.Name = "githubLink";
this.githubLink.Size = new System.Drawing.Size(116, 15);
this.githubLink.TabIndex = 3;
this.githubLink.TabStop = true;
this.githubLink.Text = "Click to go to github";
this.githubLink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.githubLink_LinkClicked);
//
// okBtn
//
this.okBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.okBtn.Location = new System.Drawing.Point(256, 347);
this.okBtn.Name = "okBtn";
this.okBtn.Size = new System.Drawing.Size(75, 23);
this.okBtn.TabIndex = 5;
this.okBtn.Text = "OK";
this.okBtn.UseVisualStyleBackColor = true;
this.okBtn.Click += new System.EventHandler(this.okBtn_Click);
//
// logsLink
//
this.logsLink.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.logsLink.AutoSize = true;
this.logsLink.Location = new System.Drawing.Point(271, 289);
this.logsLink.Name = "logsLink";
this.logsLink.Size = new System.Drawing.Size(155, 15);
this.logsLink.TabIndex = 4;
this.logsLink.TabStop = true;
this.logsLink.Text = "Click to open log files folder";
this.logsLink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.logsLink_LinkClicked);
//
// exceptionTb
//
this.exceptionTb.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.exceptionTb.Location = new System.Drawing.Point(12, 82);
this.exceptionTb.Multiline = true;
this.exceptionTb.Name = "exceptionTb";
this.exceptionTb.ReadOnly = true;
this.exceptionTb.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.exceptionTb.Size = new System.Drawing.Size(560, 159);
this.exceptionTb.TabIndex = 1;
//
// MessageBoxAlertAdminDialog
//
this.AcceptButton = this.okBtn;
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(584, 382);
this.Controls.Add(this.exceptionTb);
this.Controls.Add(this.logsLink);
this.Controls.Add(this.okBtn);
this.Controls.Add(this.githubLink);
this.Controls.Add(this.label1);
this.Controls.Add(this.descriptionLbl);
this.Controls.Add(this.pictureBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "MessageBoxAlertAdminDialog";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "MessageBoxAlertAdmin";
this.Load += new System.EventHandler(this.MessageBoxAlertAdminDialog_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label descriptionLbl;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.LinkLabel githubLink;
private System.Windows.Forms.Button okBtn;
private System.Windows.Forms.LinkLabel logsLink;
private System.Windows.Forms.TextBox exceptionTb;
}
}

View File

@ -0,0 +1,46 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using Dinah.Core;
namespace LibationWinForms.Dialogs
{
public partial class MessageBoxAlertAdminDialog : Form
{
public MessageBoxAlertAdminDialog() => InitializeComponent();
/// <summary>
/// Displays a message box with specified text and caption.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="exception">Exception to display</param>
public MessageBoxAlertAdminDialog(string text, string caption, Exception exception) : this()
{
this.descriptionLbl.Text = text;
this.Text = caption;
this.exceptionTb.Text = $"{exception.Message}\r\n\r\n{exception.StackTrace}";
}
private void MessageBoxAlertAdminDialog_Load(object sender, EventArgs e)
{
if (this.DesignMode)
return;
System.Media.SystemSounds.Hand.Play();
pictureBox1.Image = SystemIcons.Error.ToBitmap();
}
private void githubLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
=> Go.To.Url("https://github.com/rmcrackan/Libation/issues");
private void logsLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
=> Go.To.Folder(FileManager.Configuration.Instance.LibationFiles);
private void okBtn_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}

View File

@ -0,0 +1,68 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="label1.Text" xml:space="preserve">
<value>If you'd like to report this error to an advinistrator:
Step 1: Go to Libation's "issues" page on github
Step 2: Find your log files
Setp 3: Click "New issue" button
Step 4: Drag/drop your log files</value>
</data>
</root>

View File

@ -60,7 +60,7 @@ namespace LibationWinForms.Dialogs
if (string.IsNullOrWhiteSpace(newBooks)) if (string.IsNullOrWhiteSpace(newBooks))
{ {
MessageBox.Show("Cannot set Books Location to blank"); MessageBox.Show("Cannot set Books Location to blank", "Location is blank", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
@ -68,7 +68,7 @@ namespace LibationWinForms.Dialogs
{ {
if (booksSelectControl.SelectedDirectoryIsCustom) if (booksSelectControl.SelectedDirectoryIsCustom)
{ {
MessageBox.Show($"Not saving change to Books location. This folder does not exist:\r\n{newBooks}"); MessageBox.Show($"Not saving change to Books location. This folder does not exist:\r\n{newBooks}", "Folder does not exist", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }

View File

@ -338,8 +338,7 @@ namespace LibationWinForms
} }
catch (Exception ex) catch (Exception ex)
{ {
Serilog.Log.Logger.Error(ex, "Error attempting to export library"); MessageBoxAlertAdmin.Show("Error attempting to export your library.", "Error exporting", ex);
MessageBox.Show("Error attempting to export your library. Error message:\r\n\r\n" + ex.Message, "Error exporting", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
#endregion #endregion
@ -409,7 +408,7 @@ namespace LibationWinForms
if (!Configuration.Instance.TrySetLibationFiles(libationFilesDialog.SelectedDirectory)) if (!Configuration.Instance.TrySetLibationFiles(libationFilesDialog.SelectedDirectory))
{ {
MessageBox.Show("Not saving change to Libation Files location. This folder does not exist:\r\n" + libationFilesDialog.SelectedDirectory); MessageBox.Show("Not saving change to Libation Files location. This folder does not exist:\r\n" + libationFilesDialog.SelectedDirectory, "Error saving change", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LibationWinForms.Dialogs;
namespace LibationWinForms
{
public static class MessageBoxAlertAdmin
{
/// <summary>
/// Logs error. Displays a message box dialog with specified text and caption.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="exception">Exception to log</param>
/// <returns>One of the System.Windows.Forms.DialogResult values.</returns>
public static System.Windows.Forms.DialogResult Show(string text, string caption, Exception exception)
{
Serilog.Log.Logger.Error(exception, "Alert admin error: {@DebugText}", new { text, caption });
using var form = new MessageBoxAlertAdminDialog(text, caption, exception);
return form.ShowDialog();
}
}
}

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using ApplicationServices; using ApplicationServices;
using DataLayer; using DataLayer;
using Dinah.Core;
using Dinah.Core.Collections.Generic; using Dinah.Core.Collections.Generic;
using Dinah.Core.DataBinding; using Dinah.Core.DataBinding;
using Dinah.Core.Windows.Forms; using Dinah.Core.Windows.Forms;
@ -178,7 +179,7 @@ namespace LibationWinForms
if (FileManager.AudibleFileStorage.Audio.Exists(productId)) if (FileManager.AudibleFileStorage.Audio.Exists(productId))
{ {
var filePath = FileManager.AudibleFileStorage.Audio.GetPath(productId); var filePath = FileManager.AudibleFileStorage.Audio.GetPath(productId);
System.Diagnostics.Process.Start("explorer.exe", $"/select, \"{filePath}\""); Go.To.File(filePath);
return; return;
} }