mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
Made images path configurable. Fixed Issue 36.
This commit is contained in:
parent
2e92da3259
commit
ef0a73f26d
10 changed files with 196 additions and 49 deletions
|
|
@ -396,22 +396,33 @@ public class CardPluginImpl implements CardPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Download images.
|
||||
*
|
||||
* @param allCards Set of cards to download images for.
|
||||
* @param imagesPath Path to check in and store images to. Can be null, in such case default path should be used.
|
||||
*/
|
||||
@Override
|
||||
public void downloadImages(Set<Card> allCards) {
|
||||
DownloadPictures.startDownload(null, allCards);
|
||||
public void downloadImages(Set<Card> allCards, String imagesPath) {
|
||||
DownloadPictures.startDownload(null, allCards, imagesPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download various symbols (mana, tap, set).
|
||||
*
|
||||
* @param imagesPath Path to check in and store symbols to. Can be null, in such case default path should be used.
|
||||
*/
|
||||
@Override
|
||||
public void downloadSymbols() {
|
||||
public void downloadSymbols(String imagesPath) {
|
||||
final DownloadGui g = new DownloadGui(new Downloader());
|
||||
|
||||
Iterable<DownloadJob> it = new GathererSymbols();
|
||||
Iterable<DownloadJob> it = new GathererSymbols(imagesPath);
|
||||
|
||||
for (DownloadJob job : it) {
|
||||
g.getDownloader().add(job);
|
||||
}
|
||||
|
||||
it = new GathererSets();
|
||||
it = new GathererSets(imagesPath);
|
||||
for(DownloadJob job:it) {
|
||||
g.getDownloader().add(job);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,17 +4,17 @@ import java.awt.Rectangle;
|
|||
import java.io.File;
|
||||
|
||||
public class Constants {
|
||||
public static final String RESOURCE_PATH_MANA_LARGE = IO.imageBaseDir + "symbols" + File.separator + "large";
|
||||
public static final String RESOURCE_PATH_MANA_MEDIUM = IO.imageBaseDir + "symbols" + File.separator + "medium";
|
||||
public static final String RESOURCE_PATH_MANA_LARGE = IO.imageBaseDir + File.separator + "symbols" + File.separator + "large";
|
||||
public static final String RESOURCE_PATH_MANA_MEDIUM = IO.imageBaseDir + File.separator + "symbols" + File.separator + "medium";
|
||||
|
||||
public static final String RESOURCE_PATH_SET = IO.imageBaseDir + "sets" + File.separator;
|
||||
public static final String RESOURCE_PATH_SET = IO.imageBaseDir + File.separator + "sets" + File.separator;
|
||||
public static final String RESOURCE_PATH_SET_SMALL = RESOURCE_PATH_SET + File.separator + "small" + File.separator;
|
||||
|
||||
public static final Rectangle CARD_SIZE_FULL = new Rectangle(101, 149);
|
||||
public static final Rectangle THUMBNAIL_SIZE_FULL = new Rectangle(102, 146);
|
||||
|
||||
public interface IO {
|
||||
public static final String imageBaseDir = "plugins" + File.separator + "images" + File.separator;
|
||||
public static final String imageBaseDir = "plugins" + File.separator + "images";
|
||||
public static final String IMAGE_PROPERTIES_FILE = "image.url.properties";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package org.mage.plugins.card.dl.sources;
|
||||
|
||||
import com.google.common.collect.AbstractIterator;
|
||||
import org.mage.plugins.card.dl.DownloadJob;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -12,7 +11,11 @@ import static org.mage.plugins.card.dl.DownloadJob.fromURL;
|
|||
import static org.mage.plugins.card.dl.DownloadJob.toFile;
|
||||
|
||||
public class GathererSets implements Iterable<DownloadJob> {
|
||||
private static final File outDir = new File("plugins/images/sets");
|
||||
|
||||
private final static String SETS_PATH = File.separator + "sets";
|
||||
private final static File DEFAULT_OUT_DIR = new File("plugins" + File.separator + "images" + SETS_PATH);
|
||||
private static File outDir = DEFAULT_OUT_DIR;
|
||||
|
||||
private static final String[] symbols = {"DIS", "DST", "GPT", "RAV", "MRD", "10E", "HOP", "EVE", "APC", "TMP", "CHK"};
|
||||
private static final String[] withMythics = {"ALA", "CFX", "ARB", "ZEN", "WWK", "ROE", "SOM", "M10", "M11", "DDF", "MBS", "NPH"};
|
||||
private static final HashMap<String, String> symbolsReplacements = new HashMap<String, String>();
|
||||
|
|
@ -23,6 +26,14 @@ public class GathererSets implements Iterable<DownloadJob> {
|
|||
symbolsReplacements.put("TMP", "TE");
|
||||
}
|
||||
|
||||
public GathererSets(String path) {
|
||||
if (path == null) {
|
||||
useDefaultDir();
|
||||
} else {
|
||||
changeOutDir(path);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<DownloadJob> iterator() {
|
||||
ArrayList<DownloadJob> jobs = new ArrayList<DownloadJob>();
|
||||
|
|
@ -48,4 +59,20 @@ public class GathererSets implements Iterable<DownloadJob> {
|
|||
String url = "http://gatherer.wizards.com/Handlers/Image.ashx?type=symbol&set=" + set + "&size=small&rarity=" + rarity;
|
||||
return new DownloadJob(set + "-" + rarity, fromURL(url), toFile(dst));
|
||||
}
|
||||
|
||||
private void changeOutDir(String path) {
|
||||
File file = new File(path + SETS_PATH);
|
||||
if (file.exists()) {
|
||||
outDir = file;
|
||||
} else {
|
||||
file.mkdirs();
|
||||
if (file.exists()) {
|
||||
outDir = file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void useDefaultDir() {
|
||||
outDir = DEFAULT_OUT_DIR;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,16 +7,15 @@
|
|||
package org.mage.plugins.card.dl.sources;
|
||||
|
||||
|
||||
import static java.lang.String.format;
|
||||
import static org.mage.plugins.card.dl.DownloadJob.fromURL;
|
||||
import static org.mage.plugins.card.dl.DownloadJob.toFile;
|
||||
import com.google.common.collect.AbstractIterator;
|
||||
import org.mage.plugins.card.dl.DownloadJob;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.mage.plugins.card.dl.DownloadJob;
|
||||
|
||||
import com.google.common.collect.AbstractIterator;
|
||||
import static java.lang.String.format;
|
||||
import static org.mage.plugins.card.dl.DownloadJob.fromURL;
|
||||
import static org.mage.plugins.card.dl.DownloadJob.toFile;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -29,7 +28,10 @@ public class GathererSymbols implements Iterable<DownloadJob> {
|
|||
//TODO chaos and planeswalker symbol
|
||||
//chaos: http://gatherer.wizards.com/Images/Symbols/chaos.gif
|
||||
|
||||
private static final File outDir = new File("plugins/images/symbols");
|
||||
private final static String SYMBOLS_PATH = File.separator + "symbols";
|
||||
private final static File DEFAULT_OUT_DIR = new File("plugins" + File.separator + "images" + SYMBOLS_PATH);
|
||||
private static File outDir = DEFAULT_OUT_DIR;
|
||||
|
||||
private static final String urlFmt = "http://gatherer.wizards.com/handlers/image.ashx?size=%1$s&name=%2$s&type=symbol";
|
||||
|
||||
private static final String[] sizes = {"small", "medium", "large"};
|
||||
|
|
@ -44,6 +46,14 @@ public class GathererSymbols implements Iterable<DownloadJob> {
|
|||
|
||||
"X", "S", "T", "Q"};
|
||||
private static final int minNumeric = 0, maxNumeric = 16;
|
||||
|
||||
public GathererSymbols(String path) {
|
||||
if (path == null) {
|
||||
useDefaultDir();
|
||||
} else {
|
||||
changeOutDir(path);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<DownloadJob> iterator() {
|
||||
|
|
@ -80,4 +90,20 @@ public class GathererSymbols implements Iterable<DownloadJob> {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void changeOutDir(String path) {
|
||||
File file = new File(path + SYMBOLS_PATH);
|
||||
if (file.exists()) {
|
||||
outDir = file;
|
||||
} else {
|
||||
file.mkdirs();
|
||||
if (file.exists()) {
|
||||
outDir = file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void useDefaultDir() {
|
||||
outDir = DEFAULT_OUT_DIR;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import java.util.Set;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import javax.management.ImmutableDescriptor;
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
|
|
@ -69,6 +70,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
private static boolean offlineMode = false;
|
||||
private JCheckBox checkBox;
|
||||
private final Object sync = new Object();
|
||||
private String imagesPath;
|
||||
|
||||
private static CardImageSource cardImageSource;
|
||||
|
||||
|
|
@ -79,11 +81,11 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
public static final Proxy.Type[] types = Proxy.Type.values();
|
||||
|
||||
public static void main(String[] args) {
|
||||
startDownload(null, null);
|
||||
startDownload(null, null, null);
|
||||
}
|
||||
|
||||
public static void startDownload(JFrame frame, Set<Card> allCards) {
|
||||
ArrayList<CardInfo> cards = getNeededCards(allCards);
|
||||
public static void startDownload(JFrame frame, Set<Card> allCards, String imagesPath) {
|
||||
ArrayList<CardInfo> cards = getNeededCards(allCards, imagesPath);
|
||||
|
||||
/*
|
||||
* if (cards == null || cards.size() == 0) {
|
||||
|
|
@ -91,7 +93,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
* "All card pictures have been downloaded."); return; }
|
||||
*/
|
||||
|
||||
DownloadPictures download = new DownloadPictures(cards);
|
||||
DownloadPictures download = new DownloadPictures(cards, imagesPath);
|
||||
JDialog dlg = download.getDlg(frame);
|
||||
dlg.setVisible(true);
|
||||
dlg.dispose();
|
||||
|
|
@ -115,8 +117,9 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
public DownloadPictures(ArrayList<CardInfo> cards) {
|
||||
public DownloadPictures(ArrayList<CardInfo> cards, String imagesPath) {
|
||||
this.cards = cards;
|
||||
this.imagesPath = imagesPath;
|
||||
|
||||
addr = new JTextField("Proxy Address");
|
||||
port = new JTextField("Proxy Port");
|
||||
|
|
@ -230,7 +233,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
dlg = new JOptionPane(p0, JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[1]);
|
||||
}
|
||||
|
||||
private static ArrayList<CardInfo> getNeededCards(Set<Card> allCards) {
|
||||
private static ArrayList<CardInfo> getNeededCards(Set<Card> allCards, String imagesPath) {
|
||||
|
||||
ArrayList<CardInfo> cardsToDownload = new ArrayList<CardInfo>();
|
||||
|
||||
|
|
@ -273,7 +276,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
|| card.getName().equals("Plains")) {
|
||||
withCollectorId = true;
|
||||
}
|
||||
file = new File(CardImageUtils.getImagePath(card, withCollectorId));
|
||||
file = new File(CardImageUtils.getImagePath(card, withCollectorId, imagesPath));
|
||||
if (!file.exists()) {
|
||||
cardsToDownload.add(card);
|
||||
}
|
||||
|
|
@ -375,7 +378,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
@Override
|
||||
public void run() {
|
||||
|
||||
File base = new File(Constants.IO.imageBaseDir);
|
||||
File base = new File(this.imagesPath != null ? imagesPath : Constants.IO.imageBaseDir);
|
||||
if (!base.exists()) {
|
||||
base.mkdir();
|
||||
}
|
||||
|
|
@ -411,7 +414,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
}
|
||||
|
||||
if (url != null) {
|
||||
Runnable task = new DownloadTask(card, new URL(url));
|
||||
Runnable task = new DownloadTask(card, new URL(url), imagesPath);
|
||||
executor.execute(task);
|
||||
} else {
|
||||
synchronized (sync) {
|
||||
|
|
@ -435,10 +438,12 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
private final class DownloadTask implements Runnable {
|
||||
private CardInfo card;
|
||||
private URL url;
|
||||
private String imagesPath;
|
||||
|
||||
public DownloadTask(CardInfo card, URL url) {
|
||||
public DownloadTask(CardInfo card, URL url, String imagesPath) {
|
||||
this.card = card;
|
||||
this.url = url;
|
||||
this.imagesPath = imagesPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -446,7 +451,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
try {
|
||||
BufferedInputStream in = new BufferedInputStream(url.openConnection(p).getInputStream());
|
||||
|
||||
createDirForCard(card);
|
||||
createDirForCard(card, imagesPath);
|
||||
|
||||
boolean withCollectorId = false;
|
||||
if (card.getName().equals("Forest") || card.getName().equals("Mountain") || card.getName().equals("Swamp")
|
||||
|
|
@ -485,8 +490,8 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
}
|
||||
}
|
||||
|
||||
private static File createDirForCard(CardInfo card) throws Exception {
|
||||
File setDir = new File(CardImageUtils.getImageDir(card));
|
||||
private static File createDirForCard(CardInfo card, String imagesPath) throws Exception {
|
||||
File setDir = new File(CardImageUtils.getImageDir(card, imagesPath));
|
||||
if (!setDir.exists()) {
|
||||
setDir.mkdirs();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,23 +127,28 @@ public class CardImageUtils {
|
|||
return set;
|
||||
}
|
||||
|
||||
public static String getImageDir(CardInfo card) {
|
||||
public static String getImageDir(CardInfo card, String imagesPath) {
|
||||
if (card.getSet() == null) {
|
||||
return "";
|
||||
}
|
||||
String set = updateSet(card.getSet(), false).toUpperCase();
|
||||
String imagesDir = (imagesPath != null ? imagesPath : Constants.IO.imageBaseDir);
|
||||
if (card.isToken()) {
|
||||
return Constants.IO.imageBaseDir + File.separator + "TOK" + File.separator + set;
|
||||
return imagesDir + File.separator + "TOK" + File.separator + set;
|
||||
} else {
|
||||
return Constants.IO.imageBaseDir + set;
|
||||
return imagesDir + File.separator + set;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getImagePath(CardInfo card, boolean withCollector) {
|
||||
|
||||
public static String getImagePath(CardInfo card, boolean withCollector) {
|
||||
return getImagePath(card, withCollector, null);
|
||||
}
|
||||
|
||||
public static String getImagePath(CardInfo card, boolean withCollector, String imagesPath) {
|
||||
if (withCollector) {
|
||||
return getImageDir(card) + File.separator + card.getName() + "." + card.getCollectorId() + ".full.jpg";
|
||||
return getImageDir(card, imagesPath) + File.separator + card.getName() + "." + card.getCollectorId() + ".full.jpg";
|
||||
} else {
|
||||
return getImageDir(card) + File.separator + card.getName() + ".full.jpg";
|
||||
return getImageDir(card, imagesPath) + File.separator + card.getName() + ".full.jpg";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue