Tighter protection around unpredictable ApplicationSettings properties

This commit is contained in:
Justin Aquadro 2013-01-27 19:42:48 -05:00
parent 1596d3365d
commit 24c349ce50

View file

@ -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);