moved gui downloader to a separate package

introducted 'protocols' for imagecache item urls.
products and tokens use their unique prefixes to point to the picture location correctly.
This commit is contained in:
Maxmtg
2012-03-16 07:16:56 +00:00
parent 0579f8f23d
commit 18387625af
17 changed files with 161 additions and 246 deletions

11
.gitattributes vendored
View File

@@ -11252,11 +11252,6 @@ src/main/java/forge/GameActionUtil.java svneol=native#text/plain
src/main/java/forge/GameEntity.java -text src/main/java/forge/GameEntity.java -text
src/main/java/forge/GameLog.java -text src/main/java/forge/GameLog.java -text
src/main/java/forge/GuiDisplayUtil.java svneol=native#text/plain src/main/java/forge/GuiDisplayUtil.java svneol=native#text/plain
src/main/java/forge/GuiDownloadPicturesLQ.java svneol=native#text/plain
src/main/java/forge/GuiDownloadPrices.java svneol=native#text/plain
src/main/java/forge/GuiDownloadQuestImages.java -text
src/main/java/forge/GuiDownloadSetPicturesLQ.java svneol=native#text/plain
src/main/java/forge/GuiDownloader.java -text
src/main/java/forge/GuiImportPicture.java svneol=native#text/plain src/main/java/forge/GuiImportPicture.java svneol=native#text/plain
src/main/java/forge/GuiInput.java svneol=native#text/plain src/main/java/forge/GuiInput.java svneol=native#text/plain
src/main/java/forge/GuiMigrateLocalMWSSetPicturesHQ.java svneol=native#text/plain src/main/java/forge/GuiMigrateLocalMWSSetPicturesHQ.java svneol=native#text/plain
@@ -11563,6 +11558,12 @@ src/main/java/forge/gui/deckeditor/elements/TableSorterCascade.java -text
src/main/java/forge/gui/deckeditor/elements/TableView.java -text src/main/java/forge/gui/deckeditor/elements/TableView.java -text
src/main/java/forge/gui/deckeditor/elements/package-info.java -text src/main/java/forge/gui/deckeditor/elements/package-info.java -text
src/main/java/forge/gui/deckeditor/package-info.java -text src/main/java/forge/gui/deckeditor/package-info.java -text
src/main/java/forge/gui/download/GuiDownloadPicturesLQ.java svneol=native#text/plain
src/main/java/forge/gui/download/GuiDownloadPrices.java svneol=native#text/plain
src/main/java/forge/gui/download/GuiDownloadQuestImages.java -text
src/main/java/forge/gui/download/GuiDownloadSetPicturesLQ.java svneol=native#text/plain
src/main/java/forge/gui/download/GuiDownloader.java -text
src/main/java/forge/gui/download/package-info.java -text
src/main/java/forge/gui/game/CardDetailPanel.java svneol=native#text/plain src/main/java/forge/gui/game/CardDetailPanel.java svneol=native#text/plain
src/main/java/forge/gui/game/CardPanel.java svneol=native#text/plain src/main/java/forge/gui/game/CardPanel.java svneol=native#text/plain
src/main/java/forge/gui/game/CardPicturePanel.java svneol=native#text/plain src/main/java/forge/gui/game/CardPicturePanel.java svneol=native#text/plain

View File

