Search in sources :

Example 6 with ResourceDownloader

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

the class SFPluginDetailsLoaderImpl method loadPluginList.

protected void loadPluginList() throws SFPluginDetailsException {
    try {
        String page_url_to_use = addEPIDS(page_url);
        URL original_url = new URL(page_url_to_use);
        URL url = original_url;
        Proxy proxy = null;
        PluginProxy plugin_proxy = null;
        boolean tried_proxy = false;
        boolean ok = false;
        if (COConfigurationManager.getBooleanParameter("update.anonymous")) {
            tried_proxy = true;
            plugin_proxy = AEProxyFactory.getPluginProxy("loading plugin details", url);
            if (plugin_proxy == null) {
                throw (new SFPluginDetailsException("Proxy not available"));
            } else {
                url = plugin_proxy.getURL();
                proxy = plugin_proxy.getProxy();
            }
        }
        try {
            while (true) {
                try {
                    ResourceDownloader dl = rd_factory.create(url, proxy);
                    if (plugin_proxy != null) {
                        dl.setProperty("URL_HOST", plugin_proxy.getURLHostRewrite());
                    }
                    dl = rd_factory.getRetryDownloader(dl, 5);
                    dl.addListener(this);
                    Properties details = new Properties();
                    InputStream is = dl.download();
                    details.load(is);
                    is.close();
                    Iterator it = details.keySet().iterator();
                    while (it.hasNext()) {
                        String plugin_id = (String) it.next();
                        String data = (String) details.get(plugin_id);
                        int pos = 0;
                        List bits = new ArrayList();
                        while (pos < data.length()) {
                            int p1 = data.indexOf(';', pos);
                            if (p1 == -1) {
                                bits.add(data.substring(pos).trim());
                                break;
                            } else {
                                bits.add(data.substring(pos, p1).trim());
                                pos = p1 + 1;
                            }
                        }
                        if (bits.size() < 3) {
                            Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR, "SF loadPluginList failed for plugin '" + plugin_id + "'.  Details array is " + bits.size() + " (3 min)"));
                        } else {
                            String version = (String) bits.get(0);
                            String cvs_version = (String) bits.get(1);
                            String name = (String) bits.get(2);
                            String category = "";
                            if (bits.size() > 3) {
                                category = (String) bits.get(3);
                            }
                            plugin_ids.add(plugin_id);
                            plugin_map.put(plugin_id.toLowerCase(MessageText.LOCALE_ENGLISH), new SFPluginDetailsImpl(this, plugin_id, version, cvs_version, name, category));
                        }
                    }
                    ok = true;
                    break;
                } catch (Throwable e) {
                    if (!tried_proxy) {
                        tried_proxy = true;
                        plugin_proxy = AEProxyFactory.getPluginProxy("loading plugin details", url);
                        if (plugin_proxy == null) {
                            throw (e);
                        } else {
                            url = plugin_proxy.getURL();
                            proxy = plugin_proxy.getProxy();
                        }
                    } else {
                        throw (e);
                    }
                }
            }
        } finally {
            if (plugin_proxy != null) {
                plugin_proxy.setOK(ok);
            }
        }
        plugin_ids_loaded = true;
        plugin_ids_loaded_at = SystemTime.getCurrentTime();
    } catch (Throwable e) {
        Debug.printStackTrace(e);
        throw (new SFPluginDetailsException("Plugin list load failed", e));
    }
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) InputStream(java.io.InputStream) PluginProxy(com.biglybt.core.proxy.AEProxyFactory.PluginProxy) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) URL(java.net.URL) Proxy(java.net.Proxy) PluginProxy(com.biglybt.core.proxy.AEProxyFactory.PluginProxy) SFPluginDetailsException(com.biglybt.pifimpl.update.sf.SFPluginDetailsException)

Example 7 with ResourceDownloader

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

the class ResourceDownloaderFactoryImpl method getSuffixBasedDownloader.

@Override
public ResourceDownloader getSuffixBasedDownloader(ResourceDownloader _downloader) {
    ResourceDownloaderBaseImpl dl = (ResourceDownloaderBaseImpl) _downloader;
    URL target = null;
    while (true) {
        List kids = dl.getChildren();
        if (kids.size() == 0) {
            target = ((ResourceDownloaderURLImpl) dl).getURL();
            break;
        }
        dl = (ResourceDownloaderBaseImpl) kids.get(0);
    }
    ResourceDownloader result;
    if (target == null) {
        if (Logger.isEnabled())
            Logger.log(new LogEvent(LOGID, "ResourceDownloader: suffix " + "based downloader failed to find leaf"));
        result = _downloader;
    } else {
        if (target.getPath().toLowerCase().endsWith(".torrent")) {
            result = getTorrentDownloader(_downloader, true);
        } else {
            result = _downloader;
        }
    }
    if (COConfigurationManager.getBooleanParameter("update.anonymous")) {
        try {
            ((ResourceDownloaderBaseImpl) result).setPropertyRecursive(ResourceDownloader.PR_BOOLEAN_ANONYMOUS, true);
        } catch (Throwable e) {
            Debug.out(e);
        }
    }
    return (result);
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) List(java.util.List) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) URL(java.net.URL)

Example 8 with ResourceDownloader

use of com.biglybt.pif.utils.resourcedownloader.ResourceDownloader 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)

Example 9 with ResourceDownloader

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

the class ResourceDownloaderTorrentImpl method getSizeSupport.

