Search in sources :

Example 11 with TFile

use of net.java.truevfs.access.TFile in project mage by magefree.

the class ImageCache method getCardbackImage.

public static BufferedImage getCardbackImage() {
    BufferedImage image = ImageCache.loadImage(new TFile(CardImageUtils.buildImagePathToDefault(DirectLinksForDownload.cardbackFilename)));
    image = getRoundCorner(image);
    return image;
}
Also used : TFile(net.java.truevfs.access.TFile) BufferedImage(java.awt.image.BufferedImage)

Example 12 with TFile

use of net.java.truevfs.access.TFile in project mage by magefree.

the class CardImageUtils method generateTokenImagePath.

/**
 * @param card
 * @return String if image exists, else null
 */
public static String generateTokenImagePath(CardDownloadData card) {
    if (card.isToken()) {
        String filePath = getTokenImagePath(card);
        if (pathCache.containsKey(card)) {
            if (filePath.equals(pathCache.get(card))) {
                return pathCache.get(card);
            }
        }
        TFile file = new TFile(filePath);
        if (!file.exists() && card.getTokenSetCode() != null) {
            filePath = searchForCardImage(card);
            file = new TFile(filePath);
        }
        if (file.exists()) {
            pathCache.put(card, filePath);
            return filePath;
        }
    // log.warn("Token image file not found. Set: " + card.getSet() + " Token Set Code: " + card.getTokenSetCode() + " Name: " + card.getName() + " File path: " + getTokenImagePath(card));
    } else {
        LOGGER.warn("Trying to get token path for non token card. Set: " + card.getSet() + " Set Code: " + card.getTokenSetCode() + " Name: " + card.getName());
    }
    return null;
}
Also used : TFile(net.java.truevfs.access.TFile)

Example 13 with TFile

use of net.java.truevfs.access.TFile in project mage by magefree.

the class LoadMissingCardDataNew method prepareMissingCards.

private static List<CardDownloadData> prepareMissingCards(List<CardInfo> allCards, boolean redownloadMode) {
    // get filter for Standard Type 2 cards
    Set<String> type2SetsFilter = new HashSet<>();
    List<String> constructedFormats = ConstructedFormats.getSetsByFormat(ConstructedFormats.STANDARD);
    if (constructedFormats != null && !constructedFormats.isEmpty()) {
        type2SetsFilter.addAll(constructedFormats);
    } else {
        logger.warn("No formats defined. Try connecting to a server first!");
    }
    // prepare checking list
    List<CardDownloadData> allCardsUrls = Collections.synchronizedList(new ArrayList<>());
    try {
        allCards.parallelStream().forEach(card -> {
            if (!card.getCardNumber().isEmpty() && !"0".equals(card.getCardNumber()) && !card.getSetCode().isEmpty()) {
                String cardName = card.getName();
                boolean isType2 = type2SetsFilter.contains(card.getSetCode());
                CardDownloadData url = new CardDownloadData(cardName, card.getSetCode(), card.getCardNumber(), card.usesVariousArt(), 0, "", "", false, card.isDoubleFaced(), card.isNightCard());
                // variations must have diff file names with additional postfix
                if (url.getUsesVariousArt()) {
                    url.setDownloadName(createDownloadName(card));
                }
                url.setFlipCard(card.isFlipCard());
                url.setSplitCard(card.isSplitCard());
                url.setType2(isType2);
                // main side
                allCardsUrls.add(url);
                // second side (xmage's set doesn't have info about it, so generate it here)
                if (card.isDoubleFaced()) {
                    if (card.getSecondSideName() == null || card.getSecondSideName().trim().isEmpty()) {
                        throw new IllegalStateException("Second side card can't have empty name.");
                    }
                    CardInfo secondSideCard = CardRepository.instance.findCardWPreferredSet(card.getSecondSideName(), card.getSetCode(), false);
                    if (secondSideCard == null) {
                        throw new IllegalStateException("Can''t find second side card in database: " + card.getSecondSideName());
                    }
                    url = new CardDownloadData(card.getSecondSideName(), card.getSetCode(), secondSideCard.getCardNumber(), card.usesVariousArt(), 0, "", "", false, card.isDoubleFaced(), true);
                    url.setType2(isType2);
                    allCardsUrls.add(url);
                }
                if (card.isFlipCard()) {
                    if (card.getFlipCardName() == null || card.getFlipCardName().trim().isEmpty()) {
                        throw new IllegalStateException("Flipped card can't have empty name.");
                    }
                    CardDownloadData cardDownloadData = new CardDownloadData(card.getFlipCardName(), card.getSetCode(), card.getCardNumber(), card.usesVariousArt(), 0, "", "", false, card.isDoubleFaced(), card.isNightCard());
                    cardDownloadData.setFlipCard(true);
                    cardDownloadData.setFlippedSide(true);
                    cardDownloadData.setType2(isType2);
                    allCardsUrls.add(cardDownloadData);
                }
                if (card.isModalDoubleFacesCard()) {
                    if (card.getModalDoubleFacesSecondSideName() == null || card.getModalDoubleFacesSecondSideName().trim().isEmpty()) {
                        throw new IllegalStateException("MDF card can't have empty name.");
                    }
                    CardDownloadData cardDownloadData = new CardDownloadData(card.getModalDoubleFacesSecondSideName(), card.getSetCode(), card.getCardNumber(), card.usesVariousArt(), 0, "", "", false, true, true);
                    cardDownloadData.setType2(isType2);
                    allCardsUrls.add(cardDownloadData);
                }
            } else if (card.getCardNumber().isEmpty() || "0".equals(card.getCardNumber())) {
                logger.error("Card has no collector ID and won't be sent to client: " + card.getName());
            } else if (card.getSetCode().isEmpty()) {
                logger.error("Card has no set name and won't be sent to client:" + card.getName());
            } else {
                logger.info("Card was not selected: " + card.getName());
            }
        });
        allCardsUrls.addAll(getTokenCardUrls());
    } catch (Exception e) {
        logger.error(e);
    }
    // find missing files
    List<CardDownloadData> cardsToDownload = Collections.synchronizedList(new ArrayList<>());
    allCardsUrls.parallelStream().forEach(card -> {
        if (redownloadMode) {
            // need all cards
            cardsToDownload.add(card);
        } else {
            // need missing cards
            File file = new TFile(CardImageUtils.buildImagePathToCard(card));
            if (!file.exists()) {
                cardsToDownload.add(card);
            }
        }
    });
    return Collections.synchronizedList(new ArrayList<>(cardsToDownload));
}
Also used : CardInfo(mage.cards.repository.CardInfo) FsSyncException(net.java.truevfs.kernel.spec.FsSyncException) AccessDeniedException(java.nio.file.AccessDeniedException) TFile(net.java.truevfs.access.TFile) TFile(net.java.truevfs.access.TFile)

