private async void Button_Click(object sender, RoutedEventArgs e) { var matches = _allWrappers.Where(x => x.ToDelete).Select(x => x.GameStats).ToList(); Logger.WriteLine("Deleting " + matches.Count + " duplicate matches."); var controller = await this.ShowProgressAsync("Deleting duplicate matches...", "Deleting duplicates on HearthStats..."); await HearthStatsManager.DeleteMatchesAsync(matches.ToList(), false); controller.SetMessage("Deleting local duplicates..."); foreach (var match in matches) { var deck = DeckList.Instance.Decks.FirstOrDefault(d => d.DeckId == match.DeckId); if (deck == null) { continue; } deck.DeckStats.Games.Remove(match); } DeckStatsList.Save(); Helper.MainWindow.DeckPickerList.UpdateDecks(); await controller.CloseAsync(); await this.ShowMessageAsync("Success", "Deleted " + _allWrappers.Count(x => x.ToDelete) + " duplicates."); Config.Instance.FixedDuplicateMatches = true; Config.Save(); Close(); }
private async void ButtonDeleteGame_OnClick(object sender, RoutedEventArgs e) { if (SelectedGame == null) { return; } var run = DataGridArenaRuns.SelectedItem as ArenaRun; if (run == null) { return; } var window = Helper.GetParentWindow(this); if (await window.ShowDeleteGameStatsMessage(SelectedGame) != MessageDialogResult.Affirmative) { return; } if (run.Deck.DeckStats.Games.Contains(SelectedGame)) { SelectedGame.DeleteGameFile(); run.Deck.DeckStats.Games.Remove(SelectedGame); Logger.WriteLine("Deleted game " + SelectedGame, "Runs.ButtonDeleteGame"); } if (HearthStatsAPI.IsLoggedIn && SelectedGame.HasHearthStatsId && await window.ShowCheckHearthStatsMatchDeletionDialog()) { HearthStatsManager.DeleteMatchesAsync(new List <GameStats> { SelectedGame }); } DeckStatsList.Save(); Core.MainWindow.DeckPickerList.UpdateDecks(); ArenaStats.Instance.UpdateArenaStats(); }
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(); }
private async void DeleteGames(DataGrid dataGrid, bool overall) { MetroWindow window; if (Config.Instance.StatsInWindow) { window = Core.Windows.StatsWindow; } else { window = Helper.MainWindow; } var count = dataGrid.SelectedItems.Count; if (count == 1) { var selectedGame = dataGrid.SelectedItem as GameStats; if (selectedGame == null) { return; } if (await window.ShowDeleteGameStatsMessage(selectedGame) != MessageDialogResult.Affirmative) { return; } if (!overall) { if (_deck.DeckStats.Games.Contains(selectedGame)) { selectedGame.DeleteGameFile(); _deck.DeckStats.Games.Remove(selectedGame); Logger.WriteLine("Deleted game " + selectedGame + "(overall=" + overall + ")", "DeckStatsControl"); DeckStatsList.Save(); } } else { var deck = DeckList.Instance.Decks.FirstOrDefault(d => d.DeckStats.Games.Contains(selectedGame)); if (deck != null) { if (deck.DeckStats.Games.Contains(selectedGame)) { selectedGame.DeleteGameFile(); deck.DeckStats.Games.Remove(selectedGame); Logger.WriteLine("Deleted game " + selectedGame + "(overall=" + overall + ")", "DeckStatsControl"); DefaultDeckStats.Save(); } } else { var deckstats = DefaultDeckStats.Instance.DeckStats.FirstOrDefault(ds => ds.Games.Contains(selectedGame)); if (deckstats != null) { selectedGame.DeleteGameFile(); deckstats.Games.Remove(selectedGame); Logger.WriteLine("Deleted game " + selectedGame + "(overall=" + overall + ")", "DeckStatsControl"); DefaultDeckStats.Save(); } } } if (HearthStatsAPI.IsLoggedIn && selectedGame.HasHearthStatsId && await Core.MainWindow.ShowCheckHearthStatsMatchDeletionDialog()) { HearthStatsManager.DeleteMatchesAsync(new List <GameStats> { selectedGame }); } //Core.MainWindow.DeckPickerList.Items.Refresh(); Core.MainWindow.DeckPickerList.UpdateDecks(); Refresh(); } else if (count > 1) { if (await window.ShowDeleteMultipleGameStatsMessage(count) != MessageDialogResult.Affirmative) { return; } var selectedGames = dataGrid.SelectedItems.Cast <GameStats>().Where(g => g != null).ToList(); foreach (var selectedGame in selectedGames) { if (!overall) { if (_deck.DeckStats.Games.Contains(selectedGame)) { selectedGame.DeleteGameFile(); _deck.DeckStats.Games.Remove(selectedGame); Logger.WriteLine("Deleted game " + selectedGame + "(overall=" + overall + ")", "DeckStatsControl"); } } else { var deck = DeckList.Instance.Decks.FirstOrDefault(d => d.DeckStats.Games.Contains(selectedGame)); if (deck != null) { if (deck.DeckStats.Games.Contains(selectedGame)) { selectedGame.DeleteGameFile(); deck.DeckStats.Games.Remove(selectedGame); Logger.WriteLine("Deleted game " + selectedGame + "(overall=" + overall + ")", "DeckStatsControl"); } } else { var deckstats = DefaultDeckStats.Instance.DeckStats.FirstOrDefault(ds => ds.Games.Contains(selectedGame)); if (deckstats != null) { selectedGame.DeleteGameFile(); deckstats.Games.Remove(selectedGame); Logger.WriteLine("Deleted game " + selectedGame + "(overall=" + overall + ")", "DeckStatsControl"); } } } } if (HearthStatsAPI.IsLoggedIn && selectedGames.Any(g => g.HasHearthStatsId) && await Core.MainWindow.ShowCheckHearthStatsMatchDeletionDialog()) { HearthStatsManager.DeleteMatchesAsync(selectedGames); } DeckStatsList.Save(); DefaultDeckStats.Save(); Logger.WriteLine("Deleted " + count + " games", "DeckStatsControl"); Core.MainWindow.DeckPickerList.UpdateDecks(); Refresh(); } }