Search in sources :

Example 1 with ResourceDownloaderException

use of com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException in project BiglyBT by BiglySoftware.

the class WelcomeWindow method getWhatsNew.

private void getWhatsNew(final int phase) {
    String helpFile = null;
    if (phase == 1) {
        helpFile = MessageText.getString("window.welcome.file");
        if (!helpFile.toLowerCase().startsWith(Constants.PLUGINS_WEB_SITE)) {
            getWhatsNew(2);
            return;
        }
    } else {
        helpFile = MessageText.getString("window.welcome.file");
        InputStream stream;
        stream = getClass().getResourceAsStream(helpFile);
        if (stream == null) {
            String helpFullPath = "/com/biglybt/internat/whatsnew/" + helpFile;
            stream = getClass().getResourceAsStream(helpFullPath);
        }
        if (stream == null) {
            stream = getClass().getResourceAsStream("/ChangeLog.txt");
        }
        if (stream == null) {
            sWhatsNew = "Welcome Window: Error loading resource: " + helpFile;
        } else {
            try {
                sWhatsNew = FileUtil.readInputStreamAsString(stream, 65535, "utf8");
                stream.close();
            } catch (IOException e) {
                Debug.out(e);
            }
        }
        setWhatsNew();
        return;
    }
    final String url = helpFile;
    new AEThread2("getWhatsNew", true) {

        @Override
        public void run() {
            String s;
            ResourceDownloaderFactory rdf = ResourceDownloaderFactoryImpl.getSingleton();
            try {
                ResourceDownloader rd = rdf.create(new URL(url));
                InputStream is = rd.download();
                int length = is.available();
                byte[] data = new byte[length];
                is.read(data);
                is.close();
                s = new String(data);
            } catch (ResourceDownloaderException rde) {
                // We don't need a stack trace - it's arguable that we even need any
                // errors at all - the below line is better, but suppressed output might
                // be better.
                // Debug.outNoStack("Error downloading from " + url + ", " + rde, true);
                s = "";
            } catch (Exception e) {
                Debug.out(e);
                s = "";
            }
            sWhatsNew = s;
            if (sWhatsNew == null || sWhatsNew.length() == 0) {
                getWhatsNew(phase + 1);
                return;
            }
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    if (cWhatsNew != null && !cWhatsNew.isDisposed()) {
                        setWhatsNew();
                    }
                }
            });
        }
    }.start();
}
Also used : InputStream(java.io.InputStream) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException) ResourceDownloaderFactory(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderFactory) IOException(java.io.IOException) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) URL(java.net.URL) IOException(java.io.IOException) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException)

Example 2 with ResourceDownloaderException

use of com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException in project BiglyBT by BiglySoftware.

the class TorrentDownloaderImpl method downloadSupport.

