mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-14 17:58:01 +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.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
public class LibGDXImageFetcher extends ImageFetcher {
|
||||
@@ -27,6 +28,8 @@ public class LibGDXImageFetcher extends ImageFetcher {
|
||||
}
|
||||
|
||||
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);
|
||||
System.out.println("Attempting to fetch: " + url);
|
||||
java.net.URLConnection c = url.openConnection();
|
||||
@@ -35,22 +38,40 @@ public class LibGDXImageFetcher extends ImageFetcher {
|
||||
InputStream is = c.getInputStream();
|
||||
// First, save to a temporary file so that nothing tries to read
|
||||
// a partial download.
|
||||
FileHandle destFile = new FileHandle(destPath + ".tmp");
|
||||
System.out.println(destPath);
|
||||
FileHandle destFile = new FileHandle(newdespath + ".tmp");
|
||||
System.out.println(newdespath);
|
||||
destFile.parent().mkdirs();
|
||||
|
||||
// Conversion to JPEG will be handled differently depending on the platform
|
||||
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);
|
||||
}
|
||||
|
||||
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() {
|
||||
for (String urlToDownload : downloadUrls) {
|
||||
try {
|
||||
doFetch(urlToDownload);
|
||||
doFetch(tofullBorder(urlToDownload));
|
||||
break;
|
||||
} catch (IOException e) {
|
||||
System.out.println("Failed to download card [" + destPath + "] image: " + e.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user