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("-");
XmlDocument xDoc = new XmlDocument();
xDoc.Load(@"C:\Users\Skyler\Documents\GitHub\CodeWalker\Resources\Favorites.xml");
XmlNodeList FavoriteNodes = xDoc.DocumentElement.SelectNodes("Favorite");
foreach (XmlNode FavNode in FavoriteNodes)
try
{
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)
{
if (LocationTextBox.Text != "")
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(Application.StartupPath + @"Resources\Favorites.xml");
XmlNode FavToAdd = xDoc.CreateElement("Favorite");
FavToAdd.InnerText = LocationTextBox.Text;
xDoc.DocumentElement.AppendChild(FavToAdd);
xDoc.Save(Application.StartupPath + @"Resources\Favorites.xml");
LoadFavorites();
try
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(Application.StartupPath + @"\Resources\Favorites.xml");
XmlNode FavToAdd = xDoc.CreateElement("Favorite");
FavToAdd.InnerText = LocationTextBox.Text;
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
{

View File

@ -28,15 +28,22 @@ namespace CodeWalker.Explorer
private void Init()
{
xDoc.Load(Application.StartupPath + @"Resources\Favorites.xml");
FavoriteNodes = xDoc.DocumentElement.SelectNodes("Favorite");
Root = xDoc.DocumentElement;
foreach (XmlNode FavNode in FavoriteNodes)
try
{
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)
@ -62,7 +69,7 @@ namespace CodeWalker.Explorer
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();
Close();
}