Search in sources :

Example 1 with UnloadablePlugin

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

the class PluginStateImpl method isUnloadable.

@Override
public boolean isUnloadable() {
    String dir = pi.getPluginDirectoryName();
    // mechanism to override unloadability
    boolean disable_unload = pi.getPluginProperties().getProperty("plugin.unload.disabled", "").equalsIgnoreCase("true");
    if (disable_unload) {
        return false;
    }
    // if not dir based then just test this one
    if (dir == null || dir.length() == 0) {
        return pi.getPlugin() instanceof UnloadablePlugin;
    }
    List pis = PluginInitializer.getPluginInterfaces();
    for (int i = 0; i < pis.size(); i++) {
        PluginInterface pi = (PluginInterface) pis.get(i);
        String other_dir = pi.getPluginDirectoryName();
        if (other_dir == null || other_dir.length() == 0) {
            continue;
        }
        if (dir.equals(other_dir)) {
            if (!(pi.getPlugin() instanceof UnloadablePlugin)) {
                return false;
            }
        }
    }
    for (int i = 0; i < pi.children.size(); i++) {
        if (!((PluginInterface) pi.children.get(i)).getPluginState().isUnloadable()) {
            return false;
        }
    }
    return true;
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) List(java.util.List) ArrayList(java.util.ArrayList) UnloadablePlugin(com.biglybt.pif.UnloadablePlugin)

Example 2 with UnloadablePlugin

use of com.biglybt.pif.UnloadablePlugin 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)

Aggregations

UnloadablePlugin (com.biglybt.pif.UnloadablePlugin)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 PluginException (com.biglybt.pif.PluginException)1 PluginInterface (com.biglybt.pif.PluginInterface)1