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