Example 14 with TFile

use of net.java.truevfs.access.TFile in project mage by magefree.

the class LoadMissingCardDataNew method update.

private void update(int lastCardIndex, int needDownloadCount) {
    this.cardIndex = lastCardIndex;
    if (cardIndex < needDownloadCount) {
        // downloading
        float mb = ((needDownloadCount - lastCardIndex) * selectedSource.getAverageSize()) / 1024;
        updateProgressMessage(String.format("%d of %d image downloads finished! Please wait! [%.1f Mb]", lastCardIndex, needDownloadCount, mb));
    } else {
        // finished
        List<CardDownloadData> downloadedCards = Collections.synchronizedList(new ArrayList<>());
        DownloadPicturesService.this.cardsMissing.parallelStream().forEach(cardDownloadData -> {
            TFile file = new TFile(CardImageUtils.buildImagePathToCard(cardDownloadData));
            if (file.exists()) {
                downloadedCards.add(cardDownloadData);
            }
        });
        // remove all downloaded cards, missing must be remains
        this.cardsDownloadQueue.removeAll(downloadedCards);
        this.cardsMissing.removeAll(downloadedCards);
        if (this.cardsDownloadQueue.isEmpty()) {
            // stop download
            updateProgressMessage("0 images remaining. Please close.");
        } else {
        // try download again
        }
        enableDialogButtons();
    }
}
Also used : TFile(net.java.truevfs.access.TFile)

Aggregations

TFile (net.java.truevfs.access.TFile)14 BufferedImage (java.awt.image.BufferedImage)4 IOException (java.io.IOException)2 Test (org.junit.Test)2 BufferedReader (java.io.BufferedReader)1 Writer (java.io.Writer)1 AccessDeniedException (java.nio.file.AccessDeniedException)1 Matcher (java.util.regex.Matcher)1 CardInfo (mage.cards.repository.CardInfo)1 TFileOutputStream (net.java.truevfs.access.TFileOutputStream)1 TFileReader (net.java.truevfs.access.TFileReader)1 TFileWriter (net.java.truevfs.access.TFileWriter)1 FsSyncException (net.java.truevfs.kernel.spec.FsSyncException)1 CardDownloadData (org.mage.plugins.card.images.CardDownloadData)1