public void ImportMtgArenaCollection() { if (!_mtgArenaIntegration.MtgaInstallationFound) { MessageBox.Show("MTGArena installation was not detected.\r\n\r\nIf you have MTGA installed in custom location edit <MtgaIntegration> tag in etc\\Mtgdb.Gui.xml"); return; } var countById = MtgArenaFormatter.ImportCollection(_mtgArenaIntegration, _cardRepo); if (countById.Count == 0) { MessageBox.Show("Unable to read collection from MTGA installation.\r\n\r\n" + "Make sure you are not running MTGArena right now. Otherwise data files cannot be read.\r\n\r\n" + "See logs\\error.log for details."); return; } savePreviousCollection(); var deck = Deck.Create(countById, countById.Keys.ToList(), null, null, null, null); _collectionEditor.LoadCollection(deck, append: false); MessageBox.Show($"Imported collection of {countById.Values.Sum()} cards, {countById.Count} distinct."); void savePreviousCollection() { if (_uiConfigRepository.Config.CollectionBeforeImportMtga != null) { // we are already working with MTGA collection // no point in overwriting actual collection before import with MTGA collection return; } _uiConfigRepository.Config.CollectionBeforeImportMtga = _history.Current.Collection ?? new Dictionary <string, int>(Str.Comparer); _uiConfigRepository.Save(); updateFormStatus(); } }
public DeckSerializationSubsystem( CardRepository cardRepository, ForgeSetRepository forgeSetRepo) { MtgArenaFormatter = new MtgArenaFormatter(cardRepository); MtgoFormatter = new MtgoDeckFormatter(cardRepository); _formatters = new[] { new JsonDeckFormatter(), new TcgCsvDeckFormatter(cardRepository), new ForgeDeckFormatter(cardRepository, forgeSetRepo), new MagarenaDeckFormatter(cardRepository), new DeckedBuilderDeckFormatter(cardRepository), new XMageDeckFormatter(cardRepository), MtgArenaFormatter, // must be after MtgArenaFormatter for correct format resolution MtgoFormatter }; _loadFormatters = _formatters.Where(_ => _.SupportsImport && _.SupportsFile).ToArray(); _saveFormatters = _formatters.Where(_ => _.SupportsExport && _.SupportsFile).ToArray(); ImportedFilePatterns = _loadFormatters .Where(_ => _.SupportsImport) .Select(f => f.FileNamePattern) .Distinct() .ToList(); _loadFilter = string.Join(@"|", Sequence.From($"Any {{type}}|{string.Join(@";", ImportedFilePatterns)}").Concat( _loadFormatters.Select(f => $"{f.Description}|{f.FileNamePattern}"))); _saveFilter = string.Join(@"|", _saveFormatters.Select(f => $"{f.Description}|{f.FileNamePattern}")); AppDir.Save.CreateDirectory(); }