Added Try/Catch statements (fix)

This commit is contained in:
FiftyShadesOfBlue 2018-03-16 02:38:33 -04:00
parent d86255de58
commit 902934a4b0
2 changed files with 41 additions and 21 deletions

View File

@ -3323,27 +3323,40 @@ namespace CodeWalker
favoritesToolStripMenuItem.DropDownItems.Add("-"); favoritesToolStripMenuItem.DropDownItems.Add("-");
XmlDocument xDoc = new XmlDocument(); try
xDoc.Load(@"C:\Users\Skyler\Documents\GitHub\CodeWalker\Resources\Favorites.xml");
XmlNodeList FavoriteNodes = xDoc.DocumentElement.SelectNodes("Favorite");
foreach (XmlNode FavNode in FavoriteNodes)
{ {
AddFavoriteItem(FavNode.InnerText); XmlDocument xDoc = new XmlDocument();
xDoc.Load(Application.StartupPath + @"\Resources\Favorites.xml");
XmlNodeList FavoriteNodes = xDoc.DocumentElement.SelectNodes("Favorite");
foreach (XmlNode FavNode in FavoriteNodes)
{
AddFavoriteItem(FavNode.InnerText);
}
}
catch
{
MessageBox.Show("Favorites.xml is missing from " + Application.StartupPath + @"\Resources", "Error");
} }
} }
private void addToFavToolStripMenuItem_Click(object sender, EventArgs e) private void addToFavToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (LocationTextBox.Text != "") if (LocationTextBox.Text != "")
{ {
XmlDocument xDoc = new XmlDocument(); try
xDoc.Load(Application.StartupPath + @"Resources\Favorites.xml"); {
XmlNode FavToAdd = xDoc.CreateElement("Favorite"); XmlDocument xDoc = new XmlDocument();
FavToAdd.InnerText = LocationTextBox.Text; xDoc.Load(Application.StartupPath + @"\Resources\Favorites.xml");
xDoc.DocumentElement.AppendChild(FavToAdd); XmlNode FavToAdd = xDoc.CreateElement("Favorite");
xDoc.Save(Application.StartupPath + @"Resources\Favorites.xml"); FavToAdd.InnerText = LocationTextBox.Text;
LoadFavorites(); xDoc.DocumentElement.AppendChild(FavToAdd);
xDoc.Save(Application.StartupPath + @"\Resources\Favorites.xml");
LoadFavorites();
}
catch
{
MessageBox.Show("Favorites.xml is missing from " + Application.StartupPath + @"\Resources", "Error");
}
} }
else else
{ {

View File

@ -28,15 +28,22 @@ namespace CodeWalker.Explorer
private void Init() private void Init()
{ {
xDoc.Load(Application.StartupPath + @"Resources\Favorites.xml"); try
FavoriteNodes = xDoc.DocumentElement.SelectNodes("Favorite");
Root = xDoc.DocumentElement;
foreach (XmlNode FavNode in FavoriteNodes)
{ {
FavoritesTreeView.Nodes[0].Nodes.Add(FavNode.InnerText); xDoc.Load(Application.StartupPath + @"\Resources\Favorites.xml");
} FavoriteNodes = xDoc.DocumentElement.SelectNodes("Favorite");
Root = xDoc.DocumentElement;
foreach (XmlNode FavNode in FavoriteNodes)
{
FavoritesTreeView.Nodes[0].Nodes.Add(FavNode.InnerText);
}
FavoritesTreeView.ExpandAll(); FavoritesTreeView.ExpandAll();
}
catch
{
MessageBox.Show("Favorites.xml is missing from " + Application.StartupPath + @"\Resources", "Error");
}
} }
private void ClearAllFavoritesButton_Click(object sender, EventArgs e) private void ClearAllFavoritesButton_Click(object sender, EventArgs e)
@ -62,7 +69,7 @@ namespace CodeWalker.Explorer
private void SaveButton_Click(object sender, EventArgs e) private void SaveButton_Click(object sender, EventArgs e)
{ {
xDoc.Save(@"C:\Users\Skyler\Documents\GitHub\CodeWalker\Resources\Favorites.xml"); xDoc.Save(Application.StartupPath + @"\Resources\Favorites.xml");
ExploreForm.LoadFavorites(); ExploreForm.LoadFavorites();
Close(); Close();
} }