internal static void MoveGamesToOtherDeckWithoutConfirmation(Deck targetDeck, SerializableVersion targetVersion, params GameStats[] games) { if(games == null) return; foreach(var game in games) { var defaultDeck = DefaultDeckStats.Instance.DeckStats.FirstOrDefault(ds => ds.Games.Contains(game)); if(defaultDeck != null) { defaultDeck.Games.Remove(game); DefaultDeckStats.Save(); } else { var deck = DeckList.Instance.Decks.FirstOrDefault(d => game.DeckId == d.DeckId); deck?.DeckStats.Games.Remove(game); } game.PlayerDeckVersion = targetVersion; game.HearthStatsDeckVersionId = targetDeck.GetVersion(targetVersion).HearthStatsDeckVersionId; game.DeckId = targetDeck.DeckId; game.DeckName = targetDeck.Name; targetDeck.DeckStats.Games.Add(game); if(HearthStatsAPI.IsLoggedIn && Config.Instance.HearthStatsAutoUploadNewGames) HearthStatsManager.MoveMatchAsync(game, targetDeck, background: true).Forget(); } DeckStatsList.Save(); DeckList.Save(); Core.MainWindow.DeckPickerList.UpdateDecks(); }
public static async Task<PostResult> UploadDeckAsync(Deck deck, bool saveFilesAfter = true, bool background = false) { Log.Info("trying to upload deck " + deck); if(!HearthStatsAPI.IsLoggedIn) { Log.Error("not logged in"); return PostResult.Failed; } if(background) AddBackgroundActivity(); var first = deck.GetVersion(1, 0); if(!first.IsArenaDeck && first.HasHearthStatsId && !deck.HasHearthStatsId && !deck.HearthStatsIdsAlreadyReset) { first.HearthStatsId = first.HearthStatsIdForUploading; await HearthStatsAPI.DeleteDeckAsync(first); await Task.Delay(1000); //reset everything foreach(var version in deck.VersionsIncludingSelf.Select(deck.GetVersion)) { version.ResetHearthstatsIds(); foreach(var game in version.DeckStats.Games) { game.HearthStatsDeckId = null; game.HearthStatsDeckVersionId = null; game.HearthStatsId = null; } } } var result = await HearthStatsAPI.PostDeckAsync(first, deck); if(!result.Success && result.Retry) { await Task.Delay(RetryDelay); Log.Info("try #2 to upload deck " + deck); result = await HearthStatsAPI.PostDeckAsync(first, deck); } if(result.Success) { var versions = deck.VersionsIncludingSelf.Where(v => v != new SerializableVersion(1, 0)) .Select(deck.GetVersion) .Where(d => d != null && !d.HasHearthStatsDeckVersionId) .ToList(); if(versions.Any()) { foreach(var v in versions) { await Task.Delay(VersionDelay); await UploadVersionAsync(v, first.HearthStatsIdForUploading, false); } deck.HearthStatsId = first.HearthStatsId; first.HearthStatsId = ""; first.HearthStatsIdForUploading = deck.HearthStatsId; } if(saveFilesAfter) DeckList.Save(); if(background) RemoveBackgroundActivity(); Log.Info("success uploading deck " + deck); return PostResult.WasSuccess; } if(background) RemoveBackgroundActivity(); return PostResult.Failed; }