|
@@ -25,7 +25,6 @@ package uk.co.md87.evetool;
|
25
|
25
|
import java.awt.Image;
|
26
|
26
|
import java.io.File;
|
27
|
27
|
import java.io.IOException;
|
28
|
|
-import java.net.URL;
|
29
|
28
|
import java.util.ArrayList;
|
30
|
29
|
import java.util.List;
|
31
|
30
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
@@ -34,6 +33,7 @@ import java.util.logging.Logger;
|
34
|
33
|
|
35
|
34
|
import javax.imageio.ImageIO;
|
36
|
35
|
|
|
36
|
+import uk.co.md87.evetool.api.io.Downloader;
|
37
|
37
|
import uk.co.md87.evetool.api.io.QueueSizeListener;
|
38
|
38
|
|
39
|
39
|
/**
|
|
@@ -45,6 +45,8 @@ public class ImageManager {
|
45
|
45
|
|
46
|
46
|
protected static final List<String> REQUESTS = new ArrayList<String>();
|
47
|
47
|
|
|
48
|
+ protected static final String ILLEGAL_CHARS = "[\\\\\"/:\\*\\?\"<>\\|]";
|
|
49
|
+
|
48
|
50
|
private static final List<QueueSizeListener> listeners = new ArrayList<QueueSizeListener>();
|
49
|
51
|
|
50
|
52
|
private static final AtomicInteger queueSize = new AtomicInteger(0);
|
|
@@ -63,6 +65,7 @@ public class ImageManager {
|
63
|
65
|
|
64
|
66
|
public Image getImage(final ImageType type, final Object ... arguments) throws IOException {
|
65
|
67
|
final String url = type.getUrl(arguments);
|
|
68
|
+ final String cacheUrl = url.replaceAll(ILLEGAL_CHARS, "_");
|
66
|
69
|
|
67
|
70
|
synchronized (REQUESTS) {
|
68
|
71
|
fireQueueSizeChange(queueSize.incrementAndGet());
|
|
@@ -79,8 +82,13 @@ public class ImageManager {
|
79
|
82
|
}
|
80
|
83
|
|
81
|
84
|
try {
|
82
|
|
- final Image res = ImageIO.read(new URL(url));
|
83
|
|
- return res;
|
|
85
|
+ final File file = new File(cacheDir, cacheUrl);
|
|
86
|
+
|
|
87
|
+ if (!file.exists()) {
|
|
88
|
+ Downloader.downloadPage(url, file);
|
|
89
|
+ }
|
|
90
|
+
|
|
91
|
+ return ImageIO.read(file);
|
84
|
92
|
} finally {
|
85
|
93
|
synchronized (REQUESTS) {
|
86
|
94
|
fireQueueSizeChange(queueSize.decrementAndGet());
|