Search in sources :

Example 11 with PluginException

use of com.biglybt.pif.PluginException 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 12 with PluginException

use of com.biglybt.pif.PluginException in project BiglyBT by BiglySoftware.

the class PluginStateImpl method unload.

protected void unload(boolean for_reload) throws PluginException {
    if (!isUnloadable()) {
        throw new PluginException("Plugin isn't unloadable");
    }
    String dir = pi.getPluginDirectoryName();
    // if not dir based then just test this one
    if (dir == null || dir.length() == 0) {
        try {
            ((UnloadablePlugin) pi.getPlugin()).unload();
        } catch (Throwable e) {
            Debug.out("Plugin unload operation failed", e);
        }
        initialiser.unloadPlugin(this.pi);
    } else {
        // we must copy the list here as when we unload interfaces they will be
        // removed from the original list
        List pis = new ArrayList(PluginInitializer.getPluginInterfaces());
        for (int i = 0; i < pis.size(); i++) {
            PluginInterfaceImpl pi = (PluginInterfaceImpl) pis.get(i);
            String other_dir = pi.getPluginDirectoryName();
            if (other_dir == null || other_dir.length() == 0) {
                continue;
            }
            if (dir.equals(other_dir)) {
                try {
                    ((UnloadablePlugin) pi.getPlugin()).unload();
                } catch (Throwable e) {
                    Debug.out("Plugin unload operation failed", e);
                }
                initialiser.unloadPlugin(pi);
            }
        }
    }
    for (int i = 0; i < pi.children.size(); i++) {
        ((PluginStateImpl) ((PluginInterface) pi.children.get(i)).getPluginState()).unload(for_reload);
    }
    setOperational(false, for_reload);
    pi.destroy();
}
Also used : PluginException(com.biglybt.pif.PluginException) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) UnloadablePlugin(com.biglybt.pif.UnloadablePlugin)

Example 13 with PluginException

use of com.biglybt.pif.PluginException in project BiglyBT by BiglySoftware.

the class PluginManagerImpl method startClient.

/**
 * Starts client.
 * <p>
 * With the exception of null ui, method does not return until client is closed.
 *
 * @param ui "swt", "console", "telnet", etc
 * @param properties
 */
public static void startClient(String ui, Properties properties, final StartClientListener startClientListener) throws PluginException {
    try {
        class_mon.enter();
        if (running) {
            throw (new RuntimeException(Constants.APP_NAME + " is already running"));
        }
        running = true;
    } finally {
        class_mon.exit();
    }
    String config_dir = (String) properties.get(PR_USER_DIRECTORY);
    if (config_dir != null) {
        System.setProperty(SystemProperties.SYSPROP_CONFIG_PATH, config_dir);
    }
    String user_dir = (String) properties.get(PR_APP_DIRECTORY);
    if (user_dir != null) {
        System.setProperty(SystemProperties.SYSPROP_INSTALL_PATH, user_dir);
        System.setProperty("user.dir", user_dir);
    }
    String doc_dir = (String) properties.get(PR_DOC_DIRECTORY);
    if (doc_dir != null) {
        System.setProperty(SystemProperties.SYSPROP_DOC_PATH, doc_dir);
    }
    String disable_native = (String) properties.get(PR_DISABLE_NATIVE_SUPPORT);
    if (disable_native != null && disable_native.equalsIgnoreCase("true")) {
        System.setProperty(SystemProperties.SYSPROP_PLATFORM_MANAGER_DISABLE, "true");
    }
    if (startClientListener != null) {
        CoreFactory.addCoreRunningListener(new CoreRunningListener() {

            @Override
            public void coreRunning(Core core) {
                startClientListener.clientStarted(core.getPluginManager());
            }
        });
    }
    if (ui == null) {
        try {
            core = CoreFactory.create();
            core.start();
        } catch (Throwable e) {
            Debug.printStackTrace(e);
            throw (new PluginException(Constants.APP_NAME + " failed to start", e));
        }
    } else {
        // Most likely, a plugin is calling this from their main(), which
        // will not be using our primary class loader.  Which means we already
        // have some core classes initialized on it, making it too late to
        // switch. (For example, aereg.dll will already be loaded, and the class
        // loading switch will cause an exception when trying to laod it again)
        System.setProperty("USE_OUR_PRIMARYCLASSLOADER", "0");
        String mi = (String) properties.get(PluginManager.PR_MULTI_INSTANCE);
        if (mi != null && mi.equalsIgnoreCase("true")) {
            System.setProperty(PluginManager.PR_MULTI_INSTANCE, "true");
        }
        try {
            Class.forName("com.biglybt.ui.Main").getMethod("main", new Class[] { String[].class }).invoke(null, (Object) new String[] { "--ui=" + ui });
        } catch (Throwable e) {
            throw (new PluginException("Main method invocation failed", e));
        }
    }
}
Also used : PluginException(com.biglybt.pif.PluginException) CoreRunningListener(com.biglybt.core.CoreRunningListener) Core(com.biglybt.core.Core)

Example 14 with PluginException

use of com.biglybt.pif.PluginException 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);
                List<? extends 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)

Example 15 with PluginException

use of com.biglybt.pif.PluginException in project BiglyBT by BiglySoftware.

the class RemotePairingWindow method installWebUI.

protected void installWebUI() {
    final PluginInstaller installer = CoreFactory.getSingleton().getPluginManager().getPluginInstaller();
    StandardPlugin vuze_plugin = null;
    try {
        vuze_plugin = installer.getStandardPlugin(PLUGINID_WEBUI);
    } catch (Throwable e) {
    }
    if (vuze_plugin == null) {
        return;
    }
    if (vuze_plugin.isAlreadyInstalled()) {
        PluginInterface plugin = vuze_plugin.getAlreadyInstalledPlugin();
        plugin.getPluginState().setDisabled(false);
        return;
    }
    try {
        switchToFTUX();
        final SWTSkinObject soInstall = skin.getSkinObject("pairing-install");
        final SWTSkinObject soLearnMore = skin.getSkinObject("learn-more");
        if (soLearnMore != null) {
            soLearnMore.setVisible(false);
        }
        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, soInstall.getControl());
        properties.put(UpdateCheckInstance.PT_UI_DISABLE_ON_SUCCESS_SLIDEY, true);
        installer.install(new InstallablePlugin[] { vuze_plugin }, false, properties, new PluginInstallationListener() {

            @Override
            public void completed() {
                if (soLearnMore != null) {
                    soLearnMore.setVisible(true);
                }
                switchToCode();
            }

            @Override
            public void cancelled() {
                Utils.execSWTThread(new AERunnable() {

                    @Override
                    public void runSupport() {
                        if (skinnedDialog != null && !skinnedDialog.isDisposed()) {
                            skinnedDialog.close();
                            skinnedDialog = null;
                        }
                    }
                });
            }

            @Override
            public void failed(PluginException e) {
                Debug.out(e);
            // Utils.openMessageBox(Utils.findAnyShell(), SWT.OK, "Error",
            // e.toString());
            }
        });
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    }
}
Also used : HashMap(java.util.HashMap) PluginInterface(com.biglybt.pif.PluginInterface) PluginException(com.biglybt.pif.PluginException)

Aggregations

PluginException (com.biglybt.pif.PluginException)17 PluginInterface (com.biglybt.pif.PluginInterface)7 InstallablePlugin (com.biglybt.pif.installer.InstallablePlugin)6 PluginInstallationListener (com.biglybt.pif.installer.PluginInstallationListener)6 StandardPlugin (com.biglybt.pif.installer.StandardPlugin)6 HashMap (java.util.HashMap)6 AESemaphore (com.biglybt.core.util.AESemaphore)4 Update (com.biglybt.pif.update.Update)4 UpdateCheckInstance (com.biglybt.pif.update.UpdateCheckInstance)4 UpdateCheckInstanceListener (com.biglybt.pif.update.UpdateCheckInstanceListener)4 PluginInstaller (com.biglybt.pif.installer.PluginInstaller)3 ResourceDownloader (com.biglybt.pif.utils.resourcedownloader.ResourceDownloader)3 ResourceDownloaderAdapter (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 ParameterListener (com.biglybt.core.config.ParameterListener)2 GlobalManager (com.biglybt.core.global.GlobalManager)2 TOTorrent (com.biglybt.core.torrent.TOTorrent)2 PluginManager (com.biglybt.pif.PluginManager)2