mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
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:
11
.gitattributes
vendored
11
.gitattributes
vendored
@@ -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/GameLog.java -text
|
||||
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/GuiInput.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/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/CardPanel.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/game/CardPicturePanel.java svneol=native#text/plain
|
||||
|
||||
@@ -17,13 +17,11 @@
|
||||
*/
|
||||
package forge;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
@@ -51,7 +49,6 @@ import forge.card.replacement.ReplacementHandler;
|
||||
import forge.card.trigger.TriggerHandler;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.gui.toolbox.FProgressBar;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.LineReader;
|
||||
import forge.view.SplashFrame;
|
||||
|
||||
@@ -386,7 +383,7 @@ public class CardReader implements Runnable {
|
||||
for(String line : lines ) {
|
||||
line = line.trim();
|
||||
|
||||
if("End".equals(line)) { ignoreTheRest = true; continue; }
|
||||
if("End".equals(line)) { ignoreTheRest = true; }
|
||||
if(ignoreTheRest) { continue; } // have to deplete the iterator
|
||||
// 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);
|
||||
card.setSVar(value[1], value[2]);
|
||||
} else if (line.startsWith("A:")) {
|
||||
final String value = line.substring(2);
|
||||
card.addIntrinsicAbility(value);
|
||||
card.addIntrinsicAbility(line.substring(2));
|
||||
} else if (line.startsWith("T:")) {
|
||||
final String value = line.substring(2);
|
||||
card.addTrigger(TriggerHandler.parseTrigger(value, card, true));
|
||||
card.addTrigger(TriggerHandler.parseTrigger(line.substring(2), card, true));
|
||||
} else if (line.startsWith("S:")) {
|
||||
final String value = line.substring(2);
|
||||
card.addStaticAbilityString(value);
|
||||
card.addStaticAbilityString(line.substring(2));
|
||||
} else if (line.startsWith("R:")) {
|
||||
final String value = line.substring(2);
|
||||
card.addReplacementEffect(ReplacementHandler.parseReplacement(value, card));
|
||||
card.addReplacementEffect(ReplacementHandler.parseReplacement(line.substring(2), card));
|
||||
} else if (line.startsWith("SetInfo:")) {
|
||||
final String value = line.substring("SetInfo:".length());
|
||||
card.addSet(new EditionInfo(value));
|
||||
|
||||
@@ -64,13 +64,10 @@ public class ImageCache {
|
||||
private static final LoadingCache<String, BufferedImage> IMAGE_CACHE;
|
||||
/** Constant <code>FULL_SIZE</code>. */
|
||||
private static final Pattern FULL_SIZE = Pattern.compile("(.*)#(\\d+.\\d+)");
|
||||
/** Constant <code>TOKEN="#Token"</code> */
|
||||
/** Constant <code>NORMAL="#Normal"</code> */
|
||||
/** Constant <code>TAPPED="#Tapped"</code> */
|
||||
/** Constant <code>NORMAL="#Normal"</code> */
|
||||
/** Constant <code>TAPPED="#Tapped"</code>. */
|
||||
private static final String TOKEN = "#Token", NORMAL = "#Normal", TAPPED = "#Tapped";
|
||||
private static final String SEALED_PRODUCT = "sealed://";
|
||||
|
||||
private static final String NORMAL = "#Normal", TAPPED = "#Tapped";
|
||||
public static final String SEALED_PRODUCT = "sealed://";
|
||||
private static final String TOKEN = "token://";
|
||||
|
||||
static {
|
||||
IMAGE_CACHE = CacheBuilder.newBuilder()
|
||||
@@ -108,12 +105,12 @@ public class ImageCache {
|
||||
} else {
|
||||
// original
|
||||
File path;
|
||||
if (key.endsWith(ImageCache.TOKEN)) {
|
||||
key = key.substring(0, key.length() - ImageCache.TOKEN.length());
|
||||
if (key.startsWith(ImageCache.TOKEN)) {
|
||||
key = key.substring(ImageCache.TOKEN.length());
|
||||
path = ForgeProps.getFile(NewConstants.IMAGE_TOKEN);
|
||||
} else if (key.startsWith(SEALED_PRODUCT)) {
|
||||
key = key.substring(SEALED_PRODUCT.length());
|
||||
path = ForgeProps.getFile(NewConstants.IMAGE_BASE);
|
||||
path = ForgeProps.getFile(NewConstants.IMAGE_SEALED_PRODUCT);
|
||||
} else {
|
||||
path = ForgeProps.getFile(NewConstants.IMAGE_BASE);
|
||||
}
|
||||
@@ -300,7 +297,7 @@ public class ImageCache {
|
||||
private static String getKey(final Card card) {
|
||||
|
||||
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;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge;
|
||||
package forge.gui.download;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@@ -23,6 +23,9 @@ import java.util.List;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.Card;
|
||||
import forge.GuiDisplayUtil;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
|
||||
@@ -55,13 +58,11 @@ public class GuiDownloadPicturesLQ extends GuiDownloader {
|
||||
* getNeededCards.
|
||||
* </p>
|
||||
*
|
||||
* @return an array of {@link forge.GuiDownloader.DownloadObject} objects.
|
||||
* @return an array of {@link forge.gui.download.GuiDownloader.DownloadObject} objects.
|
||||
*/
|
||||
@Override
|
||||
protected final DownloadObject[] getNeededImages() {
|
||||
// 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 String base = ForgeProps.getFile(NewConstants.IMAGE_BASE).getPath();
|
||||
@@ -70,32 +71,23 @@ public class GuiDownloadPicturesLQ extends GuiDownloader {
|
||||
}
|
||||
|
||||
final ArrayList<DownloadObject> list = new ArrayList<DownloadObject>();
|
||||
File file;
|
||||
|
||||
final DownloadObject[] a = { new DownloadObject("", "", "") };
|
||||
final DownloadObject[] cardPlay = cList.toArray(a);
|
||||
// check to see which cards we already have
|
||||
for (final DownloadObject element : cardPlay) {
|
||||
file = new File(base, element.getName());
|
||||
if (!file.exists()) {
|
||||
for (final DownloadObject element : cList) {
|
||||
if (!element.getDestination().exists()) {
|
||||
list.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
// add missing tokens to the list of things to download
|
||||
final File filebase = ForgeProps.getFile(NewConstants.IMAGE_TOKEN);
|
||||
for (final DownloadObject element : cardTokenLQ) {
|
||||
file = new File(filebase, element.getName());
|
||||
if (!file.exists()) {
|
||||
for (final DownloadObject element : GuiDownloader.readFileWithNames(NewConstants.TOKEN_IMAGES,
|
||||
ForgeProps.getFile(NewConstants.IMAGE_TOKEN))) {
|
||||
if (!element.getDestination().exists()) {
|
||||
list.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
// return all card names and urls that are needed
|
||||
final DownloadObject[] out = new DownloadObject[list.size()];
|
||||
list.toArray(out);
|
||||
|
||||
return out;
|
||||
return list.toArray(new DownloadObject[list.size()]);
|
||||
} // getNeededImages()
|
||||
|
||||
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 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++) {
|
||||
ret.add(new DownloadObject(iName + j + ".jpg", urls[j], base));
|
||||
}
|
||||
for (int j = 1; j < urls.length; j++) {
|
||||
ret.add(new DownloadObject(urls[j], new File(base, iName + j + ".jpg")));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge;
|
||||
package forge.gui.download;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.io.BufferedInputStream;
|
||||
@@ -15,10 +15,11 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge;
|
||||
package forge.gui.download;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
@@ -53,50 +54,33 @@ public class GuiDownloadQuestImages extends GuiDownloader {
|
||||
* getNeededCards.
|
||||
* </p>
|
||||
*
|
||||
* @return an array of {@link forge.GuiDownloadSetPicturesLQ} objects.
|
||||
* @return an array of {@link forge.gui.download.GuiDownloadSetPicturesLQ} objects.
|
||||
*/
|
||||
@Override
|
||||
protected final DownloadObject[] getNeededImages() {
|
||||
// read all card names and urls
|
||||
final DownloadObject[] questOpponents = GuiDownloader.readFile(NewConstants.Quest.OPPONENT_ICONS,
|
||||
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>();
|
||||
final List<DownloadObject> urls = new ArrayList<DownloadObject>();
|
||||
|
||||
File file;
|
||||
File dir = ForgeProps.getFile(NewConstants.Quest.OPPONENT_DIR);
|
||||
for (final DownloadObject questOpponent : questOpponents) {
|
||||
file = new File(dir, questOpponent.getName().replace("%20", " "));
|
||||
if (!file.exists()) {
|
||||
for (final DownloadObject questOpponent : GuiDownloader.readFile(NewConstants.Quest.OPPONENT_ICONS, ForgeProps.getFile(NewConstants.Quest.OPPONENT_DIR))) {
|
||||
if (!questOpponent.getDestination().exists()) {
|
||||
urls.add(questOpponent);
|
||||
}
|
||||
}
|
||||
|
||||
dir = ForgeProps.getFile(NewConstants.PICS_BOOSTER);
|
||||
for (final DownloadObject boosterImage : boosterImages) {
|
||||
file = new File(dir, boosterImage.getName().replace("%20", " "));
|
||||
if (!file.exists()) {
|
||||
for (final DownloadObject boosterImage : GuiDownloader.readFile(NewConstants.PICS_BOOSTER_IMAGES, ForgeProps.getFile(NewConstants.IMAGE_SEALED_PRODUCT))) {
|
||||
if (!boosterImage.getDestination().exists()) {
|
||||
urls.add(boosterImage);
|
||||
}
|
||||
}
|
||||
|
||||
dir = ForgeProps.getFile(NewConstants.IMAGE_ICON);
|
||||
for (final DownloadObject petIcon : petIcons) {
|
||||
file = new File(dir, petIcon.getName().replace("%20", " "));
|
||||
if (!file.exists()) {
|
||||
for (final DownloadObject petIcon : GuiDownloader.readFileWithNames(NewConstants.Quest.PET_SHOP_ICONS, ForgeProps.getFile(NewConstants.IMAGE_ICON))) {
|
||||
if (!petIcon.getDestination().exists()) {
|
||||
urls.add(petIcon);
|
||||
}
|
||||
}
|
||||
|
||||
dir = ForgeProps.getFile(NewConstants.IMAGE_TOKEN);
|
||||
for (final DownloadObject questPet : questPets) {
|
||||
file = new File(dir, questPet.getName().replace("%20", " "));
|
||||
if (!file.exists()) {
|
||||
for (final DownloadObject questPet : GuiDownloader.readFileWithNames(NewConstants.Quest.PET_TOKEN_IMAGES, ForgeProps.getFile(NewConstants.IMAGE_TOKEN))) {
|
||||
if (!questPet.getDestination().exists()) {
|
||||
urls.add(questPet);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge;
|
||||
package forge.gui.download;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@@ -24,6 +24,8 @@ import javax.swing.JFrame;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.CardUtil;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardEdition;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
@@ -82,9 +84,10 @@ public class GuiDownloadSetPicturesLQ extends GuiDownloader {
|
||||
}
|
||||
if (!foundSetImage) {
|
||||
final int artsCnt = c.getCard().getEditionInfo(setCode3).getCopiesCount();
|
||||
final String fn = CardUtil.buildIdealFilename(cardName, c.getArtIndex(), artsCnt);
|
||||
cList.add(new DownloadObject(fn, urlBase + setCode2 + "/" + Base64Coder.encodeString(fn, true),
|
||||
this.picturesPath + File.separator + setCode3));
|
||||
final String filename = CardUtil.buildIdealFilename(cardName, c.getArtIndex(), artsCnt);
|
||||
String url = urlBase + setCode2 + "/" + Base64Coder.encodeString(filename, true);
|
||||
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()));
|
||||
}
|
||||
}
|
||||
@@ -94,7 +97,7 @@ public class GuiDownloadSetPicturesLQ extends GuiDownloader {
|
||||
* getNeededCards.
|
||||
* </p>
|
||||
*
|
||||
* @return an array of {@link forge.GuiDownloader.DownloadObject} objects.
|
||||
* @return an array of {@link forge.gui.download.GuiDownloader.DownloadObject} objects.
|
||||
*/
|
||||
@Override
|
||||
protected final DownloadObject[] getNeededImages() {
|
||||
@@ -102,8 +105,6 @@ public class GuiDownloadSetPicturesLQ extends GuiDownloader {
|
||||
this.picturesPath = ForgeProps.getFile(NewConstants.IMAGE_BASE).getPath();
|
||||
}
|
||||
// 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>();
|
||||
|
||||
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
|
||||
File file;
|
||||
final File filebase = ForgeProps.getFile(NewConstants.IMAGE_TOKEN);
|
||||
for (final DownloadObject element : cardTokenLQ) {
|
||||
file = new File(filebase, element.getName());
|
||||
if (!file.exists()) {
|
||||
for (final DownloadObject element : GuiDownloader.readFileWithNames(NewConstants.TOKEN_IMAGES, ForgeProps.getFile(NewConstants.IMAGE_TOKEN))) {
|
||||
if (!element.getDestination().exists()) {
|
||||
cList.add(element);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.EventQueue;
|
||||
@@ -23,19 +23,18 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.net.ConnectException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.Box;
|
||||
@@ -53,11 +52,14 @@ import javax.swing.JTextField;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
/**
|
||||
@@ -382,60 +384,51 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
|
||||
final byte[] buf = new byte[1024];
|
||||
int len;
|
||||
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 {
|
||||
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
|
||||
if (!base.exists()) {
|
||||
// create folder
|
||||
if (!base.mkdir()) {
|
||||
System.out.println("Can't create folder" + this.cards[this.card].dir);
|
||||
}
|
||||
if (!base.exists() && !base.mkdir()) { // create folder if not found
|
||||
System.out.println("Can't create folder" + base.getAbsolutePath());
|
||||
}
|
||||
|
||||
try {
|
||||
in = new BufferedInputStream(new URL(url).openConnection(p).getInputStream());
|
||||
out = new BufferedOutputStream(new FileOutputStream(f));
|
||||
in = new BufferedInputStream(new URL(url).openConnection(p).getInputStream());
|
||||
out = new BufferedOutputStream(new FileOutputStream(fileDest));
|
||||
|
||||
while ((len = in.read(buf)) != -1) {
|
||||
// user cancelled
|
||||
if (this.cancel) {
|
||||
in.close();
|
||||
out.flush();
|
||||
out.close();
|
||||
while ((len = in.read(buf)) != -1) {
|
||||
// user cancelled
|
||||
if (this.cancel) {
|
||||
in.close();
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
// delete what was written so far
|
||||
f.delete();
|
||||
// delete what was written so far
|
||||
fileDest.delete();
|
||||
|
||||
return;
|
||||
} // if - cancel
|
||||
return;
|
||||
} // if - cancel
|
||||
|
||||
out.write(buf, 0, len);
|
||||
} // while - read and write file
|
||||
out.write(buf, 0, len);
|
||||
} // while - read and write file
|
||||
|
||||
in.close();
|
||||
out.flush();
|
||||
out.close();
|
||||
} catch (final ConnectException ce) {
|
||||
System.out.println("Connection refused for url: " + url);
|
||||
} catch (final MalformedURLException mURLe) {
|
||||
System.out.println("Error - possibly missing URL for: " + this.cards[this.card].getName());
|
||||
}
|
||||
in.close();
|
||||
out.flush();
|
||||
out.close();
|
||||
} catch (final ConnectException ce) {
|
||||
System.out.println("Connection refused for url: " + url);
|
||||
} catch (final MalformedURLException mURLe) {
|
||||
System.out.println("Error - possibly missing URL for: " + fileDest.getName());
|
||||
} catch (final FileNotFoundException fnfe) {
|
||||
System.out.println("Error - the LQ picture for " + this.cards[this.card].getName()
|
||||
+ " could not be found on the server. [" + this.cards[this.card].url + "] - "
|
||||
+ fnfe.getMessage());
|
||||
String formatStr = "Error - the LQ picture %s could not be found on the server. [%s] - %s";
|
||||
System.out.println(String.format(formatStr, fileDest.getName(), url, fnfe.getMessage()));
|
||||
} catch (final Exception ex) {
|
||||
Log.error("LQ Pictures", "Error downloading pictures", ex);
|
||||
}
|
||||
|
||||
// throttle
|
||||
// throttle -- why?
|
||||
try {
|
||||
Thread.sleep(r.nextInt(750) + 420);
|
||||
} catch (final InterruptedException e) {
|
||||
@@ -451,7 +444,7 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
|
||||
* getNeededCards.
|
||||
* </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();
|
||||
|
||||
@@ -460,44 +453,30 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
|
||||
* readFile.
|
||||
* </p>
|
||||
*
|
||||
* @param filename
|
||||
* @param urlsFile
|
||||
* a {@link java.lang.String} object.
|
||||
* @param dir
|
||||
* 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) {
|
||||
try {
|
||||
final FileReader zrc = new FileReader(ForgeProps.getFile(filename));
|
||||
final BufferedReader in = new BufferedReader(zrc);
|
||||
final ArrayList<DownloadObject> list = new ArrayList<DownloadObject>();
|
||||
protected static List<DownloadObject> readFile(final String urlsFile, final File dir) {
|
||||
List<String> fileLines = FileUtil.readFile(ForgeProps.getFile(urlsFile));
|
||||
final ArrayList<DownloadObject> list = new ArrayList<DownloadObject>();
|
||||
final Pattern splitter = Pattern.compile(Pattern.quote("/"));
|
||||
final Pattern replacer = Pattern.compile(Pattern.quote("%20"));
|
||||
|
||||
String line;
|
||||
StringTokenizer tok;
|
||||
for(String line : fileLines)
|
||||
{
|
||||
if( line.equals("") || line.startsWith("#")) { continue; }
|
||||
|
||||
line = in.readLine();
|
||||
while ((line != null) && (!line.equals("")) && !line.startsWith("#")) {
|
||||
tok = new StringTokenizer(line, "/");
|
||||
String[] parts = splitter.split(line);
|
||||
|
||||
// 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");
|
||||
// Maybe there's a better way to do this, but I just want the
|
||||
// filename from a URL
|
||||
String last = parts[parts.length-1];
|
||||
list.add(new DownloadObject(line, new File(dir, replacer.matcher(last).replaceAll(" "))));
|
||||
}
|
||||
return list;
|
||||
} // readFile()
|
||||
|
||||
/**
|
||||
@@ -505,51 +484,27 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
|
||||
* readFile.
|
||||
* </p>
|
||||
*
|
||||
* @param filename
|
||||
* @param urlNamesFile
|
||||
* a {@link java.lang.String} object.
|
||||
* @param dir
|
||||
* 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) {
|
||||
try {
|
||||
final FileReader zrc = new FileReader(ForgeProps.getFile(filename));
|
||||
final BufferedReader in = new BufferedReader(zrc);
|
||||
final ArrayList<DownloadObject> list = new ArrayList<DownloadObject>();
|
||||
protected static ArrayList<DownloadObject> readFileWithNames(final String urlNamesFile, final File dir) {
|
||||
List<String> fileLines = FileUtil.readFile(ForgeProps.getFile(urlNamesFile));
|
||||
final ArrayList<DownloadObject> list = new ArrayList<DownloadObject>();
|
||||
final Pattern splitter = Pattern.compile(Pattern.quote(" "));
|
||||
final Pattern replacer = Pattern.compile(Pattern.quote("%20"));
|
||||
|
||||
String line;
|
||||
StringTokenizer tok;
|
||||
|
||||
line = in.readLine();
|
||||
while ((line != null) && (!line.equals(""))) {
|
||||
if (line.startsWith("#")) {
|
||||
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");
|
||||
for(String line : fileLines)
|
||||
{
|
||||
if( StringUtils.isBlank(line) || line.startsWith("#")) { continue; }
|
||||
String[] parts = splitter.split(line, 2);
|
||||
String url = parts.length > 1 ? parts[1] : null;
|
||||
list.add(new DownloadObject(url, new File(dir, replacer.matcher(parts[0]).replaceAll(" "))));
|
||||
}
|
||||
|
||||
return list;
|
||||
} // readFile()
|
||||
|
||||
/**
|
||||
@@ -595,39 +550,21 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
|
||||
*/
|
||||
protected static class DownloadObject {
|
||||
|
||||
/** The name. */
|
||||
private final String name;
|
||||
private final String source;
|
||||
private final File destination;
|
||||
|
||||
/** The url. */
|
||||
private final String url;
|
||||
|
||||
/** 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;
|
||||
DownloadObject(final String srcUrl, final File destFile) {
|
||||
source = srcUrl;
|
||||
destination = destFile;
|
||||
// System.out.println("Created download object: "+name+" "+url+" "+dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public File getDestination() {
|
||||
return destination;
|
||||
}
|
||||
} // DownloadObject
|
||||
}
|
||||
3
src/main/java/forge/gui/download/package-info.java
Normal file
3
src/main/java/forge/gui/download/package-info.java
Normal file
@@ -0,0 +1,3 @@
|
||||
/** Forge Card Game. */
|
||||
package forge.gui.download;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package forge.gui.home.utilities;
|
||||
|
||||
import forge.Command;
|
||||
import forge.GuiDownloadPicturesLQ;
|
||||
import forge.GuiDownloadPrices;
|
||||
import forge.GuiDownloadQuestImages;
|
||||
import forge.GuiDownloadSetPicturesLQ;
|
||||
import forge.GuiImportPicture;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,6 +19,7 @@ package forge.item;
|
||||
|
||||
|
||||
import net.slightlymagic.braids.util.lambda.Lambda1;
|
||||
import forge.ImageCache;
|
||||
import forge.Singletons;
|
||||
import forge.card.BoosterData;
|
||||
import forge.card.CardEdition;
|
||||
@@ -60,7 +61,7 @@ public class BoosterPack extends OpenablePack {
|
||||
*/
|
||||
@Override
|
||||
public final String getImageFilename() {
|
||||
return "booster/" + this.contents.getEdition() + ".png";
|
||||
return ImageCache.SEALED_PRODUCT + "booster/" + this.contents.getEdition() + ".png";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.slightlymagic.braids.util.lambda.Lambda1;
|
||||
import forge.ImageCache;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.FatPackData;
|
||||
@@ -56,7 +57,7 @@ public class FatPack extends OpenablePack {
|
||||
|
||||
@Override
|
||||
public final String getImageFilename() {
|
||||
return "fatpacks/" + this.contents.getEdition();
|
||||
return ImageCache.SEALED_PRODUCT + "fatpacks/" + this.contents.getEdition();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Map;
|
||||
|
||||
import net.slightlymagic.braids.util.lambda.Lambda1;
|
||||
|
||||
import forge.ImageCache;
|
||||
import forge.Singletons;
|
||||
import forge.deck.Deck;
|
||||
import forge.quest.SellRules;
|
||||
@@ -59,7 +60,7 @@ public class PreconDeck implements InventoryItemFromSet {
|
||||
*/
|
||||
@Override
|
||||
public String getImageFilename() {
|
||||
return "precons/" + this.imageFilename;
|
||||
return ImageCache.SEALED_PRODUCT + "precons/" + this.imageFilename;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -20,6 +20,7 @@ package forge.item;
|
||||
import java.util.List;
|
||||
|
||||
import net.slightlymagic.braids.util.lambda.Lambda1;
|
||||
import forge.ImageCache;
|
||||
import forge.Singletons;
|
||||
import forge.card.BoosterData;
|
||||
import forge.card.BoosterGenerator;
|
||||
@@ -53,7 +54,7 @@ public class TournamentPack extends OpenablePack {
|
||||
|
||||
@Override
|
||||
public final String getImageFilename() {
|
||||
return "tournamentpacks/" + this.contents.getEdition();
|
||||
return ImageCache.SEALED_PRODUCT + "tournamentpacks/" + this.contents.getEdition();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -140,6 +140,7 @@ public final class NewConstants {
|
||||
public static final String IMAGE_TOKEN = "image/token";
|
||||
/** Constant <code>IMAGE_ICON="image/icon"</code>. */
|
||||
public static final String IMAGE_ICON = "image/icon";
|
||||
public static final String IMAGE_SEALED_PRODUCT = "image/product";
|
||||
/** Constant <code>PICS_BOOSTER="pics/booster"</code>. */
|
||||
public static final String PICS_BOOSTER = "pics/booster";
|
||||
/** Constant <code>PICS_BOOSTER_IMAGES="pics/booster/images"</code>. */
|
||||
@@ -147,6 +148,8 @@ public final class NewConstants {
|
||||
/** Constant <code>SOUND_BASE="sound/base"</code>. */
|
||||
public static final String SOUND_BASE = "sound/base";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* These properties are for a regular game.
|
||||
*/
|
||||
|
||||
@@ -2,6 +2,8 @@ package forge;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import forge.gui.download.GuiDownloadPicturesLQ;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA. User: dhudson
|
||||
*/
|
||||
|
||||
@@ -2,6 +2,8 @@ package forge;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import forge.gui.download.GuiDownloadSetPicturesLQ;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA. User: dhudson
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user