Refactor: removed outdated images code and fixed missing images logs for tokens;

This commit is contained in:
Oleg Agafonov 2019-01-12 03:03:04 +04:00
parent 79b0f9ad15
commit e1f8d97512
6 changed files with 20 additions and 221 deletions

View file

@ -85,11 +85,6 @@ public class StackDialog extends IDialogPanel {
jTitle.setFont(new Font("Dialog", Font.BOLD, 14));
jTitle.setText("Current stack: ");
/*jTitle2 = new CustomLabel();
jTitle2.setBounds(new Rectangle(5, 5 + SettingsManager.getInstance().getCardSize().height + 30, 129, 20));
jTitle2.setFont(new Font("Dialog", Font.BOLD, 14));
jTitle2.setText("Spell targets:");*/
this.setLayout(null);
jLayeredPane.setLayout(null);

View file

@ -94,7 +94,6 @@ public final class Constants {
public interface IO {
String DEFAULT_IMAGES_DIR = "plugins" + File.separator + "images" + File.separator;
String IMAGE_PROPERTIES_FILE = "image.url.properties";
}
public enum DeckEditorMode {

View file

@ -18,7 +18,6 @@ import net.java.truevfs.access.TVFS;
import net.java.truevfs.kernel.spec.FsSyncException;
import org.apache.log4j.Logger;
import org.mage.plugins.card.dl.sources.*;
import org.mage.plugins.card.properties.SettingsManager;
import org.mage.plugins.card.utils.CardImageUtils;
import javax.swing.*;
@ -45,10 +44,10 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
private static DownloadPicturesService instance;
private static final Logger logger = Logger.getLogger(DownloadPicturesService.class);
public static final String ALL_IMAGES = "- ALL images from selected source (can be slow)";
public static final String ALL_MODERN_IMAGES = "- MODERN images (can be slow)";
public static final String ALL_STANDARD_IMAGES = "- STANDARD images";
public static final String ALL_TOKENS = "- TOKEN images";
private static final String ALL_IMAGES = "- ALL images from selected source (can be slow)";
private static final String ALL_MODERN_IMAGES = "- MODERN images (can be slow)";
private static final String ALL_STANDARD_IMAGES = "- STANDARD images";
private static final String ALL_TOKENS = "- TOKEN images";
private DownloadImagesDialog uiDialog;
private boolean needCancel;
@ -60,7 +59,7 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
private int missingCardsCount = 0;
private int missingTokensCount = 0;
List<String> selectedSets = new ArrayList<>();
private List<String> selectedSets = new ArrayList<>();
private static CardImageSource selectedSource;
private final Object sync = new Object();
@ -393,7 +392,6 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
}
private static List<CardDownloadData> prepareMissingCards(List<CardInfo> allCards, boolean redownloadMode) {
HashSet<String> ignoreUrls = SettingsManager.getIntance().getIgnoreUrls();
// get filter for Standard Type 2 cards
Set<String> type2SetsFilter = new HashSet<>();
@ -408,8 +406,7 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
List<CardDownloadData> allCardsUrls = Collections.synchronizedList(new ArrayList<>());
try {
allCards.parallelStream().forEach(card -> {
if (!card.getCardNumber().isEmpty() && !"0".equals(card.getCardNumber()) && !card.getSetCode().isEmpty()
&& !ignoreUrls.contains(card.getSetCode())) {
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());
@ -586,8 +583,6 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
}
if (p != null) {
HashSet<String> ignoreUrls = SettingsManager.getIntance().getIgnoreUrls();
update(0, cardsDownloadQueue.size());
logger.info("Started download of " + cardsDownloadQueue.size() + " images"
+ " from source: " + selectedSource.getSourceName()
@ -602,7 +597,7 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
logger.debug("Downloading image: " + card.getName() + " (" + card.getSet() + ')');
CardImageUrls urls;
if (ignoreUrls.contains(card.getSet()) || card.isToken()) {
if (card.isToken()) {
if (!"0".equals(card.getCollectorId())) {
continue;
}

View file

@ -1,76 +0,0 @@
package org.mage.plugins.card.properties;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Properties;
import mage.client.constants.Constants;
public class SettingsManager {
private static SettingsManager settingsManager = null;
public static synchronized SettingsManager getIntance() {
if (settingsManager == null) {
settingsManager = new SettingsManager();
}
return settingsManager;
}
private SettingsManager() {
loadImageProperties();
}
public void reloadImageProperties() {
loadImageProperties();
}
private void loadImageProperties() {
imageUrlProperties = new Properties();
try {
InputStream is = SettingsManager.class.getClassLoader().getResourceAsStream(Constants.IO.IMAGE_PROPERTIES_FILE);
if (is == null) {
throw new RuntimeException("Couldn't load " + Constants.IO.IMAGE_PROPERTIES_FILE);
}
imageUrlProperties.load(is);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
public String getSetNameReplacement(String setName) {
String result = setName;
if (imageUrlProperties != null) {
result = imageUrlProperties.getProperty(setName, setName);
}
return result;
}
public HashSet<String> getIgnoreUrls() {
HashSet<String> ignoreUrls = new HashSet<>();
if (imageUrlProperties != null) {
String result = imageUrlProperties.getProperty("ignore.urls");
if (result != null) {
String[] ignore = result.split(",");
ignoreUrls.addAll(Arrays.asList(ignore));
}
}
return ignoreUrls;
}
public ArrayList<String> getTokenLookupOrder() {
ArrayList<String> order = new ArrayList<>();
if (imageUrlProperties != null) {
String result = imageUrlProperties.getProperty("token.lookup.order");
if (result != null) {
String[] sets = result.split(",");
order.addAll(Arrays.asList(sets));
}
}
return order;
}
private Properties imageUrlProperties;
}

View file

@ -1,5 +1,16 @@
package org.mage.plugins.card.utils;
import mage.client.MageFrame;
import mage.client.constants.Constants;
import mage.client.dialog.PreferencesDialog;
import mage.remote.Connection;
import mage.remote.Connection.ProxyType;
import net.java.truevfs.access.TFile;
import org.apache.log4j.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.mage.plugins.card.images.CardDownloadData;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
@ -12,18 +23,6 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.prefs.Preferences;
import mage.client.MageFrame;
import mage.client.constants.Constants;
import mage.client.dialog.PreferencesDialog;
import mage.remote.Connection;
import mage.remote.Connection.ProxyType;
import net.java.truevfs.access.TFile;
import org.apache.log4j.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.mage.plugins.card.images.CardDownloadData;
import org.mage.plugins.card.properties.SettingsManager;
public final class CardImageUtils {
private static final HashMap<CardDownloadData, String> pathCache = new HashMap<>();
@ -53,7 +52,7 @@ public final class CardImageUtils {
return filePath;
}
log.warn("Token image file not found. Set: " + card.getSet() + " Token Set Code: " + card.getTokenSetCode() + " Name: " + card.getName() + " File path: " + filePath);
log.warn("Token image file not found. Set: " + card.getSet() + " Token Set Code: " + card.getTokenSetCode() + " Name: " + card.getName() + " File path: " + getTokenImagePath(card));
} else {
log.warn("Trying to get token path for non token card. Set: " + card.getSet() + " Set Code: " + card.getTokenSetCode() + " Name: " + card.getName());
}
@ -85,20 +84,6 @@ public final class CardImageUtils {
}
}
return filename;
// makes no longer sense
// file = new TFile(filename);
// if (!file.exists()) {
// CardDownloadData updated = new CardDownloadData(card);
// updated.setName(card.getName() + " 1");
// filename = buildImagePathToCard(updated);
// file = new TFile(filename);
// if (!file.exists()) {
// updated = new CardDownloadData(card);
// updated.setName(card.getName() + " 2");
// filename = buildImagePathToCard(updated);
// }
// }
}
private static String searchForCardImage(CardDownloadData card) {
@ -112,30 +97,9 @@ public final class CardImageUtils {
pathCache.put(card, path);
return path;
}
// for (String set : SettingsManager.getIntance().getTokenLookupOrder()) {
// c.setSet(set);
// path = getTokenImagePath(c);
// file = new TFile(path);
// if (file.exists()) {
// pathCache.put(card, path);
// return path;
// }
// }
return generateTokenDescriptorImagePath(card);
}
public static String updateSet(String cardSet, boolean forUrl) {
String set = cardSet.toLowerCase(Locale.ENGLISH);
if (set.equals("con")) {
set = "cfx";
}
if (forUrl) {
set = SettingsManager.getIntance().getSetNameReplacement(set);
}
return set;
}
public static String prepareCardNameForFile(String cardName) {
return cardName.replace(":", "").replace("\"", "").replace("//", "-");
}
@ -182,7 +146,7 @@ public final class CardImageUtils {
throw new IllegalArgumentException("Card " + card.getName() + " have empty set.");
}
String set = updateSet(card.getSet(), false).toUpperCase(Locale.ENGLISH); // TODO: research auto-replace... old code?
String set = card.getSet().toUpperCase(Locale.ENGLISH);
if (card.isToken()) {
return buildImagePathToSetAsToken(set);