From 35b6a99f108e97903f32b9d105fd044b0a74e659 Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Fri, 21 Aug 2020 23:41:48 +0800 Subject: [PATCH] download .fullborder images if .full is not found --- .../forge/download/GuiDownloadService.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/forge-gui/src/main/java/forge/download/GuiDownloadService.java b/forge-gui/src/main/java/forge/download/GuiDownloadService.java index 4e72ae2842d..8667a34b0d7 100644 --- a/forge-gui/src/main/java/forge/download/GuiDownloadService.java +++ b/forge-gui/src/main/java/forge/download/GuiDownloadService.java @@ -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 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\\"; @@ -287,10 +289,23 @@ public abstract class GuiDownloadService implements Runnable { conn.setInstanceFollowRedirects(false); } 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/")){ @@ -303,7 +318,11 @@ public abstract class GuiDownloadService implements Runnable { conn.setInstanceFollowRedirects(false); 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);