forked from mirrors/NBTExplorer
More rigorous startup failure checking and reporting
This commit is contained in:
parent
b2d54f39a6
commit
366ec3fe9e
3 changed files with 65 additions and 3 deletions
|
@ -3,7 +3,7 @@
|
||||||
<Product Id="*"
|
<Product Id="*"
|
||||||
Name="NBTExplorer"
|
Name="NBTExplorer"
|
||||||
Language="1033"
|
Language="1033"
|
||||||
Version="2.6.0.0"
|
Version="2.6.1.0"
|
||||||
Manufacturer="Justin Aquadro"
|
Manufacturer="Justin Aquadro"
|
||||||
UpgradeCode="0bfb1026-21f2-4552-ad71-ca90aae10a25">
|
UpgradeCode="0bfb1026-21f2-4552-ad71-ca90aae10a25">
|
||||||
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
|
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using NBTExplorer.Windows;
|
using NBTExplorer.Windows;
|
||||||
|
|
||||||
|
@ -12,6 +16,11 @@ namespace NBTExplorer
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main ()
|
static void Main ()
|
||||||
{
|
{
|
||||||
|
Application.ThreadException += AppThreadFailureHandler;
|
||||||
|
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
|
||||||
|
|
||||||
|
AppDomain.CurrentDomain.UnhandledException += AppDomainFailureHandler;
|
||||||
|
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
Application.Run(new MainForm());
|
Application.Run(new MainForm());
|
||||||
|
@ -31,5 +40,58 @@ namespace NBTExplorer
|
||||||
MessageBox.Show("Application failed during static initialization: " + original.Message);
|
MessageBox.Show("Application failed during static initialization: " + original.Message);
|
||||||
Application.Exit();
|
Application.Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void AppThreadFailureHandler (object sender, ThreadExceptionEventArgs e)
|
||||||
|
{
|
||||||
|
ProcessException(e.Exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AppDomainFailureHandler (object sender, UnhandledExceptionEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.ExceptionObject is Exception)
|
||||||
|
ProcessException(e.ExceptionObject as Exception);
|
||||||
|
else if (e.IsTerminating) {
|
||||||
|
MessageBox.Show("NBTExplorer encountered an unknown exception object: " + e.ExceptionObject.GetType().FullName,
|
||||||
|
"NBTExplorer failed to run", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
Application.Exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ProcessException (Exception ex)
|
||||||
|
{
|
||||||
|
if (IsMissingSubstrate(ex)) {
|
||||||
|
MessageBox.Show("NBTExplorer could not find required assembly \"Substrate.dll\".\n\nIf you obtained NBTExplorer from a ZIP distribution, make sure you've extracted NBTExplorer and all of its supporting files into another directory before running it.",
|
||||||
|
"NBTExplorer failed to run", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
Application.Exit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder errorText = new StringBuilder();
|
||||||
|
errorText.AppendLine("NBTExplorer encountered the following exception while trying to run: " + ex.GetType().Name);
|
||||||
|
errorText.AppendLine("Message: " + ex.Message);
|
||||||
|
|
||||||
|
while (ex.InnerException != null) {
|
||||||
|
ex = ex.InnerException;
|
||||||
|
errorText.AppendLine();
|
||||||
|
errorText.AppendLine("Caused by Inner Exception: " + ex.GetType().Name);
|
||||||
|
errorText.AppendLine("Message: " + ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.Show(errorText.ToString(), "NBTExplorer failed to run", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
Application.Exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsMissingSubstrate (Exception ex)
|
||||||
|
{
|
||||||
|
if (ex is TypeInitializationException && ex.InnerException != null)
|
||||||
|
ex = ex.InnerException;
|
||||||
|
if (ex is FileNotFoundException) {
|
||||||
|
FileNotFoundException fileEx = ex as FileNotFoundException;
|
||||||
|
if (fileEx.FileName.Contains("Substrate"))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("2.6.0.0")]
|
[assembly: AssemblyVersion("2.6.1.0")]
|
||||||
[assembly: AssemblyFileVersion("2.6.0.0")]
|
[assembly: AssemblyFileVersion("2.6.1.0")]
|
||||||
|
|
Loading…
Reference in a new issue