Search in sources :

Example 1 with PluginInstallerListener

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

the class Initializer method run.

@Override
public void run() {
    DelayedTask delayed_task = UtilitiesImpl.addDelayedTask("SWT Initialisation", new Runnable() {

        @Override
        public void run() {
            init_task.reserve();
        }
    });
    delayed_task.queueFirst();
    // initialise the SWT locale util
    long startTime = SystemTime.getCurrentTime();
    new LocaleUtilSWT(core);
    final Display display = Utils.getDisplay();
    new UIMagnetHandler(core);
    if (!STARTUP_UIFIRST) {
        UIConfigDefaultsSWT.initialize();
        UIConfigDefaultsSWTv3.initialize(core);
        // Ensure colors initialized
        Colors.getInstance();
    } else {
        COConfigurationManager.setBooleanDefault("Show Splash", false);
    }
    if (COConfigurationManager.getBooleanParameter("Show Splash")) {
        display.asyncExec(new AERunnable() {

            @Override
            public void runSupport() {
                new SplashWindow(display, Initializer.this);
            }
        });
    }
    System.out.println("Locale Initializing took " + (SystemTime.getCurrentTime() - startTime) + "ms");
    startTime = SystemTime.getCurrentTime();
    core.addLifecycleListener(new CoreLifecycleAdapter() {

        @Override
        public void componentCreated(Core core, CoreComponent component) {
            Initializer.this.reportPercent(curPercent + 1);
            if (component instanceof GlobalManager) {
                reportCurrentTaskByKey("splash.initializePlugins");
                InitialisationFunctions.earlyInitialisation(core);
            } else if (component instanceof PluginInterface) {
                PluginInterface pi = (PluginInterface) component;
                String name = pi.getPluginName();
                String version = pi.getPluginVersion();
                // text says initializing, but it's actually initialized.  close enough
                String s = MessageText.getString("splash.plugin.init") + " " + name + (version == null ? "" : (" v" + version));
                reportCurrentTask(s);
            }
        }

        // @see com.biglybt.core.CoreLifecycleAdapter#started(com.biglybt.core.Core)
        @Override
        public void started(Core core) {
            handleCoreStarted(core);
        }

        @Override
        public void stopping(Core core) {
            Alerts.stopInitiated();
        }

        @Override
        public void stopped(Core core) {
        }

        @Override
        public boolean syncInvokeRequired() {
            return (true);
        }

        @Override
        public boolean requiresPluginInitCompleteBeforeStartedEvent() {
            return (false);
        }

        @Override
        public boolean stopRequested(Core _core) throws CoreException {
            return handleStopRestart(false);
        }

        @Override
        public boolean restartRequested(final Core core) {
            return handleStopRestart(true);
        }
    });
    reportCurrentTaskByKey("splash.initializeCore");
    boolean uiClassic = COConfigurationManager.getStringParameter("ui").equals("az2");
    try {
        new SearchUI();
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    }
    try {
        subscriptionManagerUI = new SubscriptionManagerUI();
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    }
    if (!uiClassic) {
        try {
            deviceManagerUI = new DeviceManagerUI(core);
        } catch (Throwable e) {
            Debug.printStackTrace(e);
        }
    }
    int wait = 15;
    MessageBoxShell[] wait_shell = { null };
    boolean[] abandon = { false };
    while (!core.canStart(wait)) {
        synchronized (abandon) {
            if (abandon[0]) {
                CoreWaiterSWT.startupAbandoned();
                final AESemaphore sem = new AESemaphore("waiter");
                Utils.execSWTThread(new Runnable() {

                    @Override
                    public void run() {
                        MessageBoxShell mb = new MessageBoxShell(MessageText.getString("msgbox.force.close.title"), MessageText.getString("msgbox.force.close.text", new String[] { core.getLockFile().getAbsolutePath() }), new String[] { MessageText.getString("Button.ok") }, 0);
                        mb.setIconResource("error");
                        mb.setModal(true);
                        mb.open(new UserPrompterResultListener() {

                            @Override
                            public void prompterClosed(int result) {
                                sem.releaseForever();
                            }
                        });
                    }
                });
                sem.reserve();
                SESecurityManager.exitVM(1);
            }
        }
        wait = 3;
        boolean show_wait = false;
        synchronized (wait_shell) {
            show_wait = wait_shell[0] == null;
        }
        if (show_wait) {
            AESemaphore sem = new AESemaphore("wait");
            Utils.execSWTThread(() -> {
                MessageBoxShell mb;
                try {
                    mb = new MessageBoxShell(MessageText.getString("msgbox.startup.stall.title"), MessageText.getString("msgbox.startup.stall.text"), new String[] { MessageText.getString("Button.abort") }, 0);
                    synchronized (wait_shell) {
                        wait_shell[0] = mb;
                    }
                } finally {
                    sem.release();
                }
                mb.setIconResource("warning");
                mb.setModal(true);
                mb.open((result) -> {
                    synchronized (abandon) {
                        abandon[0] = true;
                    }
                });
            });
            sem.reserve();
        }
    }
    synchronized (wait_shell) {
        if (wait_shell[0] != null) {
            Utils.execSWTThread(() -> {
                wait_shell[0].close();
            });
        }
    }
    // Other UIs could start the core before us
    if (!core.isStarted()) {
        core.start();
    } else {
        handleCoreStarted(core);
    }
    reportPercent(50);
    System.out.println("Core Initializing took " + (SystemTime.getCurrentTime() - startTime) + "ms");
    startTime = SystemTime.getCurrentTime();
    reportCurrentTaskByKey("splash.initializeUIElements");
    // Ensure colors initialized
    Colors.getInstance();
    reportPercent(curPercent + 1);
    Alerts.init();
    reportPercent(curPercent + 1);
    ProgressWindow.register(core);
    reportPercent(curPercent + 1);
    new SWTNetworkSelection();
    reportPercent(curPercent + 1);
    new AuthenticatorWindow();
    new CryptoWindow();
    reportPercent(curPercent + 1);
    new CertificateTrustWindow();
    core.getPluginManager().getPluginInstaller().addListener(new PluginInstallerListener() {

        @Override
        public boolean installRequest(final String reason, final InstallablePlugin plugin) throws PluginException {
            if (plugin instanceof StandardPlugin) {
                Map<Integer, Object> properties = new HashMap<>();
                properties.put(UpdateCheckInstance.PT_UI_EXTRA_MESSAGE, reason);
                plugin.install(false, false, false, properties);
                return (true);
            } else {
                return (false);
            }
        }
    });
}
Also used : DeviceManagerUI(com.biglybt.ui.swt.devices.DeviceManagerUI) PluginInstallerListener(com.biglybt.pif.installer.PluginInstallerListener) AuthenticatorWindow(com.biglybt.ui.swt.auth.AuthenticatorWindow) SearchUI(com.biglybt.ui.swt.search.SearchUI) CertificateTrustWindow(com.biglybt.ui.swt.auth.CertificateTrustWindow) GlobalManager(com.biglybt.core.global.GlobalManager) DelayedTask(com.biglybt.pif.utils.DelayedTask) SubscriptionManagerUI(com.biglybt.ui.swt.subscriptions.SubscriptionManagerUI) PluginInterface(com.biglybt.pif.PluginInterface) PluginException(com.biglybt.pif.PluginException) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) StandardPlugin(com.biglybt.pif.installer.StandardPlugin) InstallablePlugin(com.biglybt.pif.installer.InstallablePlugin) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) CryptoWindow(com.biglybt.ui.swt.auth.CryptoWindow) SWTNetworkSelection(com.biglybt.ui.swt.networks.SWTNetworkSelection) Map(java.util.Map) HashMap(java.util.HashMap) Display(org.eclipse.swt.widgets.Display)

Example 2 with PluginInstallerListener

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

the class ConsoleInput method registerUpdateChecker.

protected void registerUpdateChecker() {
    boolean check_at_start = COConfigurationManager.getBooleanParameter("update.start", true);
    if (!check_at_start) {
        return;
    }
    // we've got to disable the auto-update components as we're not using them (yet...)
    PluginManager pm = core.getPluginManager();
    pm.getPluginInstaller().addListener(new PluginInstallerListener() {

        @Override
        public boolean installRequest(String reason, InstallablePlugin plugin) throws PluginException {
            out.println("Plugin installation request for '" + plugin.getName() + "' - " + reason);
            String desc = plugin.getDescription();
            String[] bits = desc.split("\n");
            for (int i = 0; i < bits.length; i++) {
                out.println("\t" + bits[i]);
            }
            return (true);
        }
    });
    PluginInterface pi = pm.getPluginInterfaceByClass(CorePatchChecker.class);
    if (pi != null) {
        pi.getPluginState().setDisabled(true);
    }
    pi = pm.getPluginInterfaceByClass(UpdaterUpdateChecker.class);
    if (pi != null) {
        pi.getPluginState().setDisabled(true);
    }
    UpdateManager update_manager = core.getPluginManager().getDefaultPluginInterface().getUpdateManager();
    final UpdateCheckInstance checker = update_manager.createUpdateCheckInstance();
    checker.addListener(new UpdateCheckInstanceListener() {

        @Override
        public void cancelled(UpdateCheckInstance instance) {
        }

        @Override
        public void complete(UpdateCheckInstance instance) {
            int num_updates = 0;
            Update[] updates = instance.getUpdates();
            for (int i = 0; i < updates.length; i++) {
                Update update = updates[i];
                num_updates++;
                out.println("Update available for '" + update.getName() + "', new version = " + update.getNewVersion());
                String[] descs = update.getDescription();
                for (int j = 0; j < descs.length; j++) {
                    out.println("\t" + descs[j]);
                }
                if (update.isMandatory()) {
                    out.println("**** This is a mandatory update, other updates can not proceed until this is performed ****");
                }
            }
            // need to cancel this otherwise it sits there blocking other installer operations
            checker.cancel();
            if (num_updates > 0) {
                out.println("Apply these updates with the 'plugin update' command");
            }
        }
    });
    checker.start();
}
Also used : UpdateCheckInstance(com.biglybt.pif.update.UpdateCheckInstance) PluginInstallerListener(com.biglybt.pif.installer.PluginInstallerListener) UpdaterUpdateChecker(com.biglybt.update.UpdaterUpdateChecker) UpdateCheckInstanceListener(com.biglybt.pif.update.UpdateCheckInstanceListener) PluginException(com.biglybt.pif.PluginException) PluginInterface(com.biglybt.pif.PluginInterface) Update(com.biglybt.pif.update.Update) InstallablePlugin(com.biglybt.pif.installer.InstallablePlugin) PluginManager(com.biglybt.pif.PluginManager) UpdateManager(com.biglybt.pif.update.UpdateManager)

Aggregations

PluginException (com.biglybt.pif.PluginException)2 PluginInterface (com.biglybt.pif.PluginInterface)2 InstallablePlugin (com.biglybt.pif.installer.InstallablePlugin)2 PluginInstallerListener (com.biglybt.pif.installer.PluginInstallerListener)2 GlobalManager (com.biglybt.core.global.GlobalManager)1 PluginManager (com.biglybt.pif.PluginManager)1 StandardPlugin (com.biglybt.pif.installer.StandardPlugin)1 Update (com.biglybt.pif.update.Update)1 UpdateCheckInstance (com.biglybt.pif.update.UpdateCheckInstance)1 UpdateCheckInstanceListener (com.biglybt.pif.update.UpdateCheckInstanceListener)1 UpdateManager (com.biglybt.pif.update.UpdateManager)1 DelayedTask (com.biglybt.pif.utils.DelayedTask)1 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)1 AuthenticatorWindow (com.biglybt.ui.swt.auth.AuthenticatorWindow)1 CertificateTrustWindow (com.biglybt.ui.swt.auth.CertificateTrustWindow)1 CryptoWindow (com.biglybt.ui.swt.auth.CryptoWindow)1 DeviceManagerUI (com.biglybt.ui.swt.devices.DeviceManagerUI)1 SWTNetworkSelection (com.biglybt.ui.swt.networks.SWTNetworkSelection)1 SearchUI (com.biglybt.ui.swt.search.SearchUI)1 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)1