download .fullborder images if .full is not found

This commit is contained in:
Anthony Calosa
2020-08-21 23:41:48 +08:00
parent b62a38ec32
commit 35b6a99f10

View File

@@ -36,6 +36,7 @@ import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import forge.util.TextUtil;
import org.apache.commons.lang3.tuple.Pair;
import com.esotericsoftware.minlog.Log;
@@ -257,6 +258,7 @@ public abstract class GuiDownloadService implements Runnable {
for (Entry<String, String> kv : files.entrySet()) {
boolean isJPG = true;
boolean isLogged = false;
boolean fullborder = false;
if (cancel) {//stop prevent sleep
GuiBase.getInterface().preventSystemSleep(false);
break; }
@@ -266,7 +268,7 @@ public abstract class GuiDownloadService implements Runnable {
String url = kv.getValue();
String decodedKey = decodeURL(kv.getKey());
final File fileDest = new File(decodedKey);
File fileDest = new File(decodedKey);
final String filePath = fileDest.getPath();
final String subLastIndex = filePath.contains("pics") ? "\\pics\\" : "\\db\\";
@@ -288,9 +290,22 @@ public abstract class GuiDownloadService implements Runnable {
}
conn.connect();
//if .full file is not found try fullborder
if ((conn.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) && (url.contains(".full.jpg")))
{
fullborder = true;
conn.disconnect();
url = TextUtil.fastReplace(url, ".full.jpg", ".fullborder.jpg");
imageUrl = new URL(url);
conn = (HttpURLConnection) imageUrl.openConnection(p);
conn.setInstanceFollowRedirects(false);
conn.connect();
}
// if file is not found and this is a JPG, give PNG a shot...
if ((conn.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) && (url.endsWith(".jpg")))
{
fullborder = false;
isJPG = false;
conn.disconnect();
if(url.contains("/images/")){
@@ -304,6 +319,10 @@ public abstract class GuiDownloadService implements Runnable {
conn.connect();
}
if (fullborder) {
fileDest = new File(TextUtil.fastReplace(decodedKey, ".full.jpg", ".fullborder.jpg"));
}
switch (conn.getResponseCode()) {
case HttpURLConnection.HTTP_OK:
fos = new FileOutputStream(fileDest);