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;
}
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();
}
Aggregations