From 24c349ce5059ba5872c9eed430ce2054ea0a1af7 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Sun, 27 Jan 2013 19:42:48 -0500 Subject: [PATCH] Tighter protection around unpredictable ApplicationSettings properties --- Windows/MainForm.cs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Windows/MainForm.cs b/Windows/MainForm.cs index 4b8b938..d84f59d 100644 --- a/Windows/MainForm.cs +++ b/Windows/MainForm.cs @@ -172,7 +172,7 @@ namespace NBTExplorer.Windows DirectoryDataNode node = new DirectoryDataNode(path); _nodeTree.Nodes.Add(CreateUnexpandedNode(node)); - AddPathToHistory(Settings.Default.RecentDirectories, path); + AddPathToHistory(GetRecentDirectories(), path); } else if (File.Exists(path)) { DataNode node = null; @@ -183,7 +183,7 @@ namespace NBTExplorer.Windows if (node != null) { _nodeTree.Nodes.Add(CreateUnexpandedNode(node)); - AddPathToHistory(Settings.Default.RecentFiles, path); + AddPathToHistory(GetRecentFiles(), path); } } } @@ -229,6 +229,26 @@ namespace NBTExplorer.Windows UpdateUI(); } + private StringCollection GetRecentFiles () + { + try { + return Settings.Default.RecentFiles; + } + catch { + return null; + } + } + + private StringCollection GetRecentDirectories () + { + try { + return Settings.Default.RecentDirectories; + } + catch { + return null; + } + } + private TreeNode CreateUnexpandedNode (DataNode node) { TreeNode frontNode = new TreeNode(node.NodeDisplay); @@ -1125,6 +1145,9 @@ namespace NBTExplorer.Windows private void AddPathToHistory (StringCollection list, string entry) { + if (list == null) + return; + foreach (string item in list) { if (item == entry) { list.Remove(item);