@@ -17,13 +17,11 @@
*/ */
package forge; package forge;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
@@ -51,7 +49,6 @@ import forge.card.replacement.ReplacementHandler;
import forge.card.trigger.TriggerHandler; import forge.card.trigger.TriggerHandler;
import forge.error.ErrorViewer; import forge.error.ErrorViewer;
import forge.gui.toolbox.FProgressBar; import forge.gui.toolbox.FProgressBar;
import forge.util.FileUtil;
import forge.util.LineReader; import forge.util.LineReader;
import forge.view.SplashFrame; import forge.view.SplashFrame;
@@ -386,7 +383,7 @@ public class CardReader implements Runnable {
for(String line : lines ) { for(String line : lines ) {
line = line.trim(); line = line.trim();
if("End".equals(line)) { ignoreTheRest = true; continue; } if("End".equals(line)) { ignoreTheRest = true; }
if(ignoreTheRest) { continue; } // have to deplete the iterator if(ignoreTheRest) { continue; } // have to deplete the iterator
// otherwise the underlying class would close its stream on finalize only // otherwise the underlying class would close its stream on finalize only
@@ -451,17 +448,13 @@ public class CardReader implements Runnable {
final String[] value = line.split(":", 3); final String[] value = line.split(":", 3);
card.setSVar(value[1], value[2]); card.setSVar(value[1], value[2]);
} else if (line.startsWith("A:")) { } else if (line.startsWith("A:")) {
final String value = line.substring(2); card.addIntrinsicAbility(line.substring(2));
card.addIntrinsicAbility(value);
} else if (line.startsWith("T:")) { } else if (line.startsWith("T:")) {
final String value = line.substring(2); card.addTrigger(TriggerHandler.parseTrigger(line.substring(2), card, true));
card.addTrigger(TriggerHandler.parseTrigger(value, card, true));
} else if (line.startsWith("S:")) { } else if (line.startsWith("S:")) {
final String value = line.substring(2); card.addStaticAbilityString(line.substring(2));
card.addStaticAbilityString(value);
} else if (line.startsWith("R:")) { } else if (line.startsWith("R:")) {
final String value = line.substring(2); card.addReplacementEffect(ReplacementHandler.parseReplacement(line.substring(2), card));
card.addReplacementEffect(ReplacementHandler.parseReplacement(value, card));
} else if (line.startsWith("SetInfo:")) { } else if (line.startsWith("SetInfo:")) {
final String value = line.substring("SetInfo:".length()); final String value = line.substring("SetInfo:".length());
card.addSet(new EditionInfo(value)); card.addSet(new EditionInfo(value));

View File

@@ -64,14 +64,11 @@ public class ImageCache {
private static final LoadingCache<String, BufferedImage> IMAGE_CACHE; private static final LoadingCache<String, BufferedImage> IMAGE_CACHE;
/** Constant <code>FULL_SIZE</code>. */ /** Constant <code>FULL_SIZE</code>. */
private static final Pattern FULL_SIZE = Pattern.compile("(.*)#(\\d+.\\d+)"); private static final Pattern FULL_SIZE = Pattern.compile("(.*)#(\\d+.\\d+)");
/** Constant <code>TOKEN="#Token"</code> */
/** Constant <code>NORMAL="#Normal"</code> */ private static final String NORMAL = "#Normal", TAPPED = "#Tapped";
/** Constant <code>TAPPED="#Tapped"</code> */ public static final String SEALED_PRODUCT = "sealed://";
/** Constant <code>NORMAL="#Normal"</code> */ private static final String TOKEN = "token://";
/** Constant <code>TAPPED="#Tapped"</code>. */
private static final String TOKEN = "#Token", NORMAL = "#Normal", TAPPED = "#Tapped";
private static final String SEALED_PRODUCT = "sealed://";
static { static {
IMAGE_CACHE = CacheBuilder.newBuilder() IMAGE_CACHE = CacheBuilder.newBuilder()
.softValues() .softValues()
@@ -108,12 +105,12 @@ public class ImageCache {
} else { } else {
// original // original
File path; File path;
if (key.endsWith(ImageCache.TOKEN)) { if (key.startsWith(ImageCache.TOKEN)) {
key = key.substring(0, key.length() - ImageCache.TOKEN.length()); key = key.substring(ImageCache.TOKEN.length());
path = ForgeProps.getFile(NewConstants.IMAGE_TOKEN); path = ForgeProps.getFile(NewConstants.IMAGE_TOKEN);
} else if (key.startsWith(SEALED_PRODUCT)) { } else if (key.startsWith(SEALED_PRODUCT)) {
key = key.substring(SEALED_PRODUCT.length()); key = key.substring(SEALED_PRODUCT.length());
path = ForgeProps.getFile(NewConstants.IMAGE_BASE); path = ForgeProps.getFile(NewConstants.IMAGE_SEALED_PRODUCT);
} else { } else {
path = ForgeProps.getFile(NewConstants.IMAGE_BASE); path = ForgeProps.getFile(NewConstants.IMAGE_BASE);
} }
@@ -300,7 +297,7 @@ public class ImageCache {
private static String getKey(final Card card) { private static String getKey(final Card card) {
if ((card.isToken() && !card.isCopiedToken()) || card.isFaceDown()) { if ((card.isToken() && !card.isCopiedToken()) || card.isFaceDown()) {
return GuiDisplayUtil.cleanString(card.getImageName()) + ImageCache.TOKEN; return ImageCache.TOKEN + GuiDisplayUtil.cleanString(card.getImageName());
} }
return card.getImageFilename(); // key; return card.getImageFilename(); // key;

View File

@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package forge; package forge.gui.download;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@@ -23,6 +23,9 @@ import java.util.List;
import javax.swing.JFrame; import javax.swing.JFrame;
import forge.AllZone;
import forge.Card;
import forge.GuiDisplayUtil;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
import forge.properties.NewConstants; import forge.properties.NewConstants;
@@ -55,13 +58,11 @@ public class GuiDownloadPicturesLQ extends GuiDownloader {
* getNeededCards. * getNeededCards.
* </p> * </p>
* *
* @return an array of {@link forge.GuiDownloader.DownloadObject} objects. * @return an array of {@link forge.gui.download.GuiDownloader.DownloadObject} objects.
*/ */
@Override @Override
protected final DownloadObject[] getNeededImages() { protected final DownloadObject[] getNeededImages() {
// read token names and urls // read token names and urls
final DownloadObject[] cardTokenLQ = GuiDownloader.readFileWithNames(NewConstants.TOKEN_IMAGES,
ForgeProps.getFile(NewConstants.IMAGE_TOKEN));
final ArrayList<DownloadObject> cList = new ArrayList<DownloadObject>(); final ArrayList<DownloadObject> cList = new ArrayList<DownloadObject>();
final String base = ForgeProps.getFile(NewConstants.IMAGE_BASE).getPath(); final String base = ForgeProps.getFile(NewConstants.IMAGE_BASE).getPath();
@@ -70,32 +71,23 @@ public class GuiDownloadPicturesLQ extends GuiDownloader {
} }
final ArrayList<DownloadObject> list = new ArrayList<DownloadObject>(); final ArrayList<DownloadObject> list = new ArrayList<DownloadObject>();
File file;
final DownloadObject[] a = { new DownloadObject("", "", "") }; for (final DownloadObject element : cList) {
final DownloadObject[] cardPlay = cList.toArray(a); if (!element.getDestination().exists()) {
// check to see which cards we already have
for (final DownloadObject element : cardPlay) {
file = new File(base, element.getName());
if (!file.exists()) {
list.add(element); list.add(element);
} }
} }
// add missing tokens to the list of things to download // add missing tokens to the list of things to download
final File filebase = ForgeProps.getFile(NewConstants.IMAGE_TOKEN); for (final DownloadObject element : GuiDownloader.readFileWithNames(NewConstants.TOKEN_IMAGES,
for (final DownloadObject element : cardTokenLQ) { ForgeProps.getFile(NewConstants.IMAGE_TOKEN))) {
file = new File(filebase, element.getName()); if (!element.getDestination().exists()) {
if (!file.exists()) {
list.add(element); list.add(element);
} }
} }
// return all card names and urls that are needed // return all card names and urls that are needed
final DownloadObject[] out = new DownloadObject[list.size()]; return list.toArray(new DownloadObject[list.size()]);
list.toArray(out);
return out;
} // getNeededImages() } // getNeededImages()
private List<DownloadObject> createDLObjects(final Card c, final String base) { private List<DownloadObject> createDLObjects(final Card c, final String base) {
@@ -111,13 +103,12 @@ public class GuiDownloadPicturesLQ extends GuiDownloader {
final String[] urls = url.split("\\\\"); final String[] urls = url.split("\\\\");
final String iName = GuiDisplayUtil.cleanString(c.getImageName()); final String iName = GuiDisplayUtil.cleanString(c.getImageName());
ret.add(new DownloadObject(iName + ".jpg", urls[0], base)); ret.add(new DownloadObject(urls[0], new File(base, iName + ".jpg")));
if (urls.length > 1) { for (int j = 1; j < urls.length; j++) {
for (int j = 1; j < urls.length; j++) { ret.add(new DownloadObject(urls[j], new File(base, iName + j + ".jpg")));
ret.add(new DownloadObject(iName + j + ".jpg", urls[j], base));
}
} }
} }
return ret; return ret;

View File

@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package forge; package forge.gui.download;
import java.awt.Point; import java.awt.Point;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;

View File

@@ -15,10 +15,11 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package forge; package forge.gui.download;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame; import javax.swing.JFrame;
@@ -53,50 +54,33 @@ public class GuiDownloadQuestImages extends GuiDownloader {
* getNeededCards. * getNeededCards.
* </p> * </p>
* *
* @return an array of {@link forge.GuiDownloadSetPicturesLQ} objects. * @return an array of {@link forge.gui.download.GuiDownloadSetPicturesLQ} objects.
*/ */
@Override @Override
protected final DownloadObject[] getNeededImages() { protected final DownloadObject[] getNeededImages() {
// read all card names and urls // read all card names and urls
final DownloadObject[] questOpponents = GuiDownloader.readFile(NewConstants.Quest.OPPONENT_ICONS, final List<DownloadObject> urls = new ArrayList<DownloadObject>();
ForgeProps.getFile(NewConstants.Quest.OPPONENT_DIR));
final DownloadObject[] boosterImages = GuiDownloader.readFile(NewConstants.PICS_BOOSTER_IMAGES,
ForgeProps.getFile(NewConstants.PICS_BOOSTER));
final DownloadObject[] petIcons = GuiDownloader.readFileWithNames(NewConstants.Quest.PET_SHOP_ICONS,
ForgeProps.getFile(NewConstants.IMAGE_ICON));
final DownloadObject[] questPets = GuiDownloader.readFileWithNames(NewConstants.Quest.PET_TOKEN_IMAGES,
ForgeProps.getFile(NewConstants.IMAGE_TOKEN));
final ArrayList<DownloadObject> urls = new ArrayList<DownloadObject>();
File file; for (final DownloadObject questOpponent : GuiDownloader.readFile(NewConstants.Quest.OPPONENT_ICONS, ForgeProps.getFile(NewConstants.Quest.OPPONENT_DIR))) {
File dir = ForgeProps.getFile(NewConstants.Quest.OPPONENT_DIR); if (!questOpponent.getDestination().exists()) {
for (final DownloadObject questOpponent : questOpponents) {
file = new File(dir, questOpponent.getName().replace("%20", " "));
if (!file.exists()) {
urls.add(questOpponent); urls.add(questOpponent);
} }
} }
dir = ForgeProps.getFile(NewConstants.PICS_BOOSTER); for (final DownloadObject boosterImage : GuiDownloader.readFile(NewConstants.PICS_BOOSTER_IMAGES, ForgeProps.getFile(NewConstants.IMAGE_SEALED_PRODUCT))) {
for (final DownloadObject boosterImage : boosterImages) { if (!boosterImage.getDestination().exists()) {
file = new File(dir, boosterImage.getName().replace("%20", " "));
if (!file.exists()) {
urls.add(boosterImage); urls.add(boosterImage);
} }
} }
dir = ForgeProps.getFile(NewConstants.IMAGE_ICON); for (final DownloadObject petIcon : GuiDownloader.readFileWithNames(NewConstants.Quest.PET_SHOP_ICONS, ForgeProps.getFile(NewConstants.IMAGE_ICON))) {
for (final DownloadObject petIcon : petIcons) { if (!petIcon.getDestination().exists()) {
file = new File(dir, petIcon.getName().replace("%20", " "));
if (!file.exists()) {
urls.add(petIcon); urls.add(petIcon);
} }
} }
dir = ForgeProps.getFile(NewConstants.IMAGE_TOKEN); for (final DownloadObject questPet : GuiDownloader.readFileWithNames(NewConstants.Quest.PET_TOKEN_IMAGES, ForgeProps.getFile(NewConstants.IMAGE_TOKEN))) {
for (final DownloadObject questPet : questPets) { if (!questPet.getDestination().exists()) {
file = new File(dir, questPet.getName().replace("%20", " "));
if (!file.exists()) {
urls.add(questPet); urls.add(questPet);
} }
} }

View File

@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package forge; package forge.gui.download;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@@ -24,6 +24,8 @@ import javax.swing.JFrame;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import forge.CardUtil;
import forge.Singletons;
import forge.card.CardEdition; import forge.card.CardEdition;
import forge.item.CardDb; import forge.item.CardDb;
import forge.item.CardPrinted; import forge.item.CardPrinted;
@@ -82,9 +84,10 @@ public class GuiDownloadSetPicturesLQ extends GuiDownloader {
} }
if (!foundSetImage) { if (!foundSetImage) {
final int artsCnt = c.getCard().getEditionInfo(setCode3).getCopiesCount(); final int artsCnt = c.getCard().getEditionInfo(setCode3).getCopiesCount();
final String fn = CardUtil.buildIdealFilename(cardName, c.getArtIndex(), artsCnt); final String filename = CardUtil.buildIdealFilename(cardName, c.getArtIndex(), artsCnt);
cList.add(new DownloadObject(fn, urlBase + setCode2 + "/" + Base64Coder.encodeString(fn, true), String url = urlBase + setCode2 + "/" + Base64Coder.encodeString(filename, true);
this.picturesPath + File.separator + setCode3)); cList.add(new DownloadObject(url, new File(this.picturesPath + File.separator + setCode3, filename)));
System.out.println(String.format("%s [%s - %s]", cardName, setCode3, thisSet.getName())); System.out.println(String.format("%s [%s - %s]", cardName, setCode3, thisSet.getName()));
} }
} }
@@ -94,7 +97,7 @@ public class GuiDownloadSetPicturesLQ extends GuiDownloader {
* getNeededCards. * getNeededCards.
* </p> * </p>
* *
* @return an array of {@link forge.GuiDownloader.DownloadObject} objects. * @return an array of {@link forge.gui.download.GuiDownloader.DownloadObject} objects.
*/ */
@Override @Override
protected final DownloadObject[] getNeededImages() { protected final DownloadObject[] getNeededImages() {
@@ -102,8 +105,6 @@ public class GuiDownloadSetPicturesLQ extends GuiDownloader {
this.picturesPath = ForgeProps.getFile(NewConstants.IMAGE_BASE).getPath(); this.picturesPath = ForgeProps.getFile(NewConstants.IMAGE_BASE).getPath();
} }
// read token names and urls // read token names and urls
final DownloadObject[] cardTokenLQ = GuiDownloader.readFileWithNames(NewConstants.TOKEN_IMAGES,
ForgeProps.getFile(NewConstants.IMAGE_TOKEN));
final ArrayList<DownloadObject> cList = new ArrayList<DownloadObject>(); final ArrayList<DownloadObject> cList = new ArrayList<DownloadObject>();
for (final CardPrinted c : CardDb.instance().getAllCards()) { for (final CardPrinted c : CardDb.instance().getAllCards()) {
@@ -119,11 +120,8 @@ public class GuiDownloadSetPicturesLQ extends GuiDownloader {
} }
// add missing tokens to the list of things to download // add missing tokens to the list of things to download
File file; for (final DownloadObject element : GuiDownloader.readFileWithNames(NewConstants.TOKEN_IMAGES, ForgeProps.getFile(NewConstants.IMAGE_TOKEN))) {
final File filebase = ForgeProps.getFile(NewConstants.IMAGE_TOKEN); if (!element.getDestination().exists()) {
for (final DownloadObject element : cardTokenLQ) {
file = new File(filebase, element.getName());
if (!file.exists()) {
cList.add(element); cList.add(element);
} }
} }

View File

@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package forge; package forge.gui.download;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.EventQueue; import java.awt.EventQueue;
@@ -23,19 +23,18 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileReader;
import java.net.ConnectException; import java.net.ConnectException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.Proxy; import java.net.Proxy;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.StringTokenizer; import java.util.regex.Pattern;
import javax.swing.AbstractButton; import javax.swing.AbstractButton;
import javax.swing.Box; import javax.swing.Box;
@@ -53,11 +52,14 @@ import javax.swing.JTextField;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import org.apache.commons.lang3.StringUtils;
import com.esotericsoftware.minlog.Log; import com.esotericsoftware.minlog.Log;
import forge.error.ErrorViewer; import forge.error.ErrorViewer;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
import forge.properties.NewConstants; import forge.properties.NewConstants;
import forge.util.FileUtil;
import forge.util.MyRandom; import forge.util.MyRandom;
/** /**
@@ -382,60 +384,51 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
final byte[] buf = new byte[1024]; final byte[] buf = new byte[1024];
int len; int len;
for (this.update(0); (this.card < this.cards.length) && !this.cancel; this.update(this.card + 1)) { for (this.update(0); (this.card < this.cards.length) && !this.cancel; this.update(this.card + 1)) {
final String url = this.cards[this.card].getSource();
final File fileDest = this.cards[this.card].getDestination();
final File base = fileDest.getParentFile();
try { try {
final String url = this.cards[this.card].url;
String cName;
cName = this.cards[this.card].getName();
cName = cName.replace("%20", " ");
final File base = new File(this.cards[this.card].dir);
final File f = new File(base, cName);
// test for folder existence // test for folder existence
if (!base.exists()) { if (!base.exists() && !base.mkdir()) { // create folder if not found
// create folder System.out.println("Can't create folder" + base.getAbsolutePath());
if (!base.mkdir()) {
System.out.println("Can't create folder" + this.cards[this.card].dir);
}
} }
try { in = new BufferedInputStream(new URL(url).openConnection(p).getInputStream());
in = new BufferedInputStream(new URL(url).openConnection(p).getInputStream()); out = new BufferedOutputStream(new FileOutputStream(fileDest));
out = new BufferedOutputStream(new FileOutputStream(f));
while ((len = in.read(buf)) != -1) { while ((len = in.read(buf)) != -1) {
// user cancelled // user cancelled
if (this.cancel) { if (this.cancel) {
in.close(); in.close();
out.flush(); out.flush();
out.close(); out.close();
// delete what was written so far // delete what was written so far
f.delete(); fileDest.delete();
return; return;
} // if - cancel } // if - cancel
out.write(buf, 0, len); out.write(buf, 0, len);
} // while - read and write file } // while - read and write file
in.close(); in.close();
out.flush(); out.flush();
out.close(); out.close();
} catch (final ConnectException ce) { } catch (final ConnectException ce) {
System.out.println("Connection refused for url: " + url); System.out.println("Connection refused for url: " + url);
} catch (final MalformedURLException mURLe) { } catch (final MalformedURLException mURLe) {
System.out.println("Error - possibly missing URL for: " + this.cards[this.card].getName()); System.out.println("Error - possibly missing URL for: " + fileDest.getName());
}
} catch (final FileNotFoundException fnfe) { } catch (final FileNotFoundException fnfe) {
System.out.println("Error - the LQ picture for " + this.cards[this.card].getName() String formatStr = "Error - the LQ picture %s could not be found on the server. [%s] - %s";
+ " could not be found on the server. [" + this.cards[this.card].url + "] - " System.out.println(String.format(formatStr, fileDest.getName(), url, fnfe.getMessage()));
+ fnfe.getMessage());
} catch (final Exception ex) { } catch (final Exception ex) {
Log.error("LQ Pictures", "Error downloading pictures", ex); Log.error("LQ Pictures", "Error downloading pictures", ex);
} }
// throttle // throttle -- why?
try { try {
Thread.sleep(r.nextInt(750) + 420); Thread.sleep(r.nextInt(750) + 420);
} catch (final InterruptedException e) { } catch (final InterruptedException e) {
@@ -451,7 +444,7 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
* getNeededCards. * getNeededCards.
* </p> * </p>
* *
* @return an array of {@link forge.GuiDownloader.DownloadObject} objects. * @return an array of {@link forge.gui.download.GuiDownloader.DownloadObject} objects.
*/ */
protected abstract DownloadObject[] getNeededImages(); protected abstract DownloadObject[] getNeededImages();
@@ -460,44 +453,30 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
* readFile. * readFile.
* </p> * </p>
* *
* @param filename * @param urlsFile
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
* @param dir * @param dir
* a {@link java.util.File} object. * a {@link java.util.File} object.
* @return an array of {@link forge.GuiDownloader.DownloadObject} objects. * @return an array of {@link forge.gui.download.GuiDownloader.DownloadObject} objects.
*/ */
protected static DownloadObject[] readFile(final String filename, final File dir) { protected static List<DownloadObject> readFile(final String urlsFile, final File dir) {
try { List<String> fileLines = FileUtil.readFile(ForgeProps.getFile(urlsFile));
final FileReader zrc = new FileReader(ForgeProps.getFile(filename)); final ArrayList<DownloadObject> list = new ArrayList<DownloadObject>();
final BufferedReader in = new BufferedReader(zrc); final Pattern splitter = Pattern.compile(Pattern.quote("/"));
final ArrayList<DownloadObject> list = new ArrayList<DownloadObject>(); final Pattern replacer = Pattern.compile(Pattern.quote("%20"));
for(String line : fileLines)
{
if( line.equals("") || line.startsWith("#")) { continue; }
String line; String[] parts = splitter.split(line);
StringTokenizer tok;
line = in.readLine(); // Maybe there's a better way to do this, but I just want the
while ((line != null) && (!line.equals("")) && !line.startsWith("#")) { // filename from a URL
tok = new StringTokenizer(line, "/"); String last = parts[parts.length-1];
list.add(new DownloadObject(line, new File(dir, replacer.matcher(last).replaceAll(" "))));
// Maybe there's a better way to do this, but I just want the
// filename from a URL
String last = null;
while (tok.hasMoreTokens()) {
last = tok.nextToken();
}
list.add(new DownloadObject(last, line, dir.getPath()));
line = in.readLine();
}
final DownloadObject[] out = new DownloadObject[list.size()];
list.toArray(out);
return out;
} catch (final Exception ex) {
ErrorViewer.showError(ex, "GuiDownloader: readFile() error");
throw new RuntimeException("GuiDownloader : readFile() error");
} }
return list;
} // readFile() } // readFile()
/** /**
@@ -505,51 +484,27 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
* readFile. * readFile.
* </p> * </p>
* *
* @param filename * @param urlNamesFile
* a {@link java.lang.String} object. * a {@link java.lang.String} object.
* @param dir * @param dir
* a {@link java.util.File} object. * a {@link java.util.File} object.
* @return an array of {@link forge.GuiDownloader.DownloadObject} objects. * @return an array of {@link forge.gui.download.GuiDownloader.DownloadObject} objects.
*/ */
protected static DownloadObject[] readFileWithNames(final String filename, final File dir) { protected static ArrayList<DownloadObject> readFileWithNames(final String urlNamesFile, final File dir) {
try { List<String> fileLines = FileUtil.readFile(ForgeProps.getFile(urlNamesFile));
final FileReader zrc = new FileReader(ForgeProps.getFile(filename)); final ArrayList<DownloadObject> list = new ArrayList<DownloadObject>();
final BufferedReader in = new BufferedReader(zrc); final Pattern splitter = Pattern.compile(Pattern.quote(" "));
final ArrayList<DownloadObject> list = new ArrayList<DownloadObject>(); final Pattern replacer = Pattern.compile(Pattern.quote("%20"));
String line; for(String line : fileLines)
StringTokenizer tok; {
if( StringUtils.isBlank(line) || line.startsWith("#")) { continue; }
line = in.readLine(); String[] parts = splitter.split(line, 2);
while ((line != null) && (!line.equals(""))) { String url = parts.length > 1 ? parts[1] : null;
if (line.startsWith("#")) { list.add(new DownloadObject(url, new File(dir, replacer.matcher(parts[0]).replaceAll(" "))));
line = in.readLine();
continue;
}
String name = null;
String url = null;
tok = new StringTokenizer(line, " ");
if (tok.hasMoreTokens()) {
name = tok.nextToken();
}
if (tok.hasMoreTokens()) {
url = tok.nextToken();
}
list.add(new DownloadObject(name, url, dir.getPath()));
line = in.readLine();
}
final DownloadObject[] out = new DownloadObject[list.size()];
list.toArray(out);
return out;
} catch (final Exception ex) {
ErrorViewer.showError(ex, "GuiDownloader: readFile() error");
throw new RuntimeException("GuiDownloader : readFile() error");
} }
return list;
} // readFile() } // readFile()
/** /**
@@ -595,39 +550,21 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
*/ */
protected static class DownloadObject { protected static class DownloadObject {
/** The name. */ private final String source;
private final String name; private final File destination;
/** The url. */ DownloadObject(final String srcUrl, final File destFile) {
private final String url; source = srcUrl;
destination = destFile;
/** The dir. */
private final String dir;
/**
* Instantiates a new download object.
*
* @param nameIn
* the name in
* @param urlIn
* the url in
* @param dirIn
* the dir in
*/
DownloadObject(final String nameIn, final String urlIn, final String dirIn) {
this.name = nameIn;
this.url = urlIn;
this.dir = dirIn;
// System.out.println("Created download object: "+name+" "+url+" "+dir); // System.out.println("Created download object: "+name+" "+url+" "+dir);
} }
/** public String getSource() {
* Gets the name. return source;
* }
* @return the name
*/ public File getDestination() {
public String getName() { return destination;
return this.name;
} }
} // DownloadObject } // DownloadObject
} }

View File

@@ -0,0 +1,3 @@
/** Forge Card Game. */
package forge.gui.download;

View File

@@ -1,12 +1,12 @@
package forge.gui.home.utilities; package forge.gui.home.utilities;
import forge.Command; import forge.Command;
import forge.GuiDownloadPicturesLQ;
import forge.GuiDownloadPrices;
import forge.GuiDownloadQuestImages;
import forge.GuiDownloadSetPicturesLQ;
import forge.GuiImportPicture; import forge.GuiImportPicture;
import forge.error.BugzReporter; import forge.error.BugzReporter;
import forge.gui.download.GuiDownloadPicturesLQ;
import forge.gui.download.GuiDownloadPrices;
import forge.gui.download.GuiDownloadQuestImages;
import forge.gui.download.GuiDownloadSetPicturesLQ;
import forge.gui.home.ICSubmenu; import forge.gui.home.ICSubmenu;
/** /**

View File

@@ -19,6 +19,7 @@ package forge.item;
import net.slightlymagic.braids.util.lambda.Lambda1; import net.slightlymagic.braids.util.lambda.Lambda1;
import forge.ImageCache;
import forge.Singletons; import forge.Singletons;
import forge.card.BoosterData; import forge.card.BoosterData;
import forge.card.CardEdition; import forge.card.CardEdition;
@@ -60,7 +61,7 @@ public class BoosterPack extends OpenablePack {
*/ */
@Override @Override
public final String getImageFilename() { public final String getImageFilename() {
return "booster/" + this.contents.getEdition() + ".png"; return ImageCache.SEALED_PRODUCT + "booster/" + this.contents.getEdition() + ".png";
} }
@Override @Override

View File

@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.slightlymagic.braids.util.lambda.Lambda1; import net.slightlymagic.braids.util.lambda.Lambda1;
import forge.ImageCache;
import forge.Singletons; import forge.Singletons;
import forge.card.CardEdition; import forge.card.CardEdition;
import forge.card.FatPackData; import forge.card.FatPackData;
@@ -56,7 +57,7 @@ public class FatPack extends OpenablePack {
@Override @Override
public final String getImageFilename() { public final String getImageFilename() {
return "fatpacks/" + this.contents.getEdition(); return ImageCache.SEALED_PRODUCT + "fatpacks/" + this.contents.getEdition();
} }

View File

@@ -23,6 +23,7 @@ import java.util.Map;
import net.slightlymagic.braids.util.lambda.Lambda1; import net.slightlymagic.braids.util.lambda.Lambda1;
import forge.ImageCache;
import forge.Singletons; import forge.Singletons;
import forge.deck.Deck; import forge.deck.Deck;
import forge.quest.SellRules; import forge.quest.SellRules;
@@ -59,7 +60,7 @@ public class PreconDeck implements InventoryItemFromSet {
*/ */
@Override @Override
public String getImageFilename() { public String getImageFilename() {
return "precons/" + this.imageFilename; return ImageCache.SEALED_PRODUCT + "precons/" + this.imageFilename;
} }
/* /*

View File

@@ -20,6 +20,7 @@ package forge.item;
import java.util.List; import java.util.List;
import net.slightlymagic.braids.util.lambda.Lambda1; import net.slightlymagic.braids.util.lambda.Lambda1;
import forge.ImageCache;
import forge.Singletons; import forge.Singletons;
import forge.card.BoosterData; import forge.card.BoosterData;
import forge.card.BoosterGenerator; import forge.card.BoosterGenerator;
@@ -53,7 +54,7 @@ public class TournamentPack extends OpenablePack {
@Override @Override
public final String getImageFilename() { public final String getImageFilename() {
return "tournamentpacks/" + this.contents.getEdition(); return ImageCache.SEALED_PRODUCT + "tournamentpacks/" + this.contents.getEdition();
} }

View File

@@ -140,6 +140,7 @@ public final class NewConstants {
public static final String IMAGE_TOKEN = "image/token"; public static final String IMAGE_TOKEN = "image/token";
/** Constant <code>IMAGE_ICON="image/icon"</code>. */ /** Constant <code>IMAGE_ICON="image/icon"</code>. */
public static final String IMAGE_ICON = "image/icon"; public static final String IMAGE_ICON = "image/icon";
public static final String IMAGE_SEALED_PRODUCT = "image/product";
/** Constant <code>PICS_BOOSTER="pics/booster"</code>. */ /** Constant <code>PICS_BOOSTER="pics/booster"</code>. */
public static final String PICS_BOOSTER = "pics/booster"; public static final String PICS_BOOSTER = "pics/booster";
/** Constant <code>PICS_BOOSTER_IMAGES="pics/booster/images"</code>. */ /** Constant <code>PICS_BOOSTER_IMAGES="pics/booster/images"</code>. */
@@ -147,6 +148,8 @@ public final class NewConstants {
/** Constant <code>SOUND_BASE="sound/base"</code>. */ /** Constant <code>SOUND_BASE="sound/base"</code>. */
public static final String SOUND_BASE = "sound/base"; public static final String SOUND_BASE = "sound/base";
/** /**
* These properties are for a regular game. * These properties are for a regular game.
*/ */

View File

@@ -2,6 +2,8 @@ package forge;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import forge.gui.download.GuiDownloadPicturesLQ;
/** /**
* Created by IntelliJ IDEA. User: dhudson * Created by IntelliJ IDEA. User: dhudson
*/ */

View File

@@ -2,6 +2,8 @@ package forge;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import forge.gui.download.GuiDownloadSetPicturesLQ;
/** /**
* Created by IntelliJ IDEA. User: dhudson * Created by IntelliJ IDEA. User: dhudson
*/ */