private Torrent downloadSupport(ResourceDownloader downloader) throws TorrentException {
    InputStream is = null;
    try {
        is = downloader.download();
        TOTorrent torrent = TOTorrentFactory.deserialiseFromBEncodedInputStream(is);
        if (encoding_requested) {
            manager.tryToSetTorrentEncoding(torrent, requested_encoding);
        } else {
            if (set_encoding) {
                manager.tryToSetDefaultTorrentEncoding(torrent);
            }
        }
        return (new TorrentImpl(torrent));
    } catch (TorrentException e) {
        throw (e);
    } catch (ResourceDownloaderException e) {
        throw (new TorrentException(e));
    } catch (Throwable e) {
        throw (new TorrentException("TorrentDownloader: download fails", e));
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                Debug.printStackTrace(e);
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException) TOTorrent(com.biglybt.core.torrent.TOTorrent) IOException(java.io.IOException) TorrentException(com.biglybt.pif.torrent.TorrentException)

Example 3 with ResourceDownloaderException

use of com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException in project BiglyBT by BiglySoftware.

the class PlatformManagerUpdateChecker method checkForUpdate.

@Override
public void checkForUpdate(final UpdateChecker checker) {
    try {
        SFPluginDetails sf_details = SFPluginDetailsLoaderFactory.getSingleton().getPluginDetails(plugin_interface.getPluginID());
        String current_version = plugin_interface.getPluginVersion();
        if (Logger.isEnabled())
            Logger.log(new LogEvent(LOGID, "PlatformManager:OSX update check starts: current = " + current_version));
        boolean current_az_is_cvs = Constants.isCVSVersion();
        String sf_plugin_version = sf_details.getVersion();
        String sf_comp_version = sf_plugin_version;
        if (current_az_is_cvs) {
            String sf_cvs_version = sf_details.getCVSVersion();
            if (sf_cvs_version.length() > 0) {
                // sf cvs version ALWAYS entry in _CVS
                sf_plugin_version = sf_cvs_version;
                sf_comp_version = sf_plugin_version.substring(0, sf_plugin_version.length() - 4);
            }
        }
        String target_version = null;
        if (sf_comp_version.length() == 0 || !Character.isDigit(sf_comp_version.charAt(0))) {
            if (Logger.isEnabled())
                Logger.log(new LogEvent(LOGID, LogEvent.LT_WARNING, "PlatformManager:OSX no valid version to check against (" + sf_comp_version + ")"));
        } else if (Constants.compareVersions(current_version, sf_comp_version) < 0) {
            target_version = sf_comp_version;
        }
        checker.reportProgress("OSX: current = " + current_version + ", latest = " + sf_comp_version);
        if (Logger.isEnabled())
            Logger.log(new LogEvent(LOGID, "PlatformManager:OSX update required = " + (target_version != null)));
        if (target_version != null) {
            String target_download = sf_details.getDownloadURL();
            if (current_az_is_cvs) {
                String sf_cvs_version = sf_details.getCVSVersion();
                if (sf_cvs_version.length() > 0) {
                    target_download = sf_details.getCVSDownloadURL();
                }
            }
            ResourceDownloaderFactory rdf = ResourceDownloaderFactoryImpl.getSingleton();
            ResourceDownloader direct_rdl = rdf.create(new URL(target_download));
            String torrent_download = Constants.URL_PLUGINS_TORRENT_BASE;
            int slash_pos = target_download.lastIndexOf("/");
            if (slash_pos == -1) {
                torrent_download += target_download;
            } else {
                torrent_download += target_download.substring(slash_pos + 1);
            }
            torrent_download += ".torrent";
            if (I2PHelpers.isI2PInstalled()) {
                torrent_download += "?i2p=1";
            }
            ResourceDownloader torrent_rdl = rdf.create(new URL(torrent_download));
            torrent_rdl = rdf.getSuffixBasedDownloader(torrent_rdl);
            // create an alternate downloader with torrent attempt first
            ResourceDownloader alternate_rdl = rdf.getAlternateDownloader(new ResourceDownloader[] { torrent_rdl, direct_rdl });
            // get size here so it is cached
            rdf.getTimeoutDownloader(rdf.getRetryDownloader(alternate_rdl, RD_SIZE_RETRIES), RD_SIZE_TIMEOUT).getSize();
            List update_desc = new ArrayList();
            List desc_lines = HTMLUtils.convertHTMLToText("", sf_details.getDescription());
            update_desc.addAll(desc_lines);
            List comment_lines = HTMLUtils.convertHTMLToText("    ", sf_details.getComment());
            update_desc.addAll(comment_lines);
            String[] update_d = new String[update_desc.size()];
            update_desc.toArray(update_d);
            final Update update = checker.addUpdate(UPDATE_NAME, update_d, current_version, target_version, alternate_rdl, Update.RESTART_REQUIRED_YES);
            update.setDescriptionURL(sf_details.getInfoURL());
            alternate_rdl.addListener(new ResourceDownloaderAdapter() {

                @Override
                public boolean completed(final ResourceDownloader downloader, InputStream data) {
                    installUpdate(checker, update, downloader, data);
                    return (true);
                }

                @Override
                public void failed(ResourceDownloader downloader, ResourceDownloaderException e) {
                    Debug.out(downloader.getName() + " failed", e);
                    update.complete(false);
                }
            });
        }
    } catch (Throwable e) {
        Debug.printStackTrace(e);
        checker.reportProgress("Failed to load plugin details for the platform manager: " + Debug.getNestedExceptionMessage(e));
        checker.failed();
    } finally {
        checker.completed();
    }
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException) ArrayList(java.util.ArrayList) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) Update(com.biglybt.pif.update.Update) URL(java.net.URL) ResourceDownloaderAdapter(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter) ResourceDownloaderFactory(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderFactory) ArrayList(java.util.ArrayList) List(java.util.List) SFPluginDetails(com.biglybt.pifimpl.update.sf.SFPluginDetails)

