Search in sources :

Example 1 with StandardPlugin

use of com.biglybt.pif.installer.StandardPlugin 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 StandardPlugin

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

the class Handler method canProcessWithoutConnection.

@Override
public boolean canProcessWithoutConnection(URL url, boolean processUrlNow) {
    String host = url.getHost();
    if (host.equalsIgnoreCase("install-plugin") && url.getPath().length() > 1) {
        String plugin_id = url.getPath().substring(1);
        PluginInstaller installer = CoreFactory.getSingleton().getPluginManager().getPluginInstaller();
        try {
            StandardPlugin installablePlugin = installer.getStandardPlugin(plugin_id);
            if (installablePlugin == null) {
                UIManager ui_manager = PluginInitializer.getDefaultInterface().getUIManager();
                String details = MessageText.getString("plugininstall.notfound.desc", new String[] { plugin_id });
                ui_manager.showMessageBox("plugininstall.notfound.title", "!" + details + "!", UIManagerEvent.MT_OK);
                return true;
            }
            installer.requestInstall(MessageText.getString("plugininstall.biglybturl"), installablePlugin);
        } catch (PluginException e) {
            UIManager ui_manager = PluginInitializer.getDefaultInterface().getUIManager();
            ui_manager.showMessageBox("plugininstall.error.title", "!" + e.getMessage() + "!", UIManagerEvent.MT_OK);
            Debug.out(e);
        }
        return true;
    }
    return false;
}
Also used : PluginInstaller(com.biglybt.pif.installer.PluginInstaller) PluginException(com.biglybt.pif.PluginException) UIManager(com.biglybt.pif.ui.UIManager) StandardPlugin(com.biglybt.pif.installer.StandardPlugin)

Example 3 with StandardPlugin

use of com.biglybt.pif.installer.StandardPlugin 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 StandardPlugin

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

the class DeviceManagerUI method createTranscodingSection.

public void createTranscodingSection() {
    // default dir
    String def = device_manager.getDefaultWorkingDirectory().getAbsolutePath();
    final DirectoryParameter def_work_dir = configModel.addDirectoryParameter2("device.config.xcode.workdir", "device.config.xcode.workdir", def);
    def_work_dir.setValue(def);
    def_work_dir.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            device_manager.setDefaultWorkingDirectory(new File(def_work_dir.getValue()));
        }
    });
    // max xcode
    final IntParameter max_xcode = configModel.addIntParameter2("device.config.xcode.maxbps", "device.config.xcode.maxbps", (int) (device_manager.getTranscodeManager().getQueue().getMaxBytesPerSecond() / 1024), 0, Integer.MAX_VALUE);
    max_xcode.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            device_manager.getTranscodeManager().getQueue().setMaxBytesPerSecond(max_xcode.getValue() * 1024);
        }
    });
    // disable sleep
    final BooleanParameter disable_sleep = configModel.addBooleanParameter2("device.config.xcode.disable_sleep", "device.config.xcode.disable_sleep", device_manager.getDisableSleep());
    disable_sleep.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            device_manager.setDisableSleep(disable_sleep.getValue());
        }
    });
    // itunes
    final ActionParameter btnITunes = configModel.addActionParameter2("devices.button.installitunes", "UpdateWindow.columns.install");
    btnITunes.setEnabled(false);
    CoreFactory.addCoreRunningListener(new CoreRunningListener() {

        @Override
        public void coreRunning(Core core) {
            boolean hasItunes = core.getPluginManager().getPluginInterfaceByID("azitunes") != null;
            btnITunes.setEnabled(!hasItunes);
        }
    });
    btnITunes.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            CoreWaiterSWT.waitForCoreRunning(new CoreRunningListener() {

                @Override
                public void coreRunning(Core core) {
                    try {
                        PluginInstaller installer = core.getPluginManager().getPluginInstaller();
                        StandardPlugin itunes_plugin = installer.getStandardPlugin("azitunes");
                        if (itunes_plugin == null) {
                            Debug.out("iTunes standard plugin not found");
                        } else {
                            itunes_plugin.install(false);
                        }
                    } catch (Throwable e) {
                        Debug.printStackTrace(e);
                    }
                }
            });
        }
    });
    configModel.createGroup("device.xcode.group", new Parameter[] { def_work_dir, max_xcode, disable_sleep, btnITunes });
}
Also used : StandardPlugin(com.biglybt.pif.installer.StandardPlugin) PluginInstaller(com.biglybt.pif.installer.PluginInstaller) CoreRunningListener(com.biglybt.core.CoreRunningListener) File(java.io.File) DiskManagerFileInfoFile(com.biglybt.core.download.DiskManagerFileInfoFile) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) Core(com.biglybt.core.Core)

Example 5 with StandardPlugin

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

the class DevicesFTUX method _doInstall.

protected void _doInstall(Core core, boolean itunes) {
    List<InstallablePlugin> plugins = new ArrayList<>(2);
    final PluginInstaller installer = core.getPluginManager().getPluginInstaller();
    StandardPlugin vuze_plugin = null;
    try {
        vuze_plugin = installer.getStandardPlugin("vuzexcode");
    } catch (Throwable ignored) {
    }
    if (vuze_plugin != null && !vuze_plugin.isAlreadyInstalled()) {
        plugins.add(vuze_plugin);
    }
    if (itunes) {
        StandardPlugin itunes_plugin = null;
        try {
            itunes_plugin = installer.getStandardPlugin("azitunes");
        } catch (Throwable ignored) {
        }
        if (itunes_plugin != null && !itunes_plugin.isAlreadyInstalled()) {
            plugins.add(itunes_plugin);
        }
    }
    if (plugins.size() == 0) {
        close();
        return;
    }
    InstallablePlugin[] installablePlugins = plugins.toArray(new InstallablePlugin[0]);
    try {
        install_area_parent.setVisible(true);
        install_area_parent.moveAbove(null);
        Map<Integer, Object> properties = new HashMap<>();
        properties.put(UpdateCheckInstance.PT_UI_STYLE, UpdateCheckInstance.PT_UI_STYLE_SIMPLE);
        properties.put(UpdateCheckInstance.PT_UI_PARENT_SWT_COMPOSITE, install_area);
        properties.put(UpdateCheckInstance.PT_UI_DISABLE_ON_SUCCESS_SLIDEY, true);
        installer.install(installablePlugins, false, properties, new PluginInstallationListener() {

            @Override
            public void completed() {
                close();
                MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
                MdiEntry entry = mdi.getEntry(SideBar.SIDEBAR_HEADER_DEVICES);
                MdiEntryVitalityImage[] vitalityImages = entry.getVitalityImages();
                for (MdiEntryVitalityImage vi : vitalityImages) {
                    if (vi.getImageID().contains("turnon")) {
                        vi.setVisible(false);
                    }
                }
                List<Runnable> to_fire;
                synchronized (to_fire_on_complete) {
                    to_fire = new ArrayList<>(to_fire_on_complete);
                    to_fire_on_complete.clear();
                }
                for (Runnable r : to_fire) {
                    if (r != null) {
                        try {
                            Utils.execSWTThread(r);
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    }
                }
            }

            @Override
            public void cancelled() {
                close();
            }

            @Override
            public void failed(PluginException e) {
                Debug.out(e);
                // Utils.openMessageBox(Utils.findAnyShell(), SWT.OK, "Error",
                // e.toString());
                close();
            }
        });
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    }
}
Also used : HashMap(java.util.HashMap) PluginException(com.biglybt.pif.PluginException) ArrayList(java.util.ArrayList) StandardPlugin(com.biglybt.pif.installer.StandardPlugin) MultipleDocumentInterface(com.biglybt.ui.mdi.MultipleDocumentInterface) InstallablePlugin(com.biglybt.pif.installer.InstallablePlugin) PluginInstaller(com.biglybt.pif.installer.PluginInstaller) PluginInstallationListener(com.biglybt.pif.installer.PluginInstallationListener) MdiEntry(com.biglybt.ui.mdi.MdiEntry) AERunnable(com.biglybt.core.util.AERunnable) ArrayList(java.util.ArrayList) List(java.util.List) MdiEntryVitalityImage(com.biglybt.ui.mdi.MdiEntryVitalityImage)

Aggregations

StandardPlugin (com.biglybt.pif.installer.StandardPlugin)8 PluginException (com.biglybt.pif.PluginException)6 InstallablePlugin (com.biglybt.pif.installer.InstallablePlugin)6 PluginInstallationListener (com.biglybt.pif.installer.PluginInstallationListener)5 PluginInstaller (com.biglybt.pif.installer.PluginInstaller)5 HashMap (java.util.HashMap)5 AESemaphore (com.biglybt.core.util.AESemaphore)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 Map (java.util.Map)2 Core (com.biglybt.core.Core)1 CoreRunningListener (com.biglybt.core.CoreRunningListener)1 DiskManagerFileInfoFile (com.biglybt.core.download.DiskManagerFileInfoFile)1 GlobalManager (com.biglybt.core.global.GlobalManager)1 AERunnable (com.biglybt.core.util.AERunnable)1