mirror of
https://github.com/correl/mage.git
synced 2024-11-24 19:19:56 +00:00
* Images: added more download stats (now you can see a progress of prepare stage);
This commit is contained in:
parent
4d20cb19cf
commit
c9f4e949fa
4 changed files with 52 additions and 17 deletions
|
@ -13,7 +13,11 @@ public interface DownloadServiceInfo {
|
|||
|
||||
void incErrorCount();
|
||||
|
||||
void updateMessage(String text);
|
||||
void updateGlobalMessage(String text);
|
||||
|
||||
void updateProgressMessage(String text);
|
||||
|
||||
void showDownloadControls(boolean needToShow);
|
||||
|
||||
Object getSync();
|
||||
}
|
||||
|
|
|
@ -145,6 +145,16 @@ public enum ScryfallImageSource implements CardImageSource {
|
|||
|
||||
preparedUrls.clear();
|
||||
|
||||
// prepare stats
|
||||
int needPrepareCount = 0;
|
||||
int currentPrepareCount = 0;
|
||||
for (CardDownloadData card : downloadList) {
|
||||
if (card.isTwoFacedCard() && card.isSecondSide()) {
|
||||
needPrepareCount++;
|
||||
}
|
||||
}
|
||||
updatePrepareStats(downloadServiceInfo, needPrepareCount, currentPrepareCount);
|
||||
|
||||
for (CardDownloadData card : downloadList) {
|
||||
// need cancel
|
||||
if (downloadServiceInfo.isNeedCancel()) {
|
||||
|
@ -153,6 +163,7 @@ public enum ScryfallImageSource implements CardImageSource {
|
|||
|
||||
// prepare the back face URL
|
||||
if (card.isTwoFacedCard() && card.isSecondSide()) {
|
||||
currentPrepareCount++;
|
||||
final String defaultCode = CardLanguage.ENGLISH.getCode();
|
||||
final String localizedCode = languageAliases.getOrDefault(this.getCurrentLanguage(), defaultCode);
|
||||
|
||||
|
@ -160,14 +171,14 @@ public enum ScryfallImageSource implements CardImageSource {
|
|||
|
||||
try {
|
||||
url = getFaceImageUrl(proxy, card, card.isToken(), localizedCode);
|
||||
preparedUrls.put(card, url);
|
||||
} catch (Exception e) {
|
||||
logger.warn("Failed to prepare image URL (back face) for " + card.getName() + " (" + card.getSet() + ") #"
|
||||
+ card.getCollectorId() + ", Error Message: " + e.getMessage());
|
||||
downloadServiceInfo.incErrorCount();
|
||||
continue;
|
||||
}
|
||||
|
||||
preparedUrls.put(card, url);
|
||||
updatePrepareStats(downloadServiceInfo, needPrepareCount, currentPrepareCount);
|
||||
}
|
||||
|
||||
// inc error count to stop on too many errors
|
||||
|
@ -177,10 +188,15 @@ public enum ScryfallImageSource implements CardImageSource {
|
|||
return true;
|
||||
}
|
||||
|
||||
private void updatePrepareStats(DownloadServiceInfo service, int need, int current) {
|
||||
synchronized (service.getSync()) {
|
||||
service.updateProgressMessage(String.format("Preparing download list... %d of %d", current, need));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CardImageUrls generateCardUrl(CardDownloadData card) throws Exception {
|
||||
return innerGenerateURL(card, false);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -184,7 +184,7 @@ public enum TokensMtgImageSource implements CardImageSource {
|
|||
private HashMap<String, List<TokenData>> getTokensData() throws IOException {
|
||||
synchronized (tokensDataSync) {
|
||||
if (tokensData == null) {
|
||||
DownloadPicturesService.getInstance().updateMessage("Find tokens data...");
|
||||
DownloadPicturesService.getInstance().updateGlobalMessage("Find tokens data...");
|
||||
tokensData = new HashMap<>();
|
||||
|
||||
// get tokens data from resource file
|
||||
|
@ -235,11 +235,11 @@ public enum TokensMtgImageSource implements CardImageSource {
|
|||
}
|
||||
}
|
||||
}
|
||||
DownloadPicturesService.getInstance().updateMessage("");
|
||||
DownloadPicturesService.getInstance().updateGlobalMessage("");
|
||||
DownloadPicturesService.getInstance().showDownloadControls(true);
|
||||
} catch (Exception ex) {
|
||||
LOGGER.warn("Failed to get tokens description from tokens.mtg.onl", ex);
|
||||
DownloadPicturesService.getInstance().updateMessage(ex.getMessage());
|
||||
DownloadPicturesService.getInstance().updateGlobalMessage(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,6 +124,7 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
CardImageUtils.checkAndFixImageFiles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNeedCancel() {
|
||||
return this.needCancel || (this.errorCount > MAX_ERRORS_COUNT_BEFORE_CANCEL);
|
||||
}
|
||||
|
@ -132,6 +133,7 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
this.needCancel = needCancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incErrorCount() {
|
||||
this.errorCount = this.errorCount + 1;
|
||||
|
||||
|
@ -209,23 +211,23 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
}
|
||||
|
||||
public void findMissingCards() {
|
||||
updateMessage("Loading...");
|
||||
updateGlobalMessage("Loading...");
|
||||
this.cardsAll.clear();
|
||||
this.cardsMissing.clear();
|
||||
this.cardsDownloadQueue.clear();
|
||||
|
||||
updateMessage("Loading cards list...");
|
||||
updateGlobalMessage("Loading cards list...");
|
||||
this.cardsAll = Collections.synchronizedList(CardRepository.instance.findCards(new CardCriteria()));
|
||||
|
||||
updateMessage("Finding missing images...");
|
||||
updateGlobalMessage("Finding missing images...");
|
||||
this.cardsMissing = prepareMissingCards(this.cardsAll, uiDialog.getRedownloadCheckbox().isSelected());
|
||||
|
||||
updateMessage("Finding available sets from selected source...");
|
||||
updateGlobalMessage("Finding available sets from selected source...");
|
||||
this.uiDialog.getSetsCombo().setModel(new DefaultComboBoxModel<>(getSetsForCurrentImageSource()));
|
||||
reloadCardsToDownload(this.uiDialog.getSetsCombo().getSelectedItem().toString());
|
||||
|
||||
this.uiDialog.showDownloadControls(true);
|
||||
updateMessage("");
|
||||
updateGlobalMessage("");
|
||||
showDownloadControls(true);
|
||||
}
|
||||
|
||||
|
@ -251,10 +253,17 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
}
|
||||
}
|
||||
|
||||
public void updateMessage(String text) {
|
||||
@Override
|
||||
public void updateGlobalMessage(String text) {
|
||||
this.uiDialog.setGlobalInfo(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressMessage(String text) {
|
||||
this.uiDialog.getProgressBar().setString(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showDownloadControls(boolean needToShow) {
|
||||
// auto-size form on show
|
||||
this.uiDialog.showDownloadControls(needToShow);
|
||||
|
@ -390,7 +399,7 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
uiDialog.setCurrentInfo("Missing: " + missingCardsCount + " card images / " + missingTokensCount + " token images");
|
||||
int imageSum = cardCount + tokenCount;
|
||||
float mb = (imageSum * selectedSource.getAverageSize()) / 1024;
|
||||
uiDialog.getProgressBar().setString(String.format(
|
||||
updateProgressMessage(String.format(
|
||||
cardIndex == imageSum
|
||||
? "%d of %d (%d cards/%d tokens) image downloads finished! Please close!"
|
||||
: "%d of %d (%d cards/%d tokens) image downloads finished! Please wait! [%.1f Mb]",
|
||||
|
@ -631,7 +640,7 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
+ " from source: " + selectedSource.getSourceName()
|
||||
+ ", language: " + selectedSource.getCurrentLanguage().getCode()
|
||||
+ ", threads: " + downloadThreadsAmount);
|
||||
uiDialog.getProgressBar().setString("Preparing download list...");
|
||||
updateProgressMessage("Preparing download list...");
|
||||
if (selectedSource.prepareDownloadList(this, cardsDownloadQueue)) {
|
||||
update(0, cardsDownloadQueue.size());
|
||||
ExecutorService executor = Executors.newFixedThreadPool(downloadThreadsAmount);
|
||||
|
@ -939,7 +948,7 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
if (cardIndex < needDownloadCount) {
|
||||
// downloading
|
||||
float mb = ((needDownloadCount - lastCardIndex) * selectedSource.getAverageSize()) / 1024;
|
||||
uiDialog.getProgressBar().setString(String.format("%d of %d image downloads finished! Please wait! [%.1f Mb]",
|
||||
updateProgressMessage(String.format("%d of %d image downloads finished! Please wait! [%.1f Mb]",
|
||||
lastCardIndex, needDownloadCount, mb));
|
||||
} else {
|
||||
// finished
|
||||
|
@ -957,7 +966,7 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
|
||||
if (this.cardsDownloadQueue.isEmpty()) {
|
||||
// stop download
|
||||
uiDialog.getProgressBar().setString("0 images remaining. Please close.");
|
||||
updateProgressMessage("0 images remaining. Please close.");
|
||||
} else {
|
||||
// try download again
|
||||
}
|
||||
|
@ -974,9 +983,15 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
|
|||
uiDialog.getStartButton().setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Proxy getProxy() {
|
||||
return proxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getSync() {
|
||||
return sync;
|
||||
}
|
||||
}
|
||||
|
||||
class LoadMissingCardDataNew implements Runnable {
|
||||
|
|
Loading…
Reference in a new issue