Example 4 with ResourceDownloaderException

use of com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException in project BiglyBT by BiglySoftware.

the class ResourceDownloaderFileImpl method asyncDownload.

@Override
public void asyncDownload() {
    try {
        this_mon.enter();
        if (!cancelled) {
            informActivity(getLogIndent() + (file.isDirectory() ? "Processing: " : "Downloading: ") + getName());
            final Object parent_tls = TorrentUtils.getTLS();
            AEThread2 t = new AEThread2("ResourceDownloaderTimeout", true) {

                @Override
                public void run() {
                    Object child_tls = TorrentUtils.getTLS();
                    TorrentUtils.setTLS(parent_tls);
                    try {
                        if (file.isDirectory()) {
                            completed(ResourceDownloaderFileImpl.this, null);
                        } else {
                            completed(ResourceDownloaderFileImpl.this, new FileInputStream(file));
                        }
                    } catch (Throwable e) {
                        failed(ResourceDownloaderFileImpl.this, new ResourceDownloaderException(ResourceDownloaderFileImpl.this, "Failed to read file", e));
                        Debug.printStackTrace(e);
                    } finally {
                        TorrentUtils.setTLS(child_tls);
                    }
                }
            };
            t.start();
        }
    } finally {
        this_mon.exit();
    }
}
Also used : ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException) FileInputStream(java.io.FileInputStream)

Example 5 with ResourceDownloaderException

use of com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException in project BiglyBT by BiglySoftware.

the class ResourceDownloaderMetaRefreshImpl method getSizeSupport.

protected long getSizeSupport() throws ResourceDownloaderException {
    try {
        ResourceDownloader x = delegate.getClone(this);
        addReportListener(x);
        HTMLPage page = HTMLPageFactory.loadPage(x.download());
        URL base_url = (URL) x.getProperty("URL_URL");
        URL redirect = page.getMetaRefreshURL(base_url);
        if (redirect == null) {
            ResourceDownloaderBaseImpl c = delegate.getClone(this);
            addReportListener(c);
            long res = c.getSize();
            setProperties(c);
            return (res);
        } else {
            ResourceDownloaderURLImpl c = new ResourceDownloaderURLImpl(getParent(), redirect);
            addReportListener(c);
            long res = c.getSize();
            setProperties(c);
            return (res);
        }
    } catch (HTMLException e) {
        throw (new ResourceDownloaderException(this, "getSize failed", e));
    }
}
Also used : HTMLPage(com.biglybt.core.html.HTMLPage) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException) HTMLException(com.biglybt.core.html.HTMLException) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) URL(java.net.URL)

Aggregations

ResourceDownloaderException (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException)26 ResourceDownloader (com.biglybt.pif.utils.resourcedownloader.ResourceDownloader)13 InputStream (java.io.InputStream)11 URL (java.net.URL)11 ResourceDownloaderAdapter (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter)6 ResourceDownloaderFactory (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderFactory)6 IOException (java.io.IOException)5 ZipInputStream (java.util.zip.ZipInputStream)5 PluginProxy (com.biglybt.core.proxy.AEProxyFactory.PluginProxy)4 TOTorrent (com.biglybt.core.torrent.TOTorrent)4 File (java.io.File)4 ArrayList (java.util.ArrayList)4 LogEvent (com.biglybt.core.logging.LogEvent)3 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)3 Update (com.biglybt.pif.update.Update)3 FileInputStream (java.io.FileInputStream)3 HTMLPage (com.biglybt.core.html.HTMLPage)2 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)2 AEThread (com.biglybt.core.util.AEThread)2 ClientIDGenerator (com.biglybt.pif.clientid.ClientIDGenerator)2