protected long getSizeSupport() throws ResourceDownloaderException {
    try {
        if (torrent_holder[0] == null) {
            ResourceDownloader x = delegate.getClone(this);
            addReportListener(x);
            InputStream is = x.download();
            try {
                torrent_holder[0] = TOTorrentFactory.deserialiseFromBEncodedInputStream(is);
            } finally {
                try {
                    is.close();
                } catch (IOException e) {
                }
            }
            if (!torrent_holder[0].isSimpleTorrent()) {
                throw (new ResourceDownloaderException(this, "Only simple torrents supported"));
            }
        }
        try {
            String file_str = new String(torrent_holder[0].getName());
            int pos = file_str.lastIndexOf(".");
            String file_type;
            if (pos != -1) {
                file_type = file_str.substring(pos + 1);
            } else {
                file_type = null;
            }
            setProperty(ResourceDownloader.PR_STRING_CONTENT_TYPE, HTTPUtils.guessContentTypeFromFileType(file_type));
        } catch (Throwable e) {
            Debug.printStackTrace(e);
        }
        return (torrent_holder[0].getSize());
    } catch (TOTorrentException e) {
        throw (new ResourceDownloaderException(this, "Torrent deserialisation failed", e));
    }
}
Also used : TOTorrentException(com.biglybt.core.torrent.TOTorrentException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) IOException(java.io.IOException)

Example 10 with ResourceDownloader

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

the class CorePatchChecker method patch.

protected void patch(UpdateCheckInstance instance, Update updater_update, PluginInterface updater_plugin) {
    try {
        // use the update plugin to log stuff....
        ResourceDownloader rd_log = updater_update.getDownloaders()[0];
        File[] files = new File(updater_plugin.getPluginDirectoryName()).listFiles();
        if (files == null) {
            if (Logger.isEnabled())
                Logger.log(new LogEvent(LOGID, "Core Patcher: no files in plugin dir!!!"));
            return;
        }
        String patch_prefix = "BiglyBT_" + Constants.getBaseVersion() + "_P";
        int highest_p = -1;
        File highest_p_file = null;
        for (int i = 0; i < files.length; i++) {
            String name = files[i].getName();
            if (name.startsWith(patch_prefix) && name.endsWith(".pat")) {
                if (Logger.isEnabled())
                    Logger.log(new LogEvent(LOGID, "Core Patcher: found patch file '" + name + "'"));
                try {
                    int this_p = Integer.parseInt(name.substring(patch_prefix.length(), name.indexOf(".pat")));
                    if (this_p > highest_p) {
                        highest_p = this_p;
                        highest_p_file = files[i];
                    }
                } catch (Throwable e) {
                    Debug.printStackTrace(e);
                }
            }
        }
        if (CorePatchLevel.getCurrentPatchLevel() >= highest_p) {
            if (Logger.isEnabled())
                Logger.log(new LogEvent(LOGID, "Core Patcher: no applicable patch found (highest = " + highest_p + ")"));
            if (updater_update.getRestartRequired() == Update.RESTART_REQUIRED_MAYBE) {
                updater_update.setRestartRequired(Update.RESTART_REQUIRED_NO);
            }
        } else {
            rd_log.reportActivity("Applying patch '" + highest_p_file.getName() + "'");
            if (Logger.isEnabled())
                Logger.log(new LogEvent(LOGID, "Core Patcher: applying patch '" + highest_p_file.toString() + "'"));
            InputStream pis = new FileInputStream(highest_p_file);
            try {
                patchBiglyBT(instance, pis, "P" + highest_p, plugin_interface.getLogger().getChannel("CorePatcher"));
                Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_INFORMATION, "Patch " + highest_p_file.getName() + " ready to be applied"));
                String done_file = highest_p_file.toString();
                done_file = done_file.substring(0, done_file.length() - 1) + "x";
                highest_p_file.renameTo(new File(done_file));
                // flip the original update over to 'restart required'
                updater_update.setRestartRequired(Update.RESTART_REQUIRED_YES);
            } finally {
                try {
                    pis.close();
                } catch (Throwable e) {
                }
            }
        }
    } catch (Throwable e) {
        Debug.printStackTrace(e);
        Logger.log(new LogAlert(LogAlert.UNREPEATABLE, "Core Patcher failed", e));
    }
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) LogAlert(com.biglybt.core.logging.LogAlert)

Aggregations

ResourceDownloader (com.biglybt.pif.utils.resourcedownloader.ResourceDownloader)37 URL (java.net.URL)18 ResourceDownloaderException (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException)16 InputStream (java.io.InputStream)14 ResourceDownloaderAdapter (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter)12 ResourceDownloaderFactory (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderFactory)11 Update (com.biglybt.pif.update.Update)9 LogEvent (com.biglybt.core.logging.LogEvent)7 PluginProxy (com.biglybt.core.proxy.AEProxyFactory.PluginProxy)6 ZipInputStream (java.util.zip.ZipInputStream)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)4 SFPluginDetails (com.biglybt.pifimpl.update.sf.SFPluginDetails)4 LogAlert (com.biglybt.core.logging.LogAlert)3 AESemaphore (com.biglybt.core.util.AESemaphore)3 PluginException (com.biglybt.pif.PluginException)3 InstallablePlugin (com.biglybt.pif.installer.InstallablePlugin)3 PluginInstallationListener (com.biglybt.pif.installer.PluginInstallationListener)3 StandardPlugin (com.biglybt.pif.installer.StandardPlugin)3