private static DeckStatsList Load() { SetupDeckStatsFile(); var file = Config.Instance.DataDir + "DeckStats.xml"; if (!File.Exists(file)) { return(new DeckStatsList()); } DeckStatsList instance = null; try { instance = XmlManager <DeckStatsList> .Load(file); } catch (Exception) { //failed loading deckstats var corruptedFile = Helper.GetValidFilePath(Config.Instance.DataDir, "DeckStats_corrupted", "xml"); try { File.Move(file, corruptedFile); } catch (Exception) { throw new Exception( "Can not load or move DeckStats.xml file. Please manually delete the file in \"%appdata\\HearthstoneDeckTracker\"."); } //get latest backup file var backup = new DirectoryInfo(Config.Instance.DataDir).GetFiles("DeckStats_backup*").OrderByDescending(x => x.CreationTime).FirstOrDefault(); if (backup != null) { try { File.Copy(backup.FullName, file); instance = XmlManager <DeckStatsList> .Load(file); } catch (Exception ex) { throw new Exception( "Error restoring DeckStats backup. Please manually rename \"DeckStats_backup.xml\" to \"DeckStats.xml\" in \"%appdata\\HearthstoneDeckTracker\".", ex); } } if (instance == null) { throw new Exception("DeckStats.xml is corrupted."); } } instance.DeckStats = instance.DeckStats.Where(x => x.Games.Any()).ToList(); return(instance); }
internal static async Task DeleteGamesWithoutConfirmation(params GameStats[] games) { games = games.Where(x => x != null).ToArray(); if (games.Length == 0) { return; } var saveDeckStats = false; var saveDefaultDeckStats = false; foreach (var game in games) { var deck = DeckList.Instance.Decks.FirstOrDefault(d => d.DeckStats.Games.Contains(game)); if (deck != null) { if (deck.DeckStats.Games.Contains(game)) { game.DeleteGameFile(); deck.DeckStats.Games.Remove(game); Log.Info($"Deleted game {game} from {deck}."); saveDeckStats = true; } } else { var deckstats = DefaultDeckStats.Instance.DeckStats.FirstOrDefault(ds => ds.Games.Contains(game)); if (deckstats != null) { game.DeleteGameFile(); deckstats.Games.Remove(game); Log.Info($"Deleted game {game} from default deck."); saveDefaultDeckStats = true; } } } if (HearthStatsAPI.IsLoggedIn && games.Any(g => g.HasHearthStatsId) && await Core.MainWindow.ShowCheckHearthStatsMatchDeletionDialog()) { HearthStatsManager.DeleteMatchesAsync(games.ToList()).Forget(); } if (saveDeckStats) { DeckStatsList.Save(); } if (saveDefaultDeckStats) { DefaultDeckStats.Save(); } Log.Info($"Deleted {games.Length} games"); Core.MainWindow.DeckPickerList.UpdateDecks(); ConstructedStats.Instance.UpdateConstructedStats(); }
public static void Load() { var file = Config.Instance.DataDir + "DeckStats.xml"; if (!File.Exists(file)) { return; } try { _instance = XmlManager <DeckStatsList> .Load(file); } catch (Exception) { //failed loading deckstats var corruptedFile = Helper.GetValidFilePath(Config.Instance.DataDir, "DeckStats_corrupted", "xml"); try { File.Move(file, corruptedFile); } catch (Exception) { throw new Exception( "Can not load or move DeckStats.xml file. Please manually delete the file in \"%appdata\\HearthstoneDeckTracker\"."); } //get latest backup file var backup = new DirectoryInfo(Config.Instance.DataDir).GetFiles("DeckStats_backup*").OrderByDescending(x => x.CreationTime).FirstOrDefault(); if (backup != null) { try { File.Copy(backup.FullName, file); _instance = XmlManager <DeckStatsList> .Load(file); } catch (Exception) { throw new Exception( "Error restoring DeckStats backup. Please manually rename \"DeckStats_backup.xml\" to \"DeckStats.xml\" in \"%appdata\\HearthstoneDeckTracker\"."); } } else { //can't call ShowMessageAsync on MainWindow at this point. todo: Add something like a message queue. MessageBox.Show("Your DeckStats file got corrupted and there was no backup to restore from.", "Error restoring DeckStats backup"); } } }
internal static void DeleteGamesWithoutConfirmation(params GameStats[] games) { games = games.Where(x => x != null).ToArray(); if (games.Length == 0) { return; } var saveDeckStats = false; var saveDefaultDeckStats = false; foreach (var game in games) { var deck = DeckList.Instance.Decks.FirstOrDefault(d => d.DeckStats.Games.Contains(game)); if (deck != null) { if (deck.DeckStats.Games.Contains(game)) { deck.DeckStats.Games.Remove(game); Log.Info($"Deleted game {game} from {deck}."); saveDeckStats = true; } } else { var deckstats = DefaultDeckStats.Instance.DeckStats.FirstOrDefault(ds => ds.Games.Contains(game)); if (deckstats != null) { deckstats.Games.Remove(game); Log.Info($"Deleted game {game} from default deck."); saveDefaultDeckStats = true; } } } if (saveDeckStats) { DeckStatsList.Save(); } if (saveDefaultDeckStats) { DefaultDeckStats.Save(); } Log.Info($"Deleted {games.Length} games"); Core.MainWindow.DeckPickerList.UpdateDecks(); ConstructedStats.Instance.UpdateConstructedStats(); }
public static void Load() { SetupDeckStatsFile(); var file = Config.Instance.DataDir + "DeckStats.xml"; if(!File.Exists(file)) return; try { _instance = XmlManager<DeckStatsList>.Load(file); } catch(Exception) { //failed loading deckstats var corruptedFile = Helper.GetValidFilePath(Config.Instance.DataDir, "DeckStats_corrupted", "xml"); try { File.Move(file, corruptedFile); } catch(Exception) { throw new Exception( "Can not load or move DeckStats.xml file. Please manually delete the file in \"%appdata\\HearthstoneDeckTracker\"."); } //get latest backup file var backup = new DirectoryInfo(Config.Instance.DataDir).GetFiles("DeckStats_backup*").OrderByDescending(x => x.CreationTime).FirstOrDefault(); if(backup != null) { try { File.Copy(backup.FullName, file); _instance = XmlManager<DeckStatsList>.Load(file); } catch(Exception ex) { throw new Exception( "Error restoring DeckStats backup. Please manually rename \"DeckStats_backup.xml\" to \"DeckStats.xml\" in \"%appdata\\HearthstoneDeckTracker\".", ex); } } else throw new Exception("DeckStats.xml is corrupted."); } }
public static void Load() { var file = Config.Instance.DataDir + "DeckStats.xml"; _instance = XmlManager <DeckStatsList> .Load(file); }
public static void Load() { var file = Config.Instance.HomeDir + "DeckStats.xml"; _instance = XmlManager<DeckStatsList>.Load(file); }