public List <BasicSetCollectionInfo> Import() { var sets = SetCardsManager.CreateEmptyCollection(); try { var collection = Reflection.GetCollection(); var goldenCollection = collection.Where(x => x.Premium); var commonCollection = collection.Where(x => x.Premium == false); foreach (var set in sets) { foreach (var card in set.Cards) { var amountGolden = goldenCollection.Where(x => x.Id.Equals(card.CardId)).Select(x => x.Count).FirstOrDefault(); var amountNonGolden = commonCollection.Where(x => x.Id.Equals(card.CardId)).Select(x => x.Count).FirstOrDefault(); card.AmountNonGolden = Math.Min(amountNonGolden, card.MaxAmountInCollection); card.AmountGolden = Math.Min(amountGolden, card.MaxAmountInCollection); } } } catch (ImportingException) { Log.Error("COLLECTION TRACKER: import exception"); throw; } catch (Exception e) { Log.Error("COLLECTION TRACKER: Random exception when importing"); Log.Error(e); } return(sets); }
public async Task <List <BasicSetCollectionInfo> > Import(string importingSet) { var sets = SetCardsManager.CreateEmptyCollection(); if (!string.IsNullOrEmpty(importingSet)) { sets = sets.Where(s => s.SetName == importingSet).ToList(); } if (!sets.Any()) { return(sets); } try { HideHDTOverlay(); var collection = Reflection.GetCollection(); var goldenCollection = Reflection.GetCollection().Where(x => x.Premium == true); var commonCollection = Reflection.GetCollection().Where(x => x.Premium == false); foreach (var set in sets) { foreach (var card in set.Cards) { var amountGolden = goldenCollection.Where(x => x.Id.Equals(card.CardId)).Select(x => x.Count).FirstOrDefault(); var amountNonGolden = commonCollection.Where(x => x.Id.Equals(card.CardId)).Select(x => x.Count).FirstOrDefault(); card.AmountNonGolden = Math.Min(amountNonGolden, card.MaxAmountInCollection); card.AmountGolden = Math.Min(amountGolden, card.MaxAmountInCollection); } } } catch (ImportingException) { ShowHDTOverlay(); throw; } catch (Exception e) { ShowHDTOverlay(); throw new ImportingException("Unexpected exception occured during importing", e); } finally { ShowHDTOverlay(); } return(sets); }
public void SetActiveAccount(string accountName, bool forceReload = false) { if (accountName == ActiveAccount && !forceReload) { return; } var activeAccount = Accounts.FirstOrDefault(ac => ac.AccountName == accountName); if (activeAccount == null) { Log.WriteLine("Cannot set active account " + accountName + " because it does not exist", LogType.Debug, "CollectionTracker.PluginSettings"); return; } if (File.Exists(activeAccount.FileStoragePath)) { _activeAccountSetsInfo = SetCardsManager.LoadSetsInfo(activeAccount.FileStoragePath); } else { _activeAccountSetsInfo = SetCardsManager.CreateEmptyCollection(); } ActiveAccount = accountName; }
public void SaveCurrentAccount(List <BasicSetCollectionInfo> setsInfo) { var activeAccount = Accounts.First(acc => acc.AccountName == ActiveAccount); SetCardsManager.SaveCollection(setsInfo, activeAccount.FileStoragePath); }
public async Task <List <BasicSetCollectionInfo> > Import(TimeSpan delayBeforeImport, string importingSet) { var sets = SetCardsManager.CreateEmptyCollection(); if (!string.IsNullOrEmpty(importingSet)) { sets = sets.Where(s => s.SetName == importingSet).ToList(); } if (!sets.Any()) { return(sets); } try { HideHDTOverlay(); HearthstoneWindow = User32.GetHearthstoneWindow(); if (!User32.IsHearthstoneInForeground()) { //restore window and bring to foreground User32.ShowWindow(HearthstoneWindow, User32.SwRestore); User32.SetForegroundWindow(HearthstoneWindow); //wait it to actually be in foreground, else the rect might be wrong await Task.Delay(500); } if (!User32.IsHearthstoneInForeground()) { Logger.WriteLine("Can't find Hearthstone window.", LOGGER_CATEGORY); throw new ImportingException("Can't find Hearthstone window."); } Logger.WriteLine("Waiting for " + delayBeforeImport.TotalSeconds + " seconds before starting the collection import", LOGGER_CATEGORY); await Task.Delay(delayBeforeImport); var hsRect = User32.GetHearthstoneRect(false); WindowXRatioTo1920 = (double)hsRect.Width / 1920; WindowYRatioTo1080 = (double)hsRect.Height / 1080; var ratio = (4.0 / 3.0) / ((double)hsRect.Width / hsRect.Height); SearchBoxPosition = new Point((int)(GetXPos(Config.Instance.ExportSearchBoxX, hsRect.Width, ratio)), (int)(Config.Instance.ExportSearchBoxY * hsRect.Height)); var cardPosX = GetXPos(Config.Instance.ExportCard1X, hsRect.Width, ratio); var card2PosX = GetXPos(Config.Instance.ExportCard2X, hsRect.Width, ratio); var cardPosY = Config.Instance.ExportCardsY * hsRect.Height; foreach (var set in sets) { foreach (var card in set.Cards) { var amount = await GetCardsAmount(card.Card, cardPosX, card2PosX, cardPosY); card.AmountNonGolden = amount.Item1; card.AmountGolden = amount.Item2; if (NonGoldenFirst && card.AmountNonGolden < 2 && card.AmountGolden > 0) { int missing = 2 - card.AmountNonGolden; int transferAmount = Math.Min(card.AmountGolden, missing); card.AmountGolden -= transferAmount; card.AmountNonGolden += transferAmount; } } } } catch (ImportingException e) { ShowHDTOverlay(); throw; } catch (Exception e) { ShowHDTOverlay(); throw new ImportingException("Unexpected exception occured during importing", e); } finally { ShowHDTOverlay(); } return(sets); }