mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 02:38:02 +00:00
update mobile image fetcher for fullborder downloads
This commit is contained in:
@@ -7,6 +7,7 @@ import forge.GuiBase;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
public class LibGDXImageFetcher extends ImageFetcher {
|
public class LibGDXImageFetcher extends ImageFetcher {
|
||||||
@@ -27,6 +28,8 @@ public class LibGDXImageFetcher extends ImageFetcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void doFetch(String urlToDownload) throws IOException {
|
private void doFetch(String urlToDownload) throws IOException {
|
||||||
|
String newdespath = urlToDownload.contains(".fullborder.jpg") ?
|
||||||
|
TextUtil.fastReplace(destPath, ".full.jpg", ".fullborder.jpg") : destPath;
|
||||||
URL url = new URL(urlToDownload);
|
URL url = new URL(urlToDownload);
|
||||||
System.out.println("Attempting to fetch: " + url);
|
System.out.println("Attempting to fetch: " + url);
|
||||||
java.net.URLConnection c = url.openConnection();
|
java.net.URLConnection c = url.openConnection();
|
||||||
@@ -35,22 +38,40 @@ public class LibGDXImageFetcher extends ImageFetcher {
|
|||||||
InputStream is = c.getInputStream();
|
InputStream is = c.getInputStream();
|
||||||
// First, save to a temporary file so that nothing tries to read
|
// First, save to a temporary file so that nothing tries to read
|
||||||
// a partial download.
|
// a partial download.
|
||||||
FileHandle destFile = new FileHandle(destPath + ".tmp");
|
FileHandle destFile = new FileHandle(newdespath + ".tmp");
|
||||||
System.out.println(destPath);
|
System.out.println(newdespath);
|
||||||
destFile.parent().mkdirs();
|
destFile.parent().mkdirs();
|
||||||
|
|
||||||
// Conversion to JPEG will be handled differently depending on the platform
|
// Conversion to JPEG will be handled differently depending on the platform
|
||||||
Forge.getDeviceAdapter().convertToJPEG(is, new FileOutputStream(destFile.file()));
|
Forge.getDeviceAdapter().convertToJPEG(is, new FileOutputStream(destFile.file()));
|
||||||
destFile.moveTo(new FileHandle(destPath));
|
destFile.moveTo(new FileHandle(newdespath));
|
||||||
|
|
||||||
System.out.println("Saved image to " + destPath);
|
System.out.println("Saved image to " + newdespath);
|
||||||
GuiBase.getInterface().invokeInEdtLater(notifyObservers);
|
GuiBase.getInterface().invokeInEdtLater(notifyObservers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String tofullBorder(String imageurl) {
|
||||||
|
if (!imageurl.contains(".full.jpg"))
|
||||||
|
return imageurl;
|
||||||
|
try {
|
||||||
|
URL url = new URL(imageurl);
|
||||||
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
|
//connection.setConnectTimeout(1000 * 5); //wait 5 seconds the most
|
||||||
|
//connection.setReadTimeout(1000 * 5);
|
||||||
|
conn.setRequestProperty("User-Agent", "");
|
||||||
|
if(conn.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND)
|
||||||
|
imageurl = TextUtil.fastReplace(imageurl, ".full.jpg", ".fullborder.jpg");
|
||||||
|
conn.disconnect();
|
||||||
|
return imageurl;
|
||||||
|
} catch (IOException ex) {
|
||||||
|
return imageurl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
for (String urlToDownload : downloadUrls) {
|
for (String urlToDownload : downloadUrls) {
|
||||||
try {
|
try {
|
||||||
doFetch(urlToDownload);
|
doFetch(tofullBorder(urlToDownload));
|
||||||
break;
|
break;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Failed to download card [" + destPath + "] image: " + e.getMessage());
|
System.out.println("Failed to download card [" + destPath + "] image: " + e.getMessage());
|
||||||
|
|||||||
Reference in New Issue
Block a user