use of com.biglybt.pif.installer.PluginInstaller 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 ****");
}
});
}
use of com.biglybt.pif.installer.PluginInstaller 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;
}
use of com.biglybt.pif.installer.PluginInstaller 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 });
}
use of com.biglybt.pif.installer.PluginInstaller 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);
}
}
use of com.biglybt.pif.installer.PluginInstaller in project BiglyBT by BiglySoftware.
the class Plugin method execute.
@Override
public void execute(String commandName, final ConsoleInput ci, List args) {
if (args.isEmpty()) {
printHelpExtra(ci.out, args);
return;
}
String subcmd = (String) args.get(0);
if (!java.util.Arrays.asList(new String[] { "location", "list", "listall", "status", "startup", "install", "uninstall", "update" }).contains(subcmd)) {
ci.out.println("Invalid subcommand: " + subcmd);
ci.out.println();
return;
}
PluginManager plugin_manager = ci.getCore().getPluginManager();
if (subcmd.equals("list") || subcmd.equals("listall")) {
boolean all_plugins = subcmd.equals("listall");
ci.out.println("> -----");
PluginInterface[] plugins = plugin_manager.getPluginInterfaces();
TreeSet plugin_ids = new TreeSet(String.CASE_INSENSITIVE_ORDER);
for (int i = 0; i < plugins.length; i++) {
if (!all_plugins && !plugins[i].getPluginState().isOperational()) {
continue;
}
String plugin_id = plugins[i].getPluginID();
plugin_ids.add(plugin_id);
}
TextWrap.printList(plugin_ids.iterator(), ci.out, " ");
ci.out.println("> -----");
return;
}
if (subcmd.equals("location")) {
// Taken from ConfigSectionPlugins.
File fUserPluginDir = FileUtil.getUserFile("plugins");
String sep = File.separator;
String sUserPluginDir;
try {
sUserPluginDir = fUserPluginDir.getCanonicalPath();
} catch (Throwable e) {
sUserPluginDir = fUserPluginDir.toString();
}
if (!sUserPluginDir.endsWith(sep)) {
sUserPluginDir += sep;
}
File fAppPluginDir = FileUtil.getApplicationFile("plugins");
String sAppPluginDir;
try {
sAppPluginDir = fAppPluginDir.getCanonicalPath();
} catch (Throwable e) {
sAppPluginDir = fAppPluginDir.toString();
}
if (!sAppPluginDir.endsWith(sep)) {
sAppPluginDir += sep;
}
ci.out.println("Shared plugin location:");
ci.out.println(" " + sAppPluginDir);
ci.out.println("User plugin location:");
ci.out.println(" " + sUserPluginDir);
ci.out.println();
return;
}
if (subcmd.equals("update")) {
if (args.size() != 1) {
ci.out.println("Usage: update");
return;
}
UpdateManager update_manager = plugin_manager.getDefaultPluginInterface().getUpdateManager();
final UpdateCheckInstance checker = update_manager.createUpdateCheckInstance();
checker.addListener(new UpdateCheckInstanceListener() {
@Override
public void cancelled(UpdateCheckInstance instance) {
}
@Override
public void complete(UpdateCheckInstance instance) {
Update[] updates = instance.getUpdates();
try {
for (Update update : updates) {
ci.out.println("Updating " + update.getName());
for (ResourceDownloader rd : update.getDownloaders()) {
rd.addListener(new ResourceDownloaderAdapter() {
@Override
public void reportActivity(ResourceDownloader downloader, String activity) {
ci.out.println("\t" + activity);
}
@Override
public void reportPercentComplete(ResourceDownloader downloader, int percentage) {
ci.out.println("\t" + percentage + "%");
}
});
rd.download();
}
}
boolean restart_required = false;
for (int i = 0; i < updates.length; i++) {
if (updates[i].getRestartRequired() == Update.RESTART_REQUIRED_YES) {
restart_required = true;
}
}
if (restart_required) {
ci.out.println("**** Restart required to complete update ****");
}
} catch (Throwable e) {
ci.out.println("Plugin update failed: " + Debug.getNestedExceptionMessage(e));
}
}
});
checker.start();
return;
}
if (subcmd.equals("install")) {
if (args.size() == 1) {
ci.out.println("Contacting plugin repository for list of available plugins...");
try {
SFPluginDetails[] plugins = SFPluginDetailsLoaderFactory.getSingleton().getPluginDetails();
for (SFPluginDetails p : plugins) {
String category = p.getCategory();
if (category != null) {
if (category.equalsIgnoreCase("hidden") || (category.equalsIgnoreCase("core"))) {
continue;
}
}
String id = p.getId();
if (plugin_manager.getPluginInterfaceByID(id, false) == null) {
String desc = p.getDescription();
int pos = desc.indexOf("<br");
if (pos > 0) {
desc = desc.substring(0, pos);
}
ci.out.println("\t" + id + ": \t\t" + desc);
}
}
} catch (Throwable e) {
ci.out.println("Failed to list plugins: " + Debug.getNestedExceptionMessage(e));
}
} else {
String target_id = (String) args.get(1);
if (plugin_manager.getPluginInterfaceByID(target_id, false) != null) {
ci.out.println("Plugin '" + target_id + "' already installed");
return;
}
final PluginInstaller installer = plugin_manager.getPluginInstaller();
try {
final StandardPlugin sp = installer.getStandardPlugin(target_id);
if (sp == null) {
ci.out.println("Plugin '" + target_id + "' is unknown");
return;
}
new AEThread2("Plugin Installer") {
@Override
public void run() {
try {
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("plugin-install");
final boolean[] restart_required = { false };
UpdateCheckInstance instance = installer.install(new InstallablePlugin[] { sp }, false, properties, new PluginInstallationListener() {
@Override
public void completed() {
ci.out.println("Installation complete");
sem.release();
}
@Override
public void cancelled() {
ci.out.println("Installation cancelled");
sem.release();
}
@Override
public void failed(PluginException e) {
ci.out.println("Installation failed: " + Debug.getNestedExceptionMessage(e));
sem.release();
}
});
instance.addListener(new UpdateCheckInstanceListener() {
@Override
public void cancelled(UpdateCheckInstance instance) {
ci.out.println("Installation cancelled");
}
@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) {
ci.out.println("\t" + activity);
}
@Override
public void reportPercentComplete(ResourceDownloader downloader, int percentage) {
ci.out.println("\t" + percentage + "%");
}
});
try {
rd.download();
} catch (Throwable e) {
}
}
if (update.getRestartRequired() != Update.RESTART_REQUIRED_NO) {
restart_required[0] = true;
}
}
}
});
sem.reserve();
if (restart_required[0]) {
ci.out.println("**** Restart required to complete installation ****");
}
} catch (Throwable e) {
ci.out.println("Install failed: " + Debug.getNestedExceptionMessage(e));
}
}
}.start();
} catch (Throwable e) {
ci.out.println("Install failed: " + Debug.getNestedExceptionMessage(e));
}
}
return;
}
// Commands from this point require a plugin ID.
if (args.size() == 1) {
ci.out.println("No plugin ID given.");
ci.out.println();
return;
}
String plugin_id = (String) args.get(1);
PluginInterface plugin = plugin_manager.getPluginInterfaceByID(plugin_id, false);
if (plugin == null) {
ci.out.println("Invalid plugin ID: " + plugin_id);
ci.out.println();
return;
}
if (subcmd.equals("status")) {
ci.out.println("ID : " + plugin.getPluginID());
ci.out.println("Name : " + plugin.getPluginName());
ci.out.println("Version: " + plugin.getPluginVersion());
ci.out.println("Running: " + plugin.getPluginState().isOperational());
ci.out.println("Runs at startup: " + plugin.getPluginState().isLoadedAtStartup());
if (!plugin.getPluginState().isBuiltIn()) {
ci.out.println("Location: " + plugin.getPluginDirectoryName());
}
ci.out.println();
return;
}
if (subcmd.equals("startup")) {
if (args.size() == 2) {
ci.out.println("Need to pass either \"on\" or \"off\"");
ci.out.println();
return;
}
String enabled_mode = (String) args.get(2);
if (enabled_mode.equals("on")) {
plugin.getPluginState().setLoadedAtStartup(true);
} else if (enabled_mode.equals("off")) {
plugin.getPluginState().setLoadedAtStartup(false);
} else {
ci.out.println("Need to pass either \"on\" or \"off\"");
ci.out.println();
return;
}
ci.out.println("Done.");
ci.out.println();
return;
}
if (subcmd.equals("uninstall")) {
PluginInterface pi = plugin_manager.getPluginInterfaceByID(plugin_id, false);
if (pi == null) {
ci.out.println("Plugin '" + plugin_id + "' is not installed");
return;
}
final PluginInstaller installer = plugin_manager.getPluginInstaller();
try {
final StandardPlugin sp = installer.getStandardPlugin(plugin_id);
if (sp == null) {
ci.out.println("Plugin '" + plugin_id + "' is not a standard plugin");
return;
}
final PluginInstaller uninstaller = plugin_manager.getPluginInstaller();
Map<Integer, Object> properties = new HashMap<>();
final AESemaphore sem = new AESemaphore("plugin-uninstall");
UpdateCheckInstance instance = uninstaller.uninstall(new PluginInterface[] { pi }, new PluginInstallationListener() {
@Override
public void completed() {
ci.out.println("Uninstallation complete");
sem.release();
}
@Override
public void cancelled() {
ci.out.println("Uninstallation cancelled");
sem.release();
}
@Override
public void failed(PluginException e) {
ci.out.println("Uninstallation failed: " + Debug.getNestedExceptionMessage(e));
sem.release();
}
}, properties);
instance.addListener(new UpdateCheckInstanceListener() {
@Override
public void cancelled(UpdateCheckInstance instance) {
ci.out.println("InsUninstallationtallation cancelled");
}
@Override
public void complete(UpdateCheckInstance instance) {
Update[] updates = instance.getUpdates();
for (final Update update : updates) {
ResourceDownloader[] rds = update.getDownloaders();
for (ResourceDownloader rd : rds) {
try {
rd.download();
} catch (Throwable e) {
}
}
}
}
});
sem.reserve();
Object obj = properties.get(UpdateCheckInstance.PT_UNINSTALL_RESTART_REQUIRED);
if (obj instanceof Boolean && (Boolean) obj) {
ci.out.println("**** Restart required to complete uninstallation ****");
}
} catch (Throwable e) {
ci.out.println("Uninstall failed: " + Debug.getNestedExceptionMessage(e));
}
}
}
Aggregations