Downloading images according to save_to_zip option

This commit is contained in:
magenoxx 2012-10-23 17:10:56 +04:00
parent 789ed428b7
commit 10ba5c2e72
5 changed files with 73 additions and 22 deletions

View file

@ -457,6 +457,9 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
File temporaryFile = new File(Constants.IO.imageBaseDir + File.separator + card.hashCode() + "." + card.getName() + ".jpg");
String imagePath = CardImageUtils.getImagePath(card, imagesPath);
TFile outputFile = new TFile(imagePath);
if (!outputFile.exists()) {
outputFile.getParentFile().mkdirs();
}
File existingFile = new File(imagePath.replaceFirst("\\w{3}.zip", ""));
if (existingFile.exists()) {
new TFile(existingFile).cp_rp(outputFile);

View file

@ -7,16 +7,18 @@ import com.mortennobel.imagescaling.ResampleOp;
import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.file.TFileInputStream;
import de.schlichtherle.truezip.file.TFileOutputStream;
import mage.client.dialog.PreferencesDialog;
import mage.view.CardView;
import org.apache.log4j.Logger;
import org.mage.plugins.card.constants.Constants;
import org.mage.plugins.card.utils.CardImageUtils;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import mage.view.CardView;
import org.apache.log4j.Logger;
import org.mage.plugins.card.constants.Constants;
import org.mage.plugins.card.utils.CardImageUtils;
/**
* This class stores ALL card images in a cache with soft values. this means
@ -76,7 +78,7 @@ public class ImageCache {
TFile file = new TFile(path);
if (thumbnail && path.endsWith(".jpg")) {
String thumbnailPath = path.replace(".zip", ".thumb.zip");
String thumbnailPath = buildThumbnailPath(path);
TFile thumbnailFile = new TFile(thumbnailPath);
if (thumbnailFile.exists()) {
//log.debug("loading thumbnail for " + key + ", path="+thumbnailPath);
@ -107,6 +109,16 @@ public class ImageCache {
}
});
}
private static String buildThumbnailPath(String path) {
String thumbnailPath;
if (PreferencesDialog.isSaveImagesToZip()) {
thumbnailPath = path.replace(".zip", ".thumb.zip");
} else {
thumbnailPath = path.replace(".jpg", ".thumb.jpg");
}
return thumbnailPath;
}
public static BufferedImage getWizardsCard(BufferedImage image) {
if (image.getWidth() == 265 && image.getHeight() == 370) {

View file

@ -1,12 +1,14 @@
package org.mage.plugins.card.utils;
import de.schlichtherle.truezip.file.TFile;
import java.util.HashMap;
import java.util.regex.Pattern;
import mage.client.dialog.PreferencesDialog;
import org.mage.plugins.card.constants.Constants;
import org.mage.plugins.card.images.CardInfo;
import org.mage.plugins.card.properties.SettingsManager;
import java.util.HashMap;
import java.util.regex.Pattern;
public class CardImageUtils {
private static final Pattern basicLandPattern = Pattern.compile("^(Forest|Mountain|Swamp|Island|Plains)$");
@ -104,9 +106,25 @@ public class CardImageUtils {
String set = updateSet(card.getSet(), false).toUpperCase();
String imagesDir = (imagesPath != null ? imagesPath : Constants.IO.imageBaseDir);
if (card.isToken()) {
return buildTokenPath(imagesDir, set);
} else {
return buildPath(imagesDir, set);
}
}
private static String buildTokenPath(String imagesDir, String set) {
if (PreferencesDialog.isSaveImagesToZip()) {
return imagesDir + TFile.separator + "TOK" + ".zip" + TFile.separator + set;
} else {
return imagesDir + TFile.separator + "TOK" + TFile.separator + set;
}
}
private static String buildPath(String imagesDir, String set) {
if (PreferencesDialog.isSaveImagesToZip()) {
return imagesDir + TFile.separator + set + ".zip" + TFile.separator + set;
} else {
return imagesDir + TFile.separator + set;
}
}