Skip to content

Commit

Permalink
added some information if problems loading .xml files arise
Browse files Browse the repository at this point in the history
  • Loading branch information
epix37 committed Jun 2, 2014
1 parent a88b5a6 commit f875adb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
22 changes: 17 additions & 5 deletions Hearthstone Deck Tracker/Helper.cs
Expand Up @@ -10,15 +10,27 @@ public class Helper

public static void CheckForUpdates()
{

SerializableVersion version;
_xmlManager = new XmlManager<SerializableVersion>() { Type = typeof(SerializableVersion) };

try
{
version = _xmlManager.Load("Version.xml");
}
catch (Exception e)
{
MessageBox.Show(
e.Message + "\n\n" + e.InnerException + "\n\n If you don't know how to fix this, please verwrite Version.xml with the default file.", "Error loading Version.xml");
return;
}


var versionXmlUrl =
@"https://raw.githubusercontent.com/Epix37/Hearthstone-Deck-Tracker/master/Hearthstone%20Deck%20Tracker/Version.xml";

var xml = new WebClient().DownloadString(versionXmlUrl);

_xmlManager = new XmlManager<SerializableVersion>() {Type = typeof (SerializableVersion)};

var currentVersion = new Version(_xmlManager.Load("Version.xml").ToString());

var currentVersion = new Version(version.ToString());
var newVersion = new Version(_xmlManager.LoadFromString(xml).ToString());

if (newVersion > currentVersion)
Expand Down
34 changes: 24 additions & 10 deletions Hearthstone Deck Tracker/NewMainWindow.xaml.cs
Expand Up @@ -77,7 +77,17 @@ public NewMainWindow()
//load config
_config = new Config();
_xmlManagerConfig = new XmlManager<Config> {Type = typeof (Config)};
_config = _xmlManagerConfig.Load("config.xml");
try
{
_config = _xmlManagerConfig.Load("config.xml");
}
catch (Exception e)
{
MessageBox.Show(
e.Message + "\n\n" + e.InnerException + "\n\n If you don't know how to fix this, please overwrite config with the default one.", "Error loading config.xml");
Close();
return;
}

//load saved decks
if (!File.Exists("PlayerDecks.xml"))
Expand All @@ -89,14 +99,18 @@ public NewMainWindow()
}
}
_xmlManager = new XmlManager<Decks> {Type = typeof (Decks)};
_deckList = _xmlManager.Load("PlayerDecks.xml");

//add saved decks to gui
//foreach (var deck in _deckList.DecksList)
// {
//ComboBoxDecks.Items.Add(deck.Name);
// ListboxDecks.Items.Add(deck);
//}
try
{
_deckList = _xmlManager.Load("PlayerDecks.xml");
}
catch (Exception e)
{
MessageBox.Show(
e.Message + "\n\n" + e.InnerException + "\n\n If you don't know how to fix this, please delete PlayerDecks.xml (this will cause you to lose your decks).", "Error loading PlayerDecks.xml");
Close();
return;
}

ListboxDecks.ItemsSource = _deckList.DecksList;


Expand Down Expand Up @@ -539,7 +553,7 @@ private void Update()
}
else
{
_overlay.Dispatcher.BeginInvoke(new Action(() => _overlay.EnableCanvas(false)));
_overlay.Dispatcher.BeginInvoke(new Action( () => _overlay.EnableCanvas(false)));
}
Thread.Sleep(_config.UpdateDelay);
}
Expand Down

0 comments on commit f875adb

Please sign in to comment.