Search in sources :

Example 11 with Update

use of com.biglybt.pif.update.Update in project BiglyBT by BiglySoftware.

the class UpdateWindow method update.

private void update() {
    btnOk.setEnabled(false);
    Messages.setLanguageText(btnCancel, "UpdateWindow.cancel");
    table.setEnabled(false);
    link_area.reset();
    if (browser != null) {
        browser.setVisible(false);
    }
    link_area.getComponent().setVisible(true);
    TableItem[] items = table.getItems();
    totalDownloadSize = 0;
    downloaders = new ArrayList();
    for (int i = 0; i < items.length; i++) {
        if (!items[i].getChecked())
            continue;
        Update update = (Update) items[i].getData();
        ResourceDownloader[] rds = update.getDownloaders();
        for (int j = 0; j < rds.length; j++) {
            downloaders.add(rds[j]);
            try {
                totalDownloadSize += rds[j].getSize();
            } catch (Exception e) {
                link_area.addLine(MessageText.getString("UpdateWindow.no_size") + rds[j].getName());
            }
        }
    }
    downloadersToData = new HashMap();
    iterDownloaders = downloaders.iterator();
    nextUpdate();
}
Also used : ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) Update(com.biglybt.pif.update.Update) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException)

Example 12 with Update

use of com.biglybt.pif.update.Update in project BiglyBT by BiglySoftware.

the class UpdateWindow method rowSelected.

protected void rowSelected() {
    checkMandatory();
    checkRestartNeeded();
    TableItem[] items = table.getSelection();
    if (items.length == 0)
        return;
    Update update = (Update) items[0].getData();
    String desciptionURL = update.getDesciptionURL();
    if (desciptionURL != null && browser != null) {
        browser.setUrl(desciptionURL);
        browser.setVisible(true);
        link_area.getComponent().setVisible(false);
    } else {
        if (browser != null) {
            browser.setVisible(false);
        }
        link_area.getComponent().setVisible(true);
        String[] descriptions = update.getDescription();
        link_area.reset();
        link_area.setRelativeURLBase(update.getRelativeURLBase());
        for (int i = 0; i < descriptions.length; i++) {
            link_area.addLine(descriptions[i]);
        }
    }
}
Also used : Update(com.biglybt.pif.update.Update)

Example 13 with Update

use of com.biglybt.pif.update.Update 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

Update (com.biglybt.pif.update.Update)13 ResourceDownloader (com.biglybt.pif.utils.resourcedownloader.ResourceDownloader)9 ResourceDownloaderAdapter (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter)7 PluginException (com.biglybt.pif.PluginException)4 InstallablePlugin (com.biglybt.pif.installer.InstallablePlugin)4 UpdateCheckInstance (com.biglybt.pif.update.UpdateCheckInstance)4 UpdateCheckInstanceListener (com.biglybt.pif.update.UpdateCheckInstanceListener)4 ResourceDownloaderException (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException)4 AESemaphore (com.biglybt.core.util.AESemaphore)3 PluginInstallationListener (com.biglybt.pif.installer.PluginInstallationListener)3 StandardPlugin (com.biglybt.pif.installer.StandardPlugin)3 ResourceDownloaderFactory (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderFactory)3 SFPluginDetails (com.biglybt.pifimpl.update.sf.SFPluginDetails)3 InputStream (java.io.InputStream)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ZipInputStream (java.util.zip.ZipInputStream)3 LogEvent (com.biglybt.core.logging.LogEvent)2 AEThread2 (com.biglybt.core.util.AEThread2)2