mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
Images: improved error messages, added cancel after too many errors;
This commit is contained in:
parent
b7615a2cdb
commit
72c9370d98
1 changed files with 52 additions and 25 deletions
|
@ -11,7 +11,6 @@ import mage.client.dialog.PreferencesDialog;
|
|||
import mage.client.util.CardLanguage;
|
||||
import mage.client.util.sets.ConstructedFormats;
|
||||
import mage.remote.Connection;
|
||||
import mage.util.StreamUtils;
|
||||
import net.java.truevfs.access.TFile;
|
||||
import net.java.truevfs.access.TFileOutputStream;
|
||||
import net.java.truevfs.access.TVFS;
|
||||
|
@ -26,8 +25,8 @@ import java.awt.event.ItemEvent;
|
|||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.nio.file.AccessDeniedException;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -49,8 +48,11 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
private static final String ALL_STANDARD_IMAGES = "- STANDARD images";
|
||||
private static final String ALL_TOKENS = "- TOKEN images";
|
||||
|
||||
private static final int MAX_ERRORS_COUNT_BEFORE_CANCEL = 50;
|
||||
|
||||
private DownloadImagesDialog uiDialog;
|
||||
private boolean needCancel;
|
||||
private int errorCount;
|
||||
private int cardIndex;
|
||||
|
||||
private List<CardInfo> cardsAll;
|
||||
|
@ -110,19 +112,28 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
|
||||
// show dialog
|
||||
instance.setNeedCancel(false);
|
||||
instance.resetErrorCount();
|
||||
instance.uiDialog.showDialog();
|
||||
instance.uiDialog.dispose();
|
||||
instance.setNeedCancel(true);
|
||||
}
|
||||
|
||||
public boolean getNeedCancel() {
|
||||
return this.needCancel;
|
||||
private boolean getNeedCancel() {
|
||||
return this.needCancel || (this.errorCount > MAX_ERRORS_COUNT_BEFORE_CANCEL);
|
||||
}
|
||||
|
||||
public void setNeedCancel(boolean needCancel) {
|
||||
private void setNeedCancel(boolean needCancel) {
|
||||
this.needCancel = needCancel;
|
||||
}
|
||||
|
||||
private void incErrorCount() {
|
||||
this.errorCount = this.errorCount + 1;
|
||||
}
|
||||
|
||||
private void resetErrorCount() {
|
||||
this.errorCount = 0;
|
||||
}
|
||||
|
||||
public DownloadPicturesService(JFrame frame) {
|
||||
// init service and dialog
|
||||
cardsAll = Collections.synchronizedList(new ArrayList<>());
|
||||
|
@ -788,9 +799,22 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
|
||||
// download
|
||||
selectedSource.doPause(url.getPath());
|
||||
|
||||
httpConn = url.openConnection(p);
|
||||
if (httpConn != null) {
|
||||
|
||||
httpConn.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
|
||||
try {
|
||||
httpConn.connect();
|
||||
} catch (SocketException e) {
|
||||
incErrorCount();
|
||||
errorsList.add("Wrong image URL or java app is not allowed to use network. Check your firewall or proxy settings. Error: " + e.getMessage() + ". Image URL: " + url.toString());
|
||||
break;
|
||||
} catch (UnknownHostException e) {
|
||||
incErrorCount();
|
||||
errorsList.add("Unknown site. Check your DNS settings. Error: " + e.getMessage() + ". Image URL: " + url.toString());
|
||||
break;
|
||||
}
|
||||
int responseCode = ((HttpURLConnection) httpConn).getResponseCode();
|
||||
|
||||
// check result
|
||||
|
@ -813,6 +837,7 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// can save result
|
||||
if (isDownloadOK & httpConn != null) {
|
||||
|
@ -868,9 +893,11 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
}
|
||||
|
||||
} catch (AccessDeniedException e) {
|
||||
incErrorCount();
|
||||
logger.error("Can't access to files: " + card.getName() + "(" + card.getSet() + "). Try rebooting your system to remove the file lock.");
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
incErrorCount();
|
||||
logger.error("Unknown error: " + e.getMessage(), e);
|
||||
} finally {
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue