From f3304f51a15c5537a53d6f50be1c87f15b283413 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Mon, 31 Mar 2014 20:53:41 -0400 Subject: [PATCH] Fix crash when refreshing an unexpanded node. Improve error logging. --- NBTExplorer.Installer/Product.wxs | 2 +- NBTExplorer/Program.cs | 48 +++++++++++++++++++++- NBTExplorer/Properties/AssemblyInfo.cs | 4 +- NBTModel/Data/Nodes/CubicRegionDataNode.cs | 2 +- NBTModel/Data/Nodes/DataNode.cs | 3 ++ NBTModel/Data/Nodes/DirectoryDataNode.cs | 2 +- NBTModel/Data/Nodes/NbtFileDataNode.cs | 2 +- NBTModel/Data/Nodes/RegionFileDataNode.cs | 2 +- NBTModel/Properties/AssemblyInfo.cs | 4 +- 9 files changed, 58 insertions(+), 11 deletions(-) diff --git a/NBTExplorer.Installer/Product.wxs b/NBTExplorer.Installer/Product.wxs index 6fc2c09..3589a72 100644 --- a/NBTExplorer.Installer/Product.wxs +++ b/NBTExplorer.Installer/Product.wxs @@ -3,7 +3,7 @@ diff --git a/NBTExplorer/Program.cs b/NBTExplorer/Program.cs index 8140bd4..35b8b42 100644 --- a/NBTExplorer/Program.cs +++ b/NBTExplorer/Program.cs @@ -66,17 +66,48 @@ private static void ProcessException (Exception ex) return; } + if (IsMissingNBTModel(ex)) { + MessageBox.Show("NBTExplorer could not find required assembly \"NBTModel.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; + Exception ix = ex; + while (ix.InnerException != null) { + ix = ix.InnerException; errorText.AppendLine(); errorText.AppendLine("Caused by Inner Exception: " + ex.GetType().Name); errorText.AppendLine("Message: " + ex.Message); } + try { + using (var writer = new StreamWriter("NBTExplorer.error.log", true)) { + writer.WriteLine("NBTExplorer Error Report"); + writer.WriteLine(DateTime.Now); + writer.WriteLine("-------"); + writer.WriteLine(errorText); + writer.WriteLine("-------"); + + ix = ex; + while (ix != null) { + writer.WriteLine(ex.StackTrace); + writer.WriteLine("-------"); + ix = ix.InnerException; + } + + writer.WriteLine(); + } + + errorText.AppendLine(); + errorText.AppendLine("Additional error detail has been written to NBTExplorer.error.log"); + } + catch { } + MessageBox.Show(errorText.ToString(), "NBTExplorer failed to run", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } @@ -93,5 +124,18 @@ private static bool IsMissingSubstrate (Exception ex) return false; } + + private static bool IsMissingNBTModel (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("NBTModel")) + return true; + } + + return false; + } } } diff --git a/NBTExplorer/Properties/AssemblyInfo.cs b/NBTExplorer/Properties/AssemblyInfo.cs index 9bbeb69..e49eb43 100644 --- a/NBTExplorer/Properties/AssemblyInfo.cs +++ b/NBTExplorer/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.7.2.0")] -[assembly: AssemblyFileVersion("2.7.2.0")] +[assembly: AssemblyVersion("2.7.3.0")] +[assembly: AssemblyFileVersion("2.7.3.0")] diff --git a/NBTModel/Data/Nodes/CubicRegionDataNode.cs b/NBTModel/Data/Nodes/CubicRegionDataNode.cs index 5f59118..0865e44 100644 --- a/NBTModel/Data/Nodes/CubicRegionDataNode.cs +++ b/NBTModel/Data/Nodes/CubicRegionDataNode.cs @@ -91,7 +91,7 @@ public override bool RefreshNode () Release(); RestoreExpandSet(this, expandSet); - return true; + return expandSet != null; } } } diff --git a/NBTModel/Data/Nodes/DataNode.cs b/NBTModel/Data/Nodes/DataNode.cs index 0d244f4..74b7eb6 100644 --- a/NBTModel/Data/Nodes/DataNode.cs +++ b/NBTModel/Data/Nodes/DataNode.cs @@ -231,6 +231,9 @@ protected Dictionary BuildExpandSet (DataNode node) protected void RestoreExpandSet (DataNode node, Dictionary expandSet) { + if (expandSet == null) + return; + node.Expand(); foreach (DataNode child in node.Nodes) { diff --git a/NBTModel/Data/Nodes/DirectoryDataNode.cs b/NBTModel/Data/Nodes/DirectoryDataNode.cs index 9d5422a..4884e03 100644 --- a/NBTModel/Data/Nodes/DirectoryDataNode.cs +++ b/NBTModel/Data/Nodes/DirectoryDataNode.cs @@ -84,7 +84,7 @@ public override bool RefreshNode () Release(); RestoreExpandSet(this, expandSet); - return true; + return expandSet != null; } } } diff --git a/NBTModel/Data/Nodes/NbtFileDataNode.cs b/NBTModel/Data/Nodes/NbtFileDataNode.cs index 7df458c..8508a54 100644 --- a/NBTModel/Data/Nodes/NbtFileDataNode.cs +++ b/NBTModel/Data/Nodes/NbtFileDataNode.cs @@ -145,7 +145,7 @@ public override bool RefreshNode () Release(); RestoreExpandSet(this, expandSet); - return true; + return expandSet != null; } public override bool CanRenameNode diff --git a/NBTModel/Data/Nodes/RegionFileDataNode.cs b/NBTModel/Data/Nodes/RegionFileDataNode.cs index 719c790..e736745 100644 --- a/NBTModel/Data/Nodes/RegionFileDataNode.cs +++ b/NBTModel/Data/Nodes/RegionFileDataNode.cs @@ -106,7 +106,7 @@ public override bool RefreshNode () Release(); RestoreExpandSet(this, expandSet); - return true; + return expandSet != null; } } } diff --git a/NBTModel/Properties/AssemblyInfo.cs b/NBTModel/Properties/AssemblyInfo.cs index 9327da9..36e05d0 100644 --- a/NBTModel/Properties/AssemblyInfo.cs +++ b/NBTModel/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.1.0")] +[assembly: AssemblyFileVersion("1.0.1.0")]