Search in sources :

Example 1 with PluginInstallationListener

use of com.biglybt.pif.installer.PluginInstallationListener in project BiglyBT by BiglySoftware.

the class PluginUpdatePlugin method initComplete.

protected void initComplete(final PluginConfig plugin_config) {
    UpdateManager update_manager = plugin_interface.getUpdateManager();
    update_manager.addListener(new UpdateManagerListener() {

        @Override
        public void checkInstanceCreated(UpdateCheckInstance inst) {
            SFPluginDetailsLoaderFactory.getSingleton().reset();
        }
    });
    final PluginManager plugin_manager = plugin_interface.getPluginManager();
    PluginInterface[] plugins = plugin_manager.getPlugins();
    int mandatory_count = 0;
    int non_mandatory_count = 0;
    for (int i = 0; i < plugins.length; i++) {
        PluginInterface pi = plugins[i];
        boolean pi_mandatory = pi.getPluginState().isMandatory();
        if (pi_mandatory) {
            mandatory_count++;
        } else {
            non_mandatory_count++;
        }
    }
    final int f_non_mandatory_count = non_mandatory_count;
    final int f_mandatory_count = mandatory_count;
    update_manager.registerUpdatableComponent(new UpdatableComponent() {

        @Override
        public String getName() {
            return ("Non-mandatory plugins");
        }

        @Override
        public int getMaximumCheckTime() {
            return (f_non_mandatory_count * ((RD_SIZE_RETRIES * RD_SIZE_TIMEOUT) / 1000));
        }

        @Override
        public void checkForUpdate(UpdateChecker checker) {
            if (checkForUpdateSupport(checker, null, false) == 0) {
                VersionCheckClient vc = VersionCheckClient.getSingleton();
                String[] rps = vc.getRecommendedPlugins();
                boolean found_one = false;
                for (int i = 0; i < rps.length; i++) {
                    String rp_id = rps[i];
                    if (plugin_manager.getPluginInterfaceByID(rp_id, false) != null) {
                        continue;
                    }
                    final String config_key = "recommended.processed." + rp_id;
                    if (!plugin_config.getPluginBooleanParameter(config_key, false)) {
                        try {
                            final PluginInstaller installer = plugin_interface.getPluginManager().getPluginInstaller();
                            StandardPlugin[] sps = installer.getStandardPlugins();
                            for (int j = 0; j < sps.length; j++) {
                                final StandardPlugin sp = sps[j];
                                if (sp.getId().equals(rp_id)) {
                                    found_one = true;
                                    checker.getCheckInstance().addListener(new UpdateCheckInstanceListener() {

                                        @Override
                                        public void cancelled(UpdateCheckInstance instance) {
                                        }

                                        @Override
                                        public void complete(UpdateCheckInstance instance) {
                                            if (instance.getUpdates().length == 0) {
                                                installRecommendedPlugin(installer, sp);
                                                plugin_config.setPluginParameter(config_key, true);
                                            }
                                        }
                                    });
                                    break;
                                }
                            }
                        } catch (Throwable e) {
                        }
                    }
                    if (found_one) {
                        break;
                    }
                }
                if (!found_one) {
                    Set<String> auto_install = vc.getAutoInstallPluginIDs();
                    final List<String> to_do = new ArrayList<>();
                    for (String pid : auto_install) {
                        if (plugin_manager.getPluginInterfaceByID(pid, false) == null) {
                            to_do.add(pid);
                        }
                    }
                    if (to_do.size() > 0) {
                        new AEThread2("pup:autoinst") {

                            @Override
                            public void run() {
                                try {
                                    Thread.sleep(120 * 1000);
                                } catch (Throwable e) {
                                    Debug.out(e);
                                    return;
                                }
                                UpdateManager update_manager = plugin_interface.getUpdateManager();
                                final List<UpdateCheckInstance> l_instances = new ArrayList<>();
                                update_manager.addListener(new UpdateManagerListener() {

                                    @Override
                                    public void checkInstanceCreated(UpdateCheckInstance instance) {
                                        synchronized (l_instances) {
                                            l_instances.add(instance);
                                        }
                                    }
                                });
                                UpdateCheckInstance[] instances = update_manager.getCheckInstances();
                                l_instances.addAll(Arrays.asList(instances));
                                long start = SystemTime.getMonotonousTime();
                                while (true) {
                                    if (SystemTime.getMonotonousTime() - start >= 5 * 60 * 1000) {
                                        break;
                                    }
                                    try {
                                        Thread.sleep(5000);
                                    } catch (Throwable e) {
                                        Debug.out(e);
                                        return;
                                    }
                                    if (l_instances.size() > 0) {
                                        boolean all_done = true;
                                        for (UpdateCheckInstance instance : l_instances) {
                                            if (!instance.isCompleteOrCancelled()) {
                                                all_done = false;
                                                break;
                                            }
                                        }
                                        if (all_done) {
                                            break;
                                        }
                                    }
                                }
                                if (update_manager.getInstallers().length > 0) {
                                    return;
                                }
                                PluginInstaller installer = plugin_interface.getPluginManager().getPluginInstaller();
                                List<InstallablePlugin> sps = new ArrayList<>();
                                for (String pid : to_do) {
                                    try {
                                        StandardPlugin sp = installer.getStandardPlugin(pid);
                                        if (sp != null) {
                                            log.log("Auto-installing " + pid);
                                            sps.add(sp);
                                        } else {
                                            log.log("Standard plugin '" + pid + "' missing");
                                        }
                                    } catch (Throwable e) {
                                        log.log("Standard plugin '" + pid + "' missing", e);
                                    }
                                }
                                if (sps.size() > 0) {
                                    Map<Integer, Object> properties = new HashMap<>();
                                    properties.put(UpdateCheckInstance.PT_UI_STYLE, UpdateCheckInstance.PT_UI_STYLE_NONE);
                                    properties.put(UpdateCheckInstance.PT_UI_DISABLE_ON_SUCCESS_SLIDEY, true);
                                    try {
                                        installer.install(sps.toArray(new InstallablePlugin[sps.size()]), false, properties, new PluginInstallationListener() {

                                            @Override
                                            public void completed() {
                                            }

                                            @Override
                                            public void cancelled() {
                                            }

                                            @Override
                                            public void failed(PluginException e) {
                                            }
                                        });
                                    } catch (Throwable e) {
                                        log.log("Auto install failed", e);
                                    }
                                }
                            }
                        }.start();
                    }
                }
            }
        }
    }, false);
    update_manager.registerUpdatableComponent(new UpdatableComponent() {

        @Override
        public String getName() {
            return ("Mandatory plugins");
        }

        @Override
        public int getMaximumCheckTime() {
            return (f_mandatory_count * ((RD_SIZE_RETRIES * RD_SIZE_TIMEOUT) / 1000));
        }

        @Override
        public void checkForUpdate(UpdateChecker checker) {
            checkForUpdateSupport(checker, null, true);
        }
    }, true);
    update_manager.addListener(new UpdateManagerListener() {

        @Override
        public void checkInstanceCreated(UpdateCheckInstance instance) {
            log.log(LoggerChannel.LT_INFORMATION, "**** Update check starts ****");
        }
    });
}
Also used : PluginInstallationListener(com.biglybt.pif.installer.PluginInstallationListener) StandardPlugin(com.biglybt.pif.installer.StandardPlugin) InstallablePlugin(com.biglybt.pif.installer.InstallablePlugin) PluginInstaller(com.biglybt.pif.installer.PluginInstaller) VersionCheckClient(com.biglybt.core.versioncheck.VersionCheckClient)

Example 2 with PluginInstallationListener

use of com.biglybt.pif.installer.PluginInstallationListener in project BiglyBT by BiglySoftware.

the class InstallablePluginImpl method install.

@Override
public void install(boolean shared, boolean low_noise, final boolean wait_until_done, Map<Integer, Object> properties) throws PluginException {
    final AESemaphore sem = new AESemaphore("FPI");
    final PluginException[] error = { null };
    installer.install(new InstallablePlugin[] { this }, shared, low_noise, properties, new PluginInstallationListener() {

        public boolean cancelled;

        @Override
        public void completed() {
            sem.release();
        }

        @Override
        public void cancelled() {
            cancelled = true;
            error[0] = new PluginException("Install cancelled");
            sem.release();
        }

        @Override
        public void failed(PluginException e) {
            error[0] = e;
            sem.release();
            if (!wait_until_done && !cancelled) {
                Debug.out("Install failed", e);
            }
        }
    });
    if (wait_until_done) {
        sem.reserve();
        if (error[0] != null) {
            throw (error[0]);
        }
    }
}
Also used : PluginInstallationListener(com.biglybt.pif.installer.PluginInstallationListener) PluginException(com.biglybt.pif.PluginException) AESemaphore(com.biglybt.core.util.AESemaphore)

Example 3 with PluginInstallationListener

use of com.biglybt.pif.installer.PluginInstallationListener in project BiglyBT by BiglySoftware.

the class PlayerInstaller method install.

public boolean install() {
    try {
        installer = CoreFactory.getSingleton().getPluginManager().getPluginInstaller();
        StandardPlugin sp = installer.getStandardPlugin("azemp");
        Map<Integer, Object> properties = new HashMap<>();
        properties.put(UpdateCheckInstance.PT_UI_STYLE, UpdateCheckInstance.PT_UI_STYLE_NONE);
        properties.put(UpdateCheckInstance.PT_UI_DISABLE_ON_SUCCESS_SLIDEY, true);
        final AESemaphore sem = new AESemaphore("emp install");
        final boolean[] result = new boolean[1];
        instance = installer.install(new InstallablePlugin[] { sp }, false, properties, new PluginInstallationListener() {

            @Override
            public void completed() {
                result[0] = true;
                if (listener != null) {
                    listener.finished();
                }
                sem.release();
            }

            @Override
            public void cancelled() {
                result[0] = false;
                if (listener != null) {
                    listener.finished();
                }
                sem.release();
            }

            @Override
            public void failed(PluginException e) {
                result[0] = false;
                if (listener != null) {
                    listener.finished();
                }
                sem.release();
            }
        });
        boolean kill_it;
        synchronized (this) {
            kill_it = cancelled;
        }
        if (kill_it) {
            instance.cancel();
            return (false);
        }
        instance.addListener(new UpdateCheckInstanceListener() {

            @Override
            public void cancelled(UpdateCheckInstance instance) {
            }

            @Override
            public void complete(UpdateCheckInstance instance) {
                Update[] updates = instance.getUpdates();
                for (final Update update : updates) {
                    ResourceDownloader[] rds = update.getDownloaders();
                    for (ResourceDownloader rd : rds) {
                        rd.addListener(new ResourceDownloaderAdapter() {

                            @Override
                            public void reportActivity(ResourceDownloader downloader, String activity) {
                            }

                            @Override
                            public void reportPercentComplete(ResourceDownloader downloader, int percentage) {
                                if (listener != null) {
                                    listener.progress(percentage);
                                }
                            }
                        });
                    }
                }
            }
        });
        sem.reserve();
        return result[0];
    } catch (Throwable e) {
    }
    return false;
}
Also used : UpdateCheckInstance(com.biglybt.pif.update.UpdateCheckInstance) UpdateCheckInstanceListener(com.biglybt.pif.update.UpdateCheckInstanceListener) HashMap(java.util.HashMap) PluginException(com.biglybt.pif.PluginException) StandardPlugin(com.biglybt.pif.installer.StandardPlugin) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) AESemaphore(com.biglybt.core.util.AESemaphore) Update(com.biglybt.pif.update.Update) InstallablePlugin(com.biglybt.pif.installer.InstallablePlugin) ResourceDownloaderAdapter(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter) PluginInstallationListener(com.biglybt.pif.installer.PluginInstallationListener)

Example 4 with PluginInstallationListener

use of com.biglybt.pif.installer.PluginInstallationListener in project BiglyBT by BiglySoftware.

the class ConfigSectionPlugins method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    if (!CoreFactory.isCoreRunning()) {
        Composite cSection = new Composite(parent, SWT.NULL);
        cSection.setLayout(new FillLayout());
        Label lblNotAvail = new Label(cSection, SWT.WRAP);
        Messages.setLanguageText(lblNotAvail, "core.not.available");
        return cSection;
    }
    GridLayout layout;
    GridData gridData;
    Label label;
    ImageLoader imageLoader = ImageLoader.getInstance();
    imgRedLed = imageLoader.getImage("redled");
    imgGreenLed = imageLoader.getImage("greenled");
    Composite infoGroup = new Composite(parent, SWT.NULL);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    Utils.setLayoutData(infoGroup, gridData);
    layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    infoGroup.setLayout(layout);
    infoGroup.setLayout(new GridLayout());
    String sep = System.getProperty("file.separator");
    File fUserPluginDir = FileUtil.getUserFile("plugins");
    String sUserPluginDir;
    try {
        sUserPluginDir = fUserPluginDir.getCanonicalPath();
    } catch (Throwable e) {
        sUserPluginDir = fUserPluginDir.toString();
    }
    if (!sUserPluginDir.endsWith(sep)) {
        sUserPluginDir += sep;
    }
    File fAppPluginDir = FileUtil.getApplicationFile("plugins");
    String sAppPluginDir;
    try {
        sAppPluginDir = fAppPluginDir.getCanonicalPath();
    } catch (Throwable e) {
        sAppPluginDir = fAppPluginDir.toString();
    }
    if (!sAppPluginDir.endsWith(sep)) {
        sAppPluginDir += sep;
    }
    label = new Label(infoGroup, SWT.WRAP);
    Utils.setLayoutData(label, new GridData(GridData.FILL_HORIZONTAL));
    Messages.setLanguageText(label, "ConfigView.pluginlist.whereToPut");
    label = new Label(infoGroup, SWT.WRAP);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalIndent = 10;
    Utils.setLayoutData(label, gridData);
    label.setText(sUserPluginDir.replaceAll("&", "&&"));
    label.setForeground(Colors.blue);
    label.setCursor(label.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    final String _sUserPluginDir = sUserPluginDir;
    label.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent arg0) {
            if (_sUserPluginDir.endsWith("/plugins/") || _sUserPluginDir.endsWith("\\plugins\\")) {
                File f = new File(_sUserPluginDir);
                String dir = _sUserPluginDir;
                if (!(f.exists() && f.isDirectory())) {
                    dir = _sUserPluginDir.substring(0, _sUserPluginDir.length() - 9);
                }
                Utils.launch(dir);
            }
        }
    });
    label = new Label(infoGroup, SWT.WRAP);
    Utils.setLayoutData(label, new GridData(GridData.FILL_HORIZONTAL));
    Messages.setLanguageText(label, "ConfigView.pluginlist.whereToPutOr");
    label = new Label(infoGroup, SWT.WRAP);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalIndent = 10;
    Utils.setLayoutData(label, gridData);
    label.setText(sAppPluginDir.replaceAll("&", "&&"));
    label.setForeground(Colors.blue);
    label.setCursor(label.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    final String _sAppPluginDir = sAppPluginDir;
    // TODO : Fix it for windows
    label.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent arg0) {
            if (_sAppPluginDir.endsWith("/plugins/") || _sAppPluginDir.endsWith("\\plugins\\")) {
                File f = new File(_sAppPluginDir);
                if (f.exists() && f.isDirectory()) {
                    Utils.launch(_sAppPluginDir);
                } else {
                    String appDir = _sAppPluginDir.substring(0, _sAppPluginDir.length() - 9);
                    System.out.println(appDir);
                    Utils.launch(appDir);
                }
            }
        }
    });
    pluginIFs = rebuildPluginIFs();
    Collections.sort(pluginIFs, new Comparator() {

        @Override
        public int compare(Object o1, Object o2) {
            return (((PluginInterface) o1).getPluginName().compareToIgnoreCase(((PluginInterface) o2).getPluginName()));
        }
    });
    Label labelInfo = new Label(infoGroup, SWT.WRAP);
    Utils.setLayoutData(labelInfo, new GridData(GridData.FILL_HORIZONTAL));
    Messages.setLanguageText(labelInfo, "ConfigView.pluginlist.info");
    table = new Table(infoGroup, SWT.BORDER | SWT.SINGLE | SWT.CHECK | SWT.VIRTUAL | SWT.FULL_SELECTION);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.heightHint = 200;
    gridData.widthHint = 200;
    Utils.setLayoutData(table, gridData);
    for (int i = 0; i < COLUMN_HEADERS.length; i++) {
        final TableColumn tc = new TableColumn(table, COLUMN_ALIGNS[i]);
        tc.setWidth(Utils.adjustPXForDPI(COLUMN_SIZES[i]));
        tc.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                boolean ascending = comparator.setField(table.indexOf(tc));
                try {
                    table.setSortColumn(tc);
                    table.setSortDirection(ascending ? SWT.UP : SWT.DOWN);
                } catch (NoSuchMethodError ignore) {
                // Ignore Pre 3.0
                }
                Collections.sort(pluginIFs, comparator);
                table.clearAll();
            }
        });
        Messages.setLanguageText(tc, HEADER_PREFIX + COLUMN_HEADERS[i]);
    }
    table.setHeaderVisible(true);
    Composite cButtons = new Composite(infoGroup, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 5;
    cButtons.setLayout(layout);
    Utils.setLayoutData(cButtons, new GridData());
    final Button btnUnload = new Button(cButtons, SWT.PUSH);
    Utils.setLayoutData(btnUnload, new GridData());
    Messages.setLanguageText(btnUnload, "ConfigView.pluginlist.unloadSelected");
    btnUnload.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            final int[] items = table.getSelectionIndices();
            new AEThread2("unload") {

                @Override
                public void run() {
                    for (int i = 0; i < items.length; i++) {
                        int index = items[i];
                        if (index >= 0 && index < pluginIFs.size()) {
                            PluginInterface pluginIF = (PluginInterface) pluginIFs.get(index);
                            if (pluginIF.getPluginState().isOperational()) {
                                if (pluginIF.getPluginState().isUnloadable()) {
                                    try {
                                        pluginIF.getPluginState().unload();
                                    } catch (PluginException e1) {
                                        // TODO Auto-generated catch block
                                        e1.printStackTrace();
                                    }
                                }
                            }
                            Utils.execSWTThread(new Runnable() {

                                @Override
                                public void run() {
                                    pluginIFs = rebuildPluginIFs();
                                    table.setItemCount(pluginIFs.size());
                                    Collections.sort(pluginIFs, comparator);
                                    table.clearAll();
                                }
                            });
                        }
                    }
                }
            }.start();
        }
    });
    btnUnload.setEnabled(false);
    final Button btnLoad = new Button(cButtons, SWT.PUSH);
    Utils.setLayoutData(btnUnload, new GridData());
    Messages.setLanguageText(btnLoad, "ConfigView.pluginlist.loadSelected");
    btnLoad.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            final int[] items = table.getSelectionIndices();
            new AEThread2("load") {

                @Override
                public void run() {
                    for (int i = 0; i < items.length; i++) {
                        int index = items[i];
                        if (index >= 0 && index < pluginIFs.size()) {
                            PluginInterface pluginIF = (PluginInterface) pluginIFs.get(index);
                            // Already loaded.
                            if (pluginIF.getPluginState().isOperational()) {
                                continue;
                            }
                            // initialise.
                            if (pluginIF.getPluginState().isDisabled()) {
                                if (pluginIF.getPluginState().hasFailed()) {
                                    continue;
                                }
                                pluginIF.getPluginState().setDisabled(false);
                            }
                            try {
                                pluginIF.getPluginState().reload();
                            } catch (PluginException e1) {
                                // TODO Auto-generated catch block
                                Debug.printStackTrace(e1);
                            }
                            Utils.execSWTThread(new Runnable() {

                                @Override
                                public void run() {
                                    if (table == null || table.isDisposed()) {
                                        return;
                                    }
                                    pluginIFs = rebuildPluginIFs();
                                    table.setItemCount(pluginIFs.size());
                                    Collections.sort(pluginIFs, comparator);
                                    table.clearAll();
                                }
                            });
                        }
                    }
                }
            }.start();
        }
    });
    btnLoad.setEnabled(false);
    // scan
    final Button btnScan = new Button(cButtons, SWT.PUSH);
    Utils.setLayoutData(btnScan, new GridData());
    Messages.setLanguageText(btnScan, "ConfigView.pluginlist.scan");
    btnScan.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            CoreFactory.getSingleton().getPluginManager().refreshPluginList(false);
            pluginIFs = rebuildPluginIFs();
            table.setItemCount(pluginIFs.size());
            Collections.sort(pluginIFs, comparator);
            table.clearAll();
        }
    });
    // uninstall
    final Button btnUninstall = new Button(cButtons, SWT.PUSH);
    Utils.setLayoutData(btnUninstall, new GridData());
    Messages.setLanguageText(btnUninstall, "ConfigView.pluginlist.uninstallSelected");
    btnUninstall.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            btnUninstall.setEnabled(false);
            final int[] items = table.getSelectionIndices();
            new AEThread2("uninstall") {

                @Override
                public void run() {
                    try {
                        List<PluginInterface> pis = new ArrayList<>();
                        for (int i = 0; i < items.length; i++) {
                            int index = items[i];
                            if (index >= 0 && index < pluginIFs.size()) {
                                PluginInterface pluginIF = (PluginInterface) pluginIFs.get(index);
                                pis.add(pluginIF);
                            }
                        }
                        if (pis.size() > 0) {
                            PluginInterface[] ps = new PluginInterface[pis.size()];
                            pis.toArray(ps);
                            try {
                                final AESemaphore wait_sem = new AESemaphore("unist:wait");
                                ps[0].getPluginManager().getPluginInstaller().uninstall(ps, new PluginInstallationListener() {

                                    @Override
                                    public void completed() {
                                        wait_sem.release();
                                    }

                                    @Override
                                    public void cancelled() {
                                        wait_sem.release();
                                    }

                                    @Override
                                    public void failed(PluginException e) {
                                        wait_sem.release();
                                    }
                                });
                                wait_sem.reserve();
                            } catch (Exception e) {
                                Debug.printStackTrace(e);
                            }
                        }
                    } finally {
                        Utils.execSWTThread(new Runnable() {

                            @Override
                            public void run() {
                                pluginIFs = rebuildPluginIFs();
                                table.setItemCount(pluginIFs.size());
                                Collections.sort(pluginIFs, comparator);
                                table.clearAll();
                                table.setSelection(new int[0]);
                            }
                        });
                    }
                }
            }.start();
        }
    });
    btnUninstall.setEnabled(false);
    table.addListener(SWT.SetData, new Listener() {

        @Override
        public void handleEvent(Event event) {
            TableItem item = (TableItem) event.item;
            int index = table.indexOf(item);
            PluginInterface pluginIF = (PluginInterface) pluginIFs.get(index);
            for (int i = 0; i < COLUMN_HEADERS.length; i++) {
                if (i == FilterComparator.FIELD_NAME)
                    item.setImage(i, pluginIF.getPluginState().isOperational() ? imgGreenLed : imgRedLed);
                String sText = comparator.getFieldValue(i, pluginIF);
                if (sText == null)
                    sText = "";
                item.setText(i, sText);
            }
            item.setGrayed(pluginIF.getPluginState().isMandatory());
            boolean bEnabled = pluginIF.getPluginState().isLoadedAtStartup();
            Utils.setCheckedInSetData(item, bEnabled);
            item.setData("PluginID", pluginIF.getPluginID());
            Utils.alternateRowBackground(item);
        }
    });
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            TableItem[] items = table.getSelection();
            if (items.length == 1) {
                int index = table.indexOf(items[0]);
                PluginInterface pluginIF = (PluginInterface) pluginIFs.get(index);
                PluginConfigModel[] models = pluginIF.getUIManager().getPluginConfigModels();
                for (PluginConfigModel model : models) {
                    if (model.getPluginInterface() == pluginIF) {
                        if (model instanceof BasicPluginConfigModel) {
                            String id = ((BasicPluginConfigModel) model).getSection();
                            UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                            if (uiFunctions != null) {
                                uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, id);
                            }
                        }
                    }
                }
            }
        }
    });
    table.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TableItem item = (TableItem) e.item;
            int index = table.indexOf(item);
            PluginInterface pluginIF = (PluginInterface) pluginIFs.get(index);
            if (e.detail == SWT.CHECK) {
                if (item.getGrayed()) {
                    if (!item.getChecked())
                        item.setChecked(true);
                    return;
                }
                pluginIF.getPluginState().setDisabled(!item.getChecked());
                pluginIF.getPluginState().setLoadedAtStartup(item.getChecked());
            }
            btnUnload.setEnabled(pluginIF.getPluginState().isOperational() && pluginIF.getPluginState().isUnloadable());
            btnLoad.setEnabled(!pluginIF.getPluginState().isOperational() && !pluginIF.getPluginState().hasFailed());
            btnUninstall.setEnabled(!(pluginIF.getPluginState().isBuiltIn() || pluginIF.getPluginState().isMandatory()));
        }
    });
    table.setItemCount(pluginIFs.size());
    return infoGroup;
}
Also used : ParameterListener(com.biglybt.core.config.ParameterListener) PluginInstallationListener(com.biglybt.pif.installer.PluginInstallationListener) GridLayout(org.eclipse.swt.layout.GridLayout) PluginInstallationListener(com.biglybt.pif.installer.PluginInstallationListener) UIFunctions(com.biglybt.ui.UIFunctions) SelectionEvent(org.eclipse.swt.events.SelectionEvent) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel) PluginConfigModel(com.biglybt.pif.ui.model.PluginConfigModel) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) PluginInterface(com.biglybt.pif.PluginInterface) PluginException(com.biglybt.pif.PluginException) MouseAdapter(org.eclipse.swt.events.MouseAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) PluginException(com.biglybt.pif.PluginException) GridData(org.eclipse.swt.layout.GridData) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) File(java.io.File) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel)

Example 5 with PluginInstallationListener

use of com.biglybt.pif.installer.PluginInstallationListener in project BiglyBT by BiglySoftware.

the class SimplePluginInstaller method install.

public boolean install() {
    try {
        installer = CoreFactory.getSingleton().getPluginManager().getPluginInstaller();
        StandardPlugin sp = installer.getStandardPlugin(plugin_id);
        if (sp == null) {
            throw (new Exception("Unknown plugin"));
        }
        Map<Integer, Object> properties = new HashMap<>();
        properties.put(UpdateCheckInstance.PT_UI_STYLE, UpdateCheckInstance.PT_UI_STYLE_NONE);
        properties.put(UpdateCheckInstance.PT_UI_DISABLE_ON_SUCCESS_SLIDEY, true);
        final AESemaphore sem = new AESemaphore("plugin-install");
        final Object[] result = new Object[] { null };
        instance = installer.install(new InstallablePlugin[] { sp }, false, properties, new PluginInstallationListener() {

            @Override
            public void completed() {
                synchronized (SimplePluginInstaller.this) {
                    completed = true;
                }
                result[0] = true;
                if (listener != null) {
                    listener.finished();
                }
                sem.release();
            }

            @Override
            public void cancelled() {
                result[0] = new Exception("Cancelled");
                if (listener != null) {
                    listener.finished();
                }
                sem.release();
            }

            @Override
            public void failed(PluginException e) {
                result[0] = e;
                if (listener != null) {
                    listener.finished();
                }
                sem.release();
            }
        });
        boolean kill_it;
        synchronized (this) {
            kill_it = cancelled;
        }
        if (kill_it) {
            instance.cancel();
            action_listener.actionComplete(new Exception("Cancelled"));
            return (false);
        }
        instance.addListener(new UpdateCheckInstanceListener() {

            @Override
            public void cancelled(UpdateCheckInstance instance) {
            }

            @Override
            public void complete(UpdateCheckInstance instance) {
                Update[] updates = instance.getUpdates();
                for (final Update update : updates) {
                    ResourceDownloader[] rds = update.getDownloaders();
                    for (ResourceDownloader rd : rds) {
                        rd.addListener(new ResourceDownloaderAdapter() {

                            @Override
                            public void reportActivity(ResourceDownloader downloader, String activity) {
                            }

                            @Override
                            public void reportPercentComplete(ResourceDownloader downloader, int percentage) {
                                if (listener != null) {
                                    listener.progress(percentage);
                                }
                            }
                        });
                    }
                }
            }
        });
        sem.reserve();
        action_listener.actionComplete(result[0]);
        return (result[0] instanceof Boolean);
    } catch (Throwable e) {
        // must report error before hitting the listener otherwise the listener cancels the action
        // and the error gets lost
        action_listener.actionComplete(e);
        if (listener != null) {
            listener.finished();
        }
    }
    return false;
}
Also used : UpdateCheckInstance(com.biglybt.pif.update.UpdateCheckInstance) UpdateCheckInstanceListener(com.biglybt.pif.update.UpdateCheckInstanceListener) HashMap(java.util.HashMap) PluginException(com.biglybt.pif.PluginException) StandardPlugin(com.biglybt.pif.installer.StandardPlugin) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) AESemaphore(com.biglybt.core.util.AESemaphore) Update(com.biglybt.pif.update.Update) PluginException(com.biglybt.pif.PluginException) InstallablePlugin(com.biglybt.pif.installer.InstallablePlugin) ResourceDownloaderAdapter(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter) PluginInstallationListener(com.biglybt.pif.installer.PluginInstallationListener)

Aggregations

PluginInstallationListener (com.biglybt.pif.installer.PluginInstallationListener)7 PluginException (com.biglybt.pif.PluginException)6 InstallablePlugin (com.biglybt.pif.installer.InstallablePlugin)5 StandardPlugin (com.biglybt.pif.installer.StandardPlugin)5 AESemaphore (com.biglybt.core.util.AESemaphore)4 HashMap (java.util.HashMap)4 PluginInstaller (com.biglybt.pif.installer.PluginInstaller)3 Update (com.biglybt.pif.update.Update)3 UpdateCheckInstance (com.biglybt.pif.update.UpdateCheckInstance)3 UpdateCheckInstanceListener (com.biglybt.pif.update.UpdateCheckInstanceListener)3 ResourceDownloader (com.biglybt.pif.utils.resourcedownloader.ResourceDownloader)3 ResourceDownloaderAdapter (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter)3 PluginInterface (com.biglybt.pif.PluginInterface)2 File (java.io.File)2 ParameterListener (com.biglybt.core.config.ParameterListener)1 AERunnable (com.biglybt.core.util.AERunnable)1 AEThread2 (com.biglybt.core.util.AEThread2)1 VersionCheckClient (com.biglybt.core.versioncheck.VersionCheckClient)1 PluginManager (com.biglybt.pif.PluginManager)1 BasicPluginConfigModel (com.biglybt.pif.ui.model.BasicPluginConfigModel)1