mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
Use pattern matching to capture directory listing from the server URL string.
Add fallback to PNG for download if JPG is not found. Correct quest-opponent-icons.txt. Space reference should be "%20".
This commit is contained in:
@@ -242,7 +242,7 @@ https://downloads.cardforge.org/images/icons/Einstein.jpg
|
|||||||
https://downloads.cardforge.org/images/icons/Ekolo.jpg
|
https://downloads.cardforge.org/images/icons/Ekolo.jpg
|
||||||
https://downloads.cardforge.org/images/icons/Elashub.jpg
|
https://downloads.cardforge.org/images/icons/Elashub.jpg
|
||||||
https://downloads.cardforge.org/images/icons/Eldrazi.jpg
|
https://downloads.cardforge.org/images/icons/Eldrazi.jpg
|
||||||
https://downloads.cardforge.org/images/icons/Eldritch Onslaught.jpg
|
https://downloads.cardforge.org/images/icons/Eldritch%20Onslaught.jpg
|
||||||
https://downloads.cardforge.org/images/icons/Electro.jpg
|
https://downloads.cardforge.org/images/icons/Electro.jpg
|
||||||
https://downloads.cardforge.org/images/icons/Elegua.jpg
|
https://downloads.cardforge.org/images/icons/Elegua.jpg
|
||||||
https://downloads.cardforge.org/images/icons/Elementalist.jpg
|
https://downloads.cardforge.org/images/icons/Elementalist.jpg
|
||||||
|
|||||||
@@ -17,7 +17,28 @@
|
|||||||
*/
|
*/
|
||||||
package forge.download;
|
package forge.download;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.ConnectException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.Proxy;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import com.esotericsoftware.minlog.Log;
|
import com.esotericsoftware.minlog.Log;
|
||||||
|
|
||||||
import forge.FThreads;
|
import forge.FThreads;
|
||||||
import forge.GuiBase;
|
import forge.GuiBase;
|
||||||
import forge.UiCommand;
|
import forge.UiCommand;
|
||||||
@@ -28,13 +49,6 @@ import forge.interfaces.ITextField;
|
|||||||
import forge.properties.ForgeConstants;
|
import forge.properties.ForgeConstants;
|
||||||
import forge.util.FileUtil;
|
import forge.util.FileUtil;
|
||||||
import forge.util.HttpUtil;
|
import forge.util.HttpUtil;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.*;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public abstract class GuiDownloadService implements Runnable {
|
public abstract class GuiDownloadService implements Runnable {
|
||||||
@@ -260,6 +274,19 @@ public abstract class GuiDownloadService implements Runnable {
|
|||||||
// don't allow redirections here -- they indicate 'file not found' on the server
|
// don't allow redirections here -- they indicate 'file not found' on the server
|
||||||
conn.setInstanceFollowRedirects(false);
|
conn.setInstanceFollowRedirects(false);
|
||||||
conn.connect();
|
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")))
|
||||||
|
{
|
||||||
|
conn.disconnect();
|
||||||
|
System.out.println(" File not found: " + url);
|
||||||
|
url = url.substring(0,url.length() - 4) + ".png";
|
||||||
|
imageUrl = new URL(url);
|
||||||
|
conn = (HttpURLConnection) imageUrl.openConnection(p);
|
||||||
|
conn.setInstanceFollowRedirects(false);
|
||||||
|
conn.connect();
|
||||||
|
}
|
||||||
|
|
||||||
switch (conn.getResponseCode()) {
|
switch (conn.getResponseCode()) {
|
||||||
case HttpURLConnection.HTTP_OK:
|
case HttpURLConnection.HTTP_OK:
|
||||||
fos = new FileOutputStream(fileDest);
|
fos = new FileOutputStream(fileDest);
|
||||||
@@ -354,14 +381,15 @@ public abstract class GuiDownloadService implements Runnable {
|
|||||||
|
|
||||||
String[] strings = response.split("<a href=\"");
|
String[] strings = response.split("<a href=\"");
|
||||||
|
|
||||||
for (String s : strings) {
|
// Use regex to find all directory paths and capture things using groups...
|
||||||
int idx = s.indexOf('/');
|
Pattern pattern = Pattern.compile(">([A-Z0-9_]+)/<");
|
||||||
if (!Character.isLetterOrDigit(s.charAt(0)) || idx > 4 || idx == -1) {
|
Matcher matcher;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String set = s.substring(0, idx);
|
for (String s : strings) {
|
||||||
existingSets.add(set);
|
matcher = pattern.matcher(s);
|
||||||
|
if (matcher.find()) {
|
||||||
|
existingSets.add(matcher.group(1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return existingSets;
|
return existingSets;
|
||||||
|
|||||||
Reference in New Issue
Block a user