Search in sources :

Example 1 with FsSyncException

use of net.java.truevfs.kernel.spec.FsSyncException in project mage by magefree.

the class LoadMissingCardDataNew method run.

@Override
public void run() {
    this.cardIndex = 0;
    this.resetErrorCount();
    File base = new File(getImagesDir());
    if (!base.exists()) {
        base.mkdir();
    }
    Connection.ProxyType configProxyType = Connection.ProxyType.valueByText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_TYPE, "None"));
    Proxy.Type type = Proxy.Type.DIRECT;
    switch(configProxyType) {
        case HTTP:
            type = Proxy.Type.HTTP;
            break;
        case SOCKS:
            type = Proxy.Type.SOCKS;
            break;
        case NONE:
        default:
            proxy = Proxy.NO_PROXY;
            break;
    }
    if (type != Proxy.Type.DIRECT) {
        try {
            String address = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_ADDRESS, "");
            Integer port = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_PORT, "80"));
            proxy = new Proxy(type, new InetSocketAddress(address, port));
        } catch (Exception ex) {
            throw new RuntimeException("Gui_DownloadPicturesService : error 1 - " + ex);
        }
    }
    int downloadThreadsAmount = Integer.parseInt((String) uiDialog.getDownloadThreadsCombo().getSelectedItem());
    if (proxy != null) {
        logger.info("Started download of " + cardsDownloadQueue.size() + " images" + " from source: " + selectedSource.getSourceName() + ", language: " + selectedSource.getCurrentLanguage().getCode() + ", threads: " + downloadThreadsAmount);
        updateProgressMessage("Preparing download list...");
        if (selectedSource.prepareDownloadList(this, cardsDownloadQueue)) {
            update(0, cardsDownloadQueue.size());
            ExecutorService executor = Executors.newFixedThreadPool(downloadThreadsAmount);
            for (int i = 0; i < cardsDownloadQueue.size() && !this.isNeedCancel(); i++) {
                try {
                    CardDownloadData card = cardsDownloadQueue.get(i);
                    logger.debug("Downloading image: " + card.getName() + " (" + card.getSet() + ')');
                    CardImageUrls urls;
                    if (card.isToken()) {
                        if (!"0".equals(card.getCollectorId())) {
                            continue;
                        }
                        urls = selectedSource.generateTokenUrl(card);
                    } else {
                        urls = selectedSource.generateCardUrl(card);
                    }
                    if (urls == null) {
                        String imageRef = selectedSource.getNextHttpImageUrl();
                        String fileName = selectedSource.getFileForHttpImage(imageRef);
                        if (imageRef != null && fileName != null) {
                            imageRef = selectedSource.getSourceName() + imageRef;
                            try {
                                card.setToken(selectedSource.isTokenSource());
                                Runnable task = new DownloadTask(card, imageRef, fileName, selectedSource.getTotalImages());
                                executor.execute(task);
                            } catch (Exception ex) {
                            }
                        } else if (selectedSource.getTotalImages() == -1) {
                            logger.info("Image not available on " + selectedSource.getSourceName() + ": " + card.getName() + " (" + card.getSet() + ')');
                            synchronized (sync) {
                                update(cardIndex + 1, cardsDownloadQueue.size());
                            }
                        }
                    } else {
                        Runnable task = new DownloadTask(card, urls, cardsDownloadQueue.size());
                        executor.execute(task);
                    }
                } catch (Exception ex) {
                    logger.error(ex, ex);
                }
            }
            executor.shutdown();
            while (!executor.isTerminated()) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException ie) {
                }
            }
        }
    }
    try {
        TVFS.umount();
    } catch (FsSyncException e) {
        logger.fatal("Couldn't unmount zip files", e);
        JOptionPane.showMessageDialog(null, "Couldn't unmount zip files", "Error", JOptionPane.ERROR_MESSAGE);
    } finally {
    // 
    }
    // stop
    reloadCardsToDownload(uiDialog.getSetsCombo().getSelectedItem().toString());
    enableDialogButtons();
    // reset images cache
    ImageCache.clearCache();
}
Also used : FsSyncException(net.java.truevfs.kernel.spec.FsSyncException) Connection(mage.remote.Connection) FsSyncException(net.java.truevfs.kernel.spec.FsSyncException) AccessDeniedException(java.nio.file.AccessDeniedException) ExecutorService(java.util.concurrent.ExecutorService) TFile(net.java.truevfs.access.TFile)

Aggregations

AccessDeniedException (java.nio.file.AccessDeniedException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Connection (mage.remote.Connection)1 TFile (net.java.truevfs.access.TFile)1 FsSyncException (net.java.truevfs.kernel.spec.FsSyncException)1