Search in sources :

Example 36 with ResourceDownloader

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

the class UpdateWindow method nextUpdate.

private void nextUpdate() {
    if (iterDownloaders.hasNext()) {
        ResourceDownloader downloader = (ResourceDownloader) iterDownloaders.next();
        downloader.addListener(this);
        downloader.asyncDownload();
    } else {
        switchToRestart();
    }
}
Also used : ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader)

Example 37 with ResourceDownloader

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

the class SWTUpdateChecker method checkForUpdate.

@Override
public void checkForUpdate(final UpdateChecker checker) {
    try {
        SWTVersionGetter versionGetter = new SWTVersionGetter(checker);
        boolean update_required = System.getProperty(SystemProperties.SYSPROP_SKIP_SWTCHECK) == null && versionGetter.needsUpdate();
        if (update_required) {
            int update_prevented_version = COConfigurationManager.getIntParameter("swt.update.prevented.version", -1);
            try {
                URL swt_url = SWT.class.getClassLoader().getResource("org/eclipse/swt/SWT.class");
                if (swt_url != null) {
                    String url_str = swt_url.toExternalForm();
                    if (url_str.startsWith("jar:file:")) {
                        File jar_file = FileUtil.getJarFileFromURL(url_str);
                        File expected_dir = new File(checker.getCheckInstance().getManager().getInstallDir());
                        File jar_file_dir = jar_file.getParentFile();
                        if (expected_dir.exists() && jar_file_dir.exists()) {
                            expected_dir = expected_dir.getCanonicalFile();
                            jar_file_dir = jar_file_dir.getCanonicalFile();
                            if (Constants.isUnix) {
                                if (expected_dir.equals(jar_file_dir)) {
                                    // user put it there, so skip everything
                                    return;
                                }
                                // For unix, when swt.jar is in the appdir/swt
                                expected_dir = new File(expected_dir, "swt");
                            }
                            if (expected_dir.equals(jar_file_dir)) {
                                if (update_prevented_version != -1) {
                                    update_prevented_version = -1;
                                    COConfigurationManager.setParameter("swt.update.prevented.version", update_prevented_version);
                                }
                            } else {
                                // we need to periodically remind the user there's a problem as they need to realise that
                                // it is causing ALL updates (core/plugin) to fail
                                String alert = MessageText.getString("swt.alert.cant.update", new String[] { String.valueOf(versionGetter.getCurrentVersion()), String.valueOf(versionGetter.getLatestVersion()), jar_file_dir.toString(), expected_dir.toString() });
                                checker.reportProgress(alert);
                                long last_prompt = COConfigurationManager.getLongParameter("swt.update.prevented.version.time", 0);
                                long now = SystemTime.getCurrentTime();
                                boolean force = now < last_prompt || now - last_prompt > 7 * 24 * 60 * 60 * 1000;
                                if (!checker.getCheckInstance().isAutomatic()) {
                                    force = true;
                                }
                                if (force || update_prevented_version != versionGetter.getCurrentVersion()) {
                                    Logger.log(new LogAlert(LogAlert.REPEATABLE, LogEvent.LT_ERROR, alert));
                                    update_prevented_version = versionGetter.getCurrentVersion();
                                    COConfigurationManager.setParameter("swt.update.prevented.version", update_prevented_version);
                                    COConfigurationManager.setParameter("swt.update.prevented.version.time", now);
                                }
                            }
                        }
                    }
                }
            } catch (Throwable e) {
                Debug.printStackTrace(e);
            }
            if (update_prevented_version == versionGetter.getCurrentVersion()) {
                Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR, "SWT update aborted due to previously reported issues regarding its install location"));
                checker.failed();
                checker.getCheckInstance().cancel();
                return;
            }
            String[] mirrors = versionGetter.getMirrors();
            ResourceDownloader swtDownloader = null;
            ResourceDownloaderFactory factory = ResourceDownloaderFactoryImpl.getSingleton();
            List<ResourceDownloader> downloaders = new ArrayList<>();
            for (int i = 0; i < mirrors.length; i++) {
                try {
                    downloaders.add(factory.getSuffixBasedDownloader(factory.create(new URL(mirrors[i]))));
                } catch (MalformedURLException e) {
                    // Do nothing
                    if (Logger.isEnabled())
                        Logger.log(new LogEvent(LOGID, LogEvent.LT_WARNING, "Cannot use URL " + mirrors[i] + " (not valid)"));
                }
            }
            for (int i = 0; i < mirrors.length; i++) {
                try {
                    downloaders.add(factory.getSuffixBasedDownloader(factory.createWithAutoPluginProxy(new URL(mirrors[i]))));
                } catch (MalformedURLException e) {
                }
            }
            ResourceDownloader[] resourceDownloaders = (ResourceDownloader[]) downloaders.toArray(new ResourceDownloader[downloaders.size()]);
            swtDownloader = factory.getAlternateDownloader(resourceDownloaders);
            try {
                swtDownloader.getSize();
            } catch (ResourceDownloaderException e) {
                Debug.printStackTrace(e);
            }
            String extra = "";
            if (Constants.isWindows && Constants.is64Bit) {
                extra = " (64-bit)";
            }
            final Update update = checker.addUpdate("SWT Library for " + versionGetter.getPlatform() + extra, new String[] { "SWT is the graphical library used by " + Constants.APP_NAME }, "" + versionGetter.getCurrentVersion(), "" + versionGetter.getLatestVersion(), swtDownloader, Update.RESTART_REQUIRED_YES);
            update.setDescriptionURL(versionGetter.getInfoURL());
            swtDownloader.addListener(new ResourceDownloaderAdapter() {

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

                @Override
                public void failed(ResourceDownloader downloader, ResourceDownloaderException e) {
                    Debug.out(downloader.getName() + " failed", e);
                    update.complete(false);
                }
            });
        }
    } catch (Throwable e) {
        Logger.log(new LogAlert(LogAlert.UNREPEATABLE, "SWT Version check failed", e));
        checker.failed();
    } finally {
        checker.completed();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) Update(com.biglybt.pif.update.Update) URL(java.net.URL) SWT(org.eclipse.swt.SWT) ResourceDownloaderAdapter(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter) ResourceDownloaderFactory(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderFactory) File(java.io.File)

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