mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 13:02:06 -08:00
* Fixed a problem that Emblems created by permanents where its owner left the game caused errors in clients. Some handling cganges of emblems.
This commit is contained in:
parent
81caed134f
commit
8075ea2e50
56 changed files with 894 additions and 850 deletions
|
|
@ -594,7 +594,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
missingCards = CardRepository.instance.findCards(new CardCriteria());
|
||||
LOGGER.info("Card pool load time: " + ((System.currentTimeMillis() - beforeCall) / 1000 + " seconds"));
|
||||
beforeCall = System.currentTimeMillis();
|
||||
if (DownloadPictures.checkForNewCards(missingCards)) {
|
||||
if (DownloadPictures.checkForMissingCardImages(missingCards)) {
|
||||
LOGGER.info("Card images checking time: " + ((System.currentTimeMillis() - beforeCall) / 1000 + " seconds"));
|
||||
UserRequestMessage message = new UserRequestMessage("New images available", "Card images are missing (" + missingCards.size() + "). Do you want to download the images?"
|
||||
+ "<br><br><i>You can deactivate the image download check on application start in the preferences.</i>");
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ import java.awt.event.MouseAdapter;
|
|||
import java.awt.event.MouseEvent;
|
||||
import java.util.*;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
|
|
@ -55,6 +54,7 @@ import mage.cards.Sets;
|
|||
import mage.cards.repository.CardCriteria;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.CardRepository;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.cards.*;
|
||||
import mage.client.constants.Constants.SortBy;
|
||||
import mage.client.deckeditor.table.TableModel;
|
||||
|
|
@ -960,7 +960,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
|
|||
filterCards();
|
||||
}
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "An expansion set must be selected to be able to generate a booster.");
|
||||
MageFrame.getInstance().showMessage("An expansion set must be selected to be able to generate a booster.");
|
||||
}
|
||||
}//GEN-LAST:event_btnBoosterActionPerformed
|
||||
|
||||
|
|
@ -993,7 +993,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
|
|||
if (currentView.cardsSize() > CardGrid.MAX_IMAGES) {
|
||||
jToggleCardView.setSelected(false);
|
||||
jToggleListView.setSelected(true);
|
||||
JOptionPane.showMessageDialog(this, new StringBuilder("The card view can't be used for more than ").append(CardGrid.MAX_IMAGES).append(" cards.").toString());
|
||||
MageFrame.getInstance().showMessage("The card view can't be used for more than " + CardGrid.MAX_IMAGES + " cards.");
|
||||
} else {
|
||||
if (!(currentView instanceof CardGrid)) {
|
||||
toggleViewMode();
|
||||
|
|
|
|||
|
|
@ -749,9 +749,9 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
if (change) {
|
||||
handCardsOfOpponentAvailable = !handCardsOfOpponentAvailable;
|
||||
if (handCardsOfOpponentAvailable) {
|
||||
JOptionPane.showMessageDialog(null, "You control other player's turn. \nUse \"Switch Hand\" button to switch between cards in different hands.");
|
||||
MageFrame.getInstance().showMessage("You control other player's turn. \nUse \"Switch Hand\" button to switch between cards in different hands.");
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "You lost control on other player's turn.");
|
||||
MageFrame.getInstance().showMessage("You lost control on other player's turn.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -49,6 +49,10 @@ public class TokensMtgImageSource implements CardImageSource {
|
|||
|
||||
private static CardImageSource instance = new TokensMtgImageSource();
|
||||
|
||||
private List<TokenData> tokensData;
|
||||
|
||||
private final Object tokensDataSync = new Object();
|
||||
|
||||
public static CardImageSource getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new TokensMtgImageSource();
|
||||
|
|
@ -82,26 +86,27 @@ public class TokensMtgImageSource implements CardImageSource {
|
|||
}
|
||||
|
||||
private static final String[] EMBLEMS = {
|
||||
"Ajani",
|
||||
"Chandra",
|
||||
"Dack",
|
||||
"Daretti",
|
||||
"Domri",
|
||||
"Elspeth",
|
||||
"Garruk",
|
||||
"Gideon",
|
||||
"Jace",
|
||||
"Kiora",
|
||||
"Koth",
|
||||
"Liliana",
|
||||
"Narset",
|
||||
"Nixilis",
|
||||
"Sarkhan",
|
||||
"Sorin",
|
||||
"Tamiyo",
|
||||
"Teferi",
|
||||
"Venser",
|
||||
};
|
||||
"Ajani",
|
||||
"Arlinn",
|
||||
"Chandra",
|
||||
"Dack",
|
||||
"Daretti",
|
||||
"Dovin",
|
||||
"Domri",
|
||||
"Elspeth",
|
||||
"Garruk",
|
||||
"Gideon",
|
||||
"Jace",
|
||||
"Kiora",
|
||||
"Koth",
|
||||
"Liliana",
|
||||
"Narset",
|
||||
"Nixilis",
|
||||
"Sarkhan",
|
||||
"Sorin",
|
||||
"Tamiyo",
|
||||
"Teferi",
|
||||
"Venser",};
|
||||
|
||||
private static final Map<String, String> SET_NAMES_REPLACEMENT = new HashMap<String, String>() {
|
||||
{
|
||||
|
|
@ -119,7 +124,7 @@ public class TokensMtgImageSource implements CardImageSource {
|
|||
// handle emblems
|
||||
if (name.toLowerCase().contains("emblem")) {
|
||||
for (String emblem : EMBLEMS) {
|
||||
if (name.toLowerCase().contains(emblem.toLowerCase())){
|
||||
if (name.toLowerCase().contains(emblem.toLowerCase())) {
|
||||
name = emblem + " Emblem";
|
||||
break;
|
||||
}
|
||||
|
|
@ -135,23 +140,23 @@ public class TokensMtgImageSource implements CardImageSource {
|
|||
// e.g. http://tokens.mtg.onl/tokens/ORI_010-Thopter.jpg -- token number 010
|
||||
// We don't know these numbers, but we can take them from a file
|
||||
// with tokens information that can be downloaded from the site.
|
||||
List<TokenData> tokensData = getTokensData();
|
||||
List<TokenData> newTokensData = getTokensData();
|
||||
|
||||
if (tokensData.isEmpty()) {
|
||||
if (newTokensData.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<TokenData> matchedTokens = new ArrayList<TokenData>();
|
||||
for (TokenData token : tokensData) {
|
||||
List<TokenData> matchedTokens = new ArrayList<>();
|
||||
for (TokenData token : newTokensData) {
|
||||
if (name.equalsIgnoreCase(token.getName()) && set.equalsIgnoreCase(token.getExpansionSetCode())) {
|
||||
matchedTokens.add(token);
|
||||
}
|
||||
}
|
||||
|
||||
if (matchedTokens.isEmpty()) {
|
||||
logger.info("Could not find data for token " + name + ", set " + set + ".");
|
||||
return null;
|
||||
}
|
||||
//
|
||||
// if (matchedTokens.isEmpty()) {
|
||||
// logger.info("Could not find data for token " + name + ", set " + set + ".");
|
||||
// return null;
|
||||
// }
|
||||
|
||||
TokenData tokenData;
|
||||
if (type == 0) {
|
||||
|
|
@ -168,72 +173,66 @@ public class TokensMtgImageSource implements CardImageSource {
|
|||
}
|
||||
|
||||
String url = "http://tokens.mtg.onl/tokens/" + tokenData.getExpansionSetCode().trim() + "_"
|
||||
+ tokenData.getNumber().trim() + "-" + tokenData.getName().trim()+ ".jpg";
|
||||
+ tokenData.getNumber().trim() + "-" + tokenData.getName().trim() + ".jpg";
|
||||
url = url.replace(' ', '-');
|
||||
return url;
|
||||
}
|
||||
|
||||
private List<TokenData> tokensData;
|
||||
|
||||
private final Object tokensDataSync = new Object();
|
||||
|
||||
private List<TokenData> getTokensData() throws IOException {
|
||||
if (tokensData == null) {
|
||||
synchronized (tokensDataSync) {
|
||||
if (tokensData == null) {
|
||||
tokensData = new ArrayList<TokenData>();
|
||||
synchronized (tokensDataSync) {
|
||||
if (tokensData == null) {
|
||||
tokensData = new ArrayList<>();
|
||||
|
||||
// get tokens data from resource file
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = this.getClass().getResourceAsStream("/tokens-mtg-onl-list.csv");
|
||||
List<TokenData> fileTokensData = parseTokensData(inputStream);
|
||||
tokensData.addAll(fileTokensData);
|
||||
} catch (Exception exception) {
|
||||
logger.warn("Failed to get tokens description from resource file tokens-mtg-onl-list.csv", exception);
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (Exception e) {
|
||||
logger.error("Input stream close failed:", e);
|
||||
// get tokens data from resource file
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = this.getClass().getResourceAsStream("/tokens-mtg-onl-list.csv");
|
||||
List<TokenData> fileTokensData = parseTokensData(inputStream);
|
||||
tokensData.addAll(fileTokensData);
|
||||
} catch (Exception exception) {
|
||||
logger.warn("Failed to get tokens description from resource file tokens-mtg-onl-list.csv", exception);
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (Exception e) {
|
||||
logger.error("Input stream close failed:", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// description on site may contain new information
|
||||
// try to add it
|
||||
try {
|
||||
URL url = new URL("http://tokens.mtg.onl/data/SetsWithTokens.csv");
|
||||
inputStream = url.openStream();
|
||||
List<TokenData> siteTokensData = parseTokensData(inputStream);
|
||||
|
||||
List<TokenData> newTokensData = new ArrayList<>();
|
||||
for (TokenData siteData : siteTokensData) {
|
||||
boolean isNew = true;
|
||||
for (TokenData fileData : tokensData) {
|
||||
if (siteData.getName().equalsIgnoreCase(fileData.getName())
|
||||
&& siteData.getNumber().equalsIgnoreCase(fileData.getNumber())
|
||||
&& siteData.getExpansionSetCode().equalsIgnoreCase(fileData.getExpansionSetCode())) {
|
||||
isNew = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isNew) {
|
||||
newTokensData.add(siteData);
|
||||
}
|
||||
}
|
||||
|
||||
// description on site may contain new information
|
||||
// try to add it
|
||||
try {
|
||||
URL url = new URL("http://tokens.mtg.onl/data/SetsWithTokens.csv");
|
||||
inputStream = url.openStream();
|
||||
List<TokenData> siteTokensData = parseTokensData(inputStream);
|
||||
|
||||
List<TokenData> newTokensData = new ArrayList<TokenData>();
|
||||
for (TokenData siteData : siteTokensData) {
|
||||
boolean isNew = true;
|
||||
for (TokenData fileData : tokensData) {
|
||||
if (siteData.getName().equalsIgnoreCase(fileData.getName())
|
||||
&& siteData.getNumber().equalsIgnoreCase(fileData.getNumber())
|
||||
&& siteData.getExpansionSetCode().equalsIgnoreCase(fileData.getExpansionSetCode())) {
|
||||
isNew = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isNew) {
|
||||
newTokensData.add(siteData);
|
||||
}
|
||||
}
|
||||
|
||||
tokensData.addAll(newTokensData);
|
||||
} catch (Exception exception) {
|
||||
logger.warn("Failed to get tokens description from tokens.mtg.onl", exception);
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (Exception e) {
|
||||
logger.error("Input stream close failed:", e);
|
||||
}
|
||||
tokensData.addAll(newTokensData);
|
||||
} catch (Exception exception) {
|
||||
logger.warn("Failed to get tokens description from tokens.mtg.onl", exception);
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (Exception e) {
|
||||
logger.error("Input stream close failed:", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -244,7 +243,7 @@ public class TokensMtgImageSource implements CardImageSource {
|
|||
}
|
||||
|
||||
private List<TokenData> parseTokensData(InputStream inputStream) throws IOException {
|
||||
List<TokenData> tokensData = new ArrayList<TokenData>();
|
||||
List<TokenData> newTokensData = new ArrayList<>();
|
||||
|
||||
InputStreamReader inputReader = null;
|
||||
BufferedReader reader = null;
|
||||
|
|
@ -266,8 +265,7 @@ public class TokensMtgImageSource implements CardImageSource {
|
|||
if (state == 2) {
|
||||
state = 0;
|
||||
}
|
||||
} else {
|
||||
if (state == 0) {
|
||||
} else if (state == 0) {
|
||||
set = line.substring(0, 3);
|
||||
state = 1;
|
||||
} else {
|
||||
|
|
@ -279,8 +277,7 @@ public class TokensMtgImageSource implements CardImageSource {
|
|||
String name = split[0].replace('‚', ',');
|
||||
String number = split[1];
|
||||
TokenData token = new TokenData(name, number, set);
|
||||
tokensData.add(token);
|
||||
}
|
||||
newTokensData.add(token);
|
||||
}
|
||||
|
||||
line = reader.readLine();
|
||||
|
|
@ -302,7 +299,7 @@ public class TokensMtgImageSource implements CardImageSource {
|
|||
}
|
||||
}
|
||||
|
||||
return tokensData;
|
||||
return newTokensData;
|
||||
}
|
||||
|
||||
final class TokenData {
|
||||
|
|
@ -334,12 +331,12 @@ public class TokensMtgImageSource implements CardImageSource {
|
|||
public Integer getTotalImages() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Boolean isTokenSource() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doPause(String httpImageUrl) {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ public class CardDownloadData {
|
|||
|
||||
private String name;
|
||||
private String downloadName;
|
||||
private String fileName = "";
|
||||
private String set;
|
||||
private String tokenSetCode;
|
||||
private String tokenDescriptor;
|
||||
|
|
@ -32,6 +33,11 @@ public class CardDownloadData {
|
|||
this(name, set, collectorId, usesVariousArt, type, tokenSetCode, tokenDescriptor, token, false, false);
|
||||
}
|
||||
|
||||
public CardDownloadData(String name, String set, String collectorId, boolean usesVariousArt, Integer type, String tokenSetCode, String tokenDescriptor, boolean token, String fileName) {
|
||||
this(name, set, collectorId, usesVariousArt, type, tokenSetCode, tokenDescriptor, token, false, false);
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public CardDownloadData(String name, String set, String collectorId, boolean usesVariousArt, Integer type, String tokenSetCode, String tokenDescriptor, boolean token, boolean twoFacedCard, boolean secondSide) {
|
||||
this.name = name;
|
||||
this.set = set;
|
||||
|
|
@ -43,7 +49,7 @@ public class CardDownloadData {
|
|||
this.secondSide = secondSide;
|
||||
this.tokenSetCode = tokenSetCode;
|
||||
this.tokenDescriptor = tokenDescriptor;
|
||||
|
||||
|
||||
if (this.tokenDescriptor == null || this.tokenDescriptor.equalsIgnoreCase("")) {
|
||||
this.tokenDescriptor = lastDitchTokenDescriptor();
|
||||
}
|
||||
|
|
@ -60,6 +66,7 @@ public class CardDownloadData {
|
|||
this.usesVariousArt = card.usesVariousArt;
|
||||
this.tokenSetCode = card.tokenSetCode;
|
||||
this.tokenDescriptor = card.tokenDescriptor;
|
||||
this.fileName = card.fileName;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -118,6 +125,14 @@ public class CardDownloadData {
|
|||
return name;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
|
@ -125,7 +140,7 @@ public class CardDownloadData {
|
|||
public String getSet() {
|
||||
return set;
|
||||
}
|
||||
|
||||
|
||||
public void setSet(String set) {
|
||||
this.set = set;
|
||||
}
|
||||
|
|
@ -144,15 +159,15 @@ public class CardDownloadData {
|
|||
|
||||
public void setTokenDescriptor(String tokenDescriptor) {
|
||||
this.tokenDescriptor = tokenDescriptor;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String lastDitchTokenDescriptor() {
|
||||
String name = this.name.replaceAll("[^a-zA-Z0-9]", "");
|
||||
String descriptor = name + "....";
|
||||
String tmpName = this.name.replaceAll("[^a-zA-Z0-9]", "");
|
||||
String descriptor = tmpName + "....";
|
||||
descriptor = descriptor.toUpperCase();
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isToken() {
|
||||
return token;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,11 +57,11 @@ import org.mage.plugins.card.dl.sources.AltMtgOnlTokensImageSource;
|
|||
import org.mage.plugins.card.dl.sources.CardImageSource;
|
||||
import org.mage.plugins.card.dl.sources.GrabbagImageSource;
|
||||
import org.mage.plugins.card.dl.sources.MagicCardsImageSource;
|
||||
import org.mage.plugins.card.dl.sources.MagidexImageSource;
|
||||
import org.mage.plugins.card.dl.sources.MtgOnlTokensImageSource;
|
||||
import org.mage.plugins.card.dl.sources.MythicspoilerComSource;
|
||||
import org.mage.plugins.card.dl.sources.TokensMtgImageSource;
|
||||
import org.mage.plugins.card.dl.sources.WizardCardsImageSource;
|
||||
import org.mage.plugins.card.dl.sources.MagidexImageSource;
|
||||
import org.mage.plugins.card.properties.SettingsManager;
|
||||
import org.mage.plugins.card.utils.CardImageUtils;
|
||||
|
||||
|
|
@ -235,7 +235,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
dlg = new JOptionPane(p0, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, options, options[1]);
|
||||
}
|
||||
|
||||
public static boolean checkForNewCards(List<CardInfo> allCards) {
|
||||
public static boolean checkForMissingCardImages(List<CardInfo> allCards) {
|
||||
AtomicBoolean missedCardTFiles = new AtomicBoolean();
|
||||
allCards.parallelStream().forEach(card -> {
|
||||
if (!missedCardTFiles.get()) {
|
||||
|
|
@ -279,7 +279,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
private void updateProgressText(int cardCount) {
|
||||
float mb = (cardCount * cardImageSource.getAverageSize()) / 1024;
|
||||
bar.setString(String.format(cardIndex == cardCount ? "%d of %d cards finished! Please close!"
|
||||
: "%d of %d cards finished! Please wait! [%.1f Mb]", 0, cardCount, mb));
|
||||
: "%d of %d cards finished! Please wait! [%.1f Mb]", 0, cardCount, mb));
|
||||
}
|
||||
|
||||
private static String createDownloadName(CardInfo card) {
|
||||
|
|
@ -309,57 +309,57 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
}
|
||||
|
||||
int numberCardImages = allCards.size();
|
||||
|
||||
int numberWithoutTokens = 0;
|
||||
try {
|
||||
offlineMode = true;
|
||||
allCards.parallelStream().forEach(card -> {
|
||||
if (!card.getCardNumber().isEmpty() && !"0".equals(card.getCardNumber()) && !card.getSetCode().isEmpty()
|
||||
&& !ignoreUrls.contains(card.getSetCode())) {
|
||||
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());
|
||||
if (url.getUsesVariousArt()) {
|
||||
url.setDownloadName(createDownloadName(card));
|
||||
}
|
||||
allCards.parallelStream().forEach(card -> {
|
||||
if (!card.getCardNumber().isEmpty() && !"0".equals(card.getCardNumber()) && !card.getSetCode().isEmpty()
|
||||
&& !ignoreUrls.contains(card.getSetCode())) {
|
||||
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());
|
||||
if (url.getUsesVariousArt()) {
|
||||
url.setDownloadName(createDownloadName(card));
|
||||
}
|
||||
|
||||
url.setFlipCard(card.isFlipCard());
|
||||
url.setSplitCard(card.isSplitCard());
|
||||
url.setType2(isType2);
|
||||
url.setFlipCard(card.isFlipCard());
|
||||
url.setSplitCard(card.isSplitCard());
|
||||
url.setType2(isType2);
|
||||
|
||||
allCardsUrls.add(url);
|
||||
if (card.isDoubleFaced()) {
|
||||
if (card.getSecondSideName() == null || card.getSecondSideName().trim().isEmpty()) {
|
||||
throw new IllegalStateException("Second side card can't have empty name.");
|
||||
}
|
||||
url = new CardDownloadData(card.getSecondSideName(), card.getSetCode(), card.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.");
|
||||
}
|
||||
url = new CardDownloadData(card.getFlipCardName(), card.getSetCode(), card.getCardNumber(), card.usesVariousArt(), 0, "", "", false, card.isDoubleFaced(), card.isNightCard());
|
||||
url.setFlipCard(true);
|
||||
url.setFlippedSide(true);
|
||||
url.setType2(isType2);
|
||||
allCardsUrls.add(url);
|
||||
}
|
||||
} else if (card.getCardNumber().isEmpty() || "0".equals(card.getCardNumber())) {
|
||||
System.err.println("There was a critical error!");
|
||||
logger.error("Card has no collector ID and won't be sent to client: " + card);
|
||||
} else if (card.getSetCode().isEmpty()) {
|
||||
System.err.println("There was a critical error!");
|
||||
logger.error("Card has no set name and won't be sent to client:" + card);
|
||||
}
|
||||
});
|
||||
allCardsUrls.add(url);
|
||||
if (card.isDoubleFaced()) {
|
||||
if (card.getSecondSideName() == null || card.getSecondSideName().trim().isEmpty()) {
|
||||
throw new IllegalStateException("Second side card can't have empty name.");
|
||||
}
|
||||
url = new CardDownloadData(card.getSecondSideName(), card.getSetCode(), card.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.");
|
||||
}
|
||||
url = new CardDownloadData(card.getFlipCardName(), card.getSetCode(), card.getCardNumber(), card.usesVariousArt(), 0, "", "", false, card.isDoubleFaced(), card.isNightCard());
|
||||
url.setFlipCard(true);
|
||||
url.setFlippedSide(true);
|
||||
url.setType2(isType2);
|
||||
allCardsUrls.add(url);
|
||||
}
|
||||
} else if (card.getCardNumber().isEmpty() || "0".equals(card.getCardNumber())) {
|
||||
System.err.println("There was a critical error!");
|
||||
logger.error("Card has no collector ID and won't be sent to client: " + card);
|
||||
} else if (card.getSetCode().isEmpty()) {
|
||||
System.err.println("There was a critical error!");
|
||||
logger.error("Card has no set name and won't be sent to client:" + card);
|
||||
}
|
||||
});
|
||||
numberWithoutTokens = allCards.size();
|
||||
allCardsUrls.addAll(getTokenCardUrls());
|
||||
} catch (Exception e) {
|
||||
logger.error(e);
|
||||
}
|
||||
|
||||
int numberTokenImages = allCardsUrls.size() - numberCardImages;
|
||||
|
||||
int numberAllTokenImages = allCardsUrls.size() - numberWithoutTokens;
|
||||
|
||||
/**
|
||||
* check to see which cards we already have
|
||||
|
|
@ -372,21 +372,16 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
}
|
||||
});
|
||||
|
||||
logger.info("Check download images (total cards: " + numberCardImages + ", total tokens: " + numberTokenImages + ") => Missing images: " + cardsToDownload.size());
|
||||
if (logger.isDebugEnabled()) {
|
||||
for (CardDownloadData card : cardsToDownload) {
|
||||
if (card.isToken()) {
|
||||
logger.debug("Card to download: " + card.getName() + " (Token) ");
|
||||
} else {
|
||||
try {
|
||||
logger.debug("Card to download: " + card.getName() + " (" + card.getSet() + ")");
|
||||
} catch (Exception e) {
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
int tokenImages = 0;
|
||||
for (CardDownloadData card : cardsToDownload) {
|
||||
logger.debug((card.isToken() ? "Token" : "Card") + " image to download: " + card.getName() + " (" + card.getSet() + ")");
|
||||
if (card.isToken()) {
|
||||
tokenImages++;
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("Check download images (total card images: " + numberCardImages + ", total token images: " + numberAllTokenImages + ")");
|
||||
logger.info(" => Missing card images: " + (cardsToDownload.size() - tokenImages));
|
||||
logger.info(" => Missing token images: " + tokenImages);
|
||||
return new ArrayList<>(cardsToDownload);
|
||||
}
|
||||
|
||||
|
|
@ -413,24 +408,29 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
String[] params = line.split("\\|", -1);
|
||||
if (params.length >= 5) {
|
||||
int type = 0;
|
||||
String fileName = "";
|
||||
if (params[4] != null && !params[4].isEmpty()) {
|
||||
type = Integer.parseInt(params[4].trim());
|
||||
}
|
||||
if (params.length > 5 && params[5] != null && !params[5].isEmpty()) {
|
||||
fileName = params[5].trim();
|
||||
}
|
||||
|
||||
if (params[1].toLowerCase().equals("generate") && params[2].startsWith("TOK:")) {
|
||||
String set = params[2].substring(4);
|
||||
CardDownloadData card = new CardDownloadData(params[3], set, "0", false, type, "", "", true);
|
||||
list.add(card);
|
||||
} else if (params[1].toLowerCase().equals("generate") && params[2].startsWith("EMBLEM:")) {
|
||||
String set = params[2].substring(7);
|
||||
CardDownloadData card = new CardDownloadData("Emblem " + params[3], set, "0", false, type, "", "", true);
|
||||
CardDownloadData card = new CardDownloadData("Emblem " + params[3], set, "0", false, type, "", "", true, fileName);
|
||||
list.add(card);
|
||||
} else if (params[1].toLowerCase().equals("generate") && params[2].startsWith("EMBLEM-:")) {
|
||||
String set = params[2].substring(8);
|
||||
CardDownloadData card = new CardDownloadData(params[3] + " Emblem", set, "0", false, type, "", "", true);
|
||||
CardDownloadData card = new CardDownloadData(params[3] + " Emblem", set, "0", false, type, "", "", true, fileName);
|
||||
list.add(card);
|
||||
} else if (params[1].toLowerCase().equals("generate") && params[2].startsWith("EMBLEM!:")) {
|
||||
String set = params[2].substring(8);
|
||||
CardDownloadData card = new CardDownloadData(params[3], set, "0", false, type, "", "", true);
|
||||
CardDownloadData card = new CardDownloadData(params[3], set, "0", false, type, "", "", true, fileName);
|
||||
list.add(card);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -531,20 +531,18 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
imageRef = cardImageSource.getSourceName() + imageRef;
|
||||
try {
|
||||
URL imageUrl = new URL(imageRef);
|
||||
if (card != null) {
|
||||
card.setToken(cardImageSource.isTokenSource());
|
||||
}
|
||||
card.setToken(cardImageSource.isTokenSource());
|
||||
Runnable task = new DownloadTask(card, imageUrl, fileName, cardImageSource.getTotalImages());
|
||||
executor.execute(task);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
} else if (card != null && cardImageSource.getTotalImages() == -1) {
|
||||
} else if (cardImageSource.getTotalImages() == -1) {
|
||||
logger.info("Card not available on " + cardImageSource.getSourceName() + ": " + card.getName() + " (" + card.getSet() + ")");
|
||||
synchronized (sync) {
|
||||
update(cardIndex + 1, cardsToDownload.size());
|
||||
}
|
||||
}
|
||||
} else if (url != null) {
|
||||
} else {
|
||||
Runnable task = new DownloadTask(card, new URL(url), cardsToDownload.size());
|
||||
executor.execute(task);
|
||||
}
|
||||
|
|
@ -637,7 +635,11 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
}
|
||||
File existingFile = new File(imagePath.replaceFirst("\\w{3}.zip", ""));
|
||||
if (existingFile.exists()) {
|
||||
new TFile(existingFile).cp_rp(outputFile);
|
||||
try {
|
||||
new TFile(existingFile).cp_rp(outputFile);
|
||||
} catch (IOException e) {
|
||||
logger.error("Error while copying file " + card.getName(), e);
|
||||
}
|
||||
synchronized (sync) {
|
||||
update(cardIndex + 1, count);
|
||||
}
|
||||
|
|
@ -728,7 +730,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
logger.error(e, e);
|
||||
} finally {
|
||||
if (temporaryFile != null) {
|
||||
//temporaryFile.delete();
|
||||
temporaryFile.delete();
|
||||
}
|
||||
}
|
||||
synchronized (sync) {
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ public class CardImageUtils {
|
|||
String imageName;
|
||||
|
||||
String type = card.getType() != 0 ? " " + Integer.toString(card.getType()) : "";
|
||||
String name = card.getName().replace(":", "").replace("//", "-");
|
||||
String name = card.getFileName().isEmpty() ? card.getName().replace(":", "").replace("//", "-") : card.getFileName();
|
||||
|
||||
if (card.getUsesVariousArt()) {
|
||||
imageName = name + "." + card.getCollectorId() + ".full.jpg";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue