Skip to content

Commit

Permalink
Fix crash when refreshing an unexpanded node. Improve error logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaquadro committed Apr 1, 2014
1 parent 3e6240d commit f3304f5
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 11 deletions.
2 changes: 1 addition & 1 deletion NBTExplorer.Installer/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Product Id="*"
Name="NBTExplorer"
Language="1033"
Version="2.7.2.0"
Version="2.7.3.0"
Manufacturer="Justin Aquadro"
UpgradeCode="0bfb1026-21f2-4552-ad71-ca90aae10a25">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
Expand Down
48 changes: 46 additions & 2 deletions NBTExplorer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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;
}
}
}
4 changes: 2 additions & 2 deletions NBTExplorer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
2 changes: 1 addition & 1 deletion NBTModel/Data/Nodes/CubicRegionDataNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public override bool RefreshNode ()
Release();
RestoreExpandSet(this, expandSet);

return true;
return expandSet != null;
}
}
}
3 changes: 3 additions & 0 deletions NBTModel/Data/Nodes/DataNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ public virtual bool HasUnexpandedChildren

protected void RestoreExpandSet (DataNode node, Dictionary<string, object> expandSet)
{
if (expandSet == null)
return;

node.Expand();

foreach (DataNode child in node.Nodes) {
Expand Down
2 changes: 1 addition & 1 deletion NBTModel/Data/Nodes/DirectoryDataNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public override bool RefreshNode ()
Release();
RestoreExpandSet(this, expandSet);

return true;
return expandSet != null;
}
}
}
2 changes: 1 addition & 1 deletion NBTModel/Data/Nodes/NbtFileDataNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public override bool RefreshNode ()
Release();
RestoreExpandSet(this, expandSet);

return true;
return expandSet != null;
}

public override bool CanRenameNode
Expand Down
2 changes: 1 addition & 1 deletion NBTModel/Data/Nodes/RegionFileDataNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public override bool RefreshNode ()
Release();
RestoreExpandSet(this, expandSet);

return true;
return expandSet != null;
}
}
}
4 changes: 2 additions & 2 deletions NBTModel/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

0 comments on commit f3304f5

Please sign in to comment.