use of com.biglybt.pif.installer.InstallablePlugin 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.InstallablePlugin in project BiglyBT by BiglySoftware.
the class PlayerInstaller method install.
public boolean install() {
try {
installer = CoreFactory.getSingleton().getPluginManager().getPluginInstaller();
StandardPlugin sp = installer.getStandardPlugin("azemp");
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("emp install");
final boolean[] result = new boolean[1];
instance = installer.install(new InstallablePlugin[] { sp }, false, properties, new PluginInstallationListener() {
@Override
public void completed() {
result[0] = true;
if (listener != null) {
listener.finished();
}
sem.release();
}
@Override
public void cancelled() {
result[0] = false;
if (listener != null) {
listener.finished();
}
sem.release();
}
@Override
public void failed(PluginException e) {
result[0] = false;
if (listener != null) {
listener.finished();
}
sem.release();
}
});
boolean kill_it;
synchronized (this) {
kill_it = cancelled;
}
if (kill_it) {
instance.cancel();
return (false);
}
instance.addListener(new UpdateCheckInstanceListener() {
@Override
public void cancelled(UpdateCheckInstance instance) {
}
@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) {
}
@Override
public void reportPercentComplete(ResourceDownloader downloader, int percentage) {
if (listener != null) {
listener.progress(percentage);
}
}
});
}
}
}
});
sem.reserve();
return result[0];
} catch (Throwable e) {
}
return false;
}
use of com.biglybt.pif.installer.InstallablePlugin 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.InstallablePlugin in project BiglyBT by BiglySoftware.
the class SimplePluginInstaller method install.
public boolean install() {
try {
installer = CoreFactory.getSingleton().getPluginManager().getPluginInstaller();
StandardPlugin sp = installer.getStandardPlugin(plugin_id);
if (sp == null) {
throw (new Exception("Unknown plugin"));
}
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 Object[] result = new Object[] { null };
instance = installer.install(new InstallablePlugin[] { sp }, false, properties, new PluginInstallationListener() {
@Override
public void completed() {
synchronized (SimplePluginInstaller.this) {
completed = true;
}
result[0] = true;
if (listener != null) {
listener.finished();
}
sem.release();
}
@Override
public void cancelled() {
result[0] = new Exception("Cancelled");
if (listener != null) {
listener.finished();
}
sem.release();
}
@Override
public void failed(PluginException e) {
result[0] = e;
if (listener != null) {
listener.finished();
}
sem.release();
}
});
boolean kill_it;
synchronized (this) {
kill_it = cancelled;
}
if (kill_it) {
instance.cancel();
action_listener.actionComplete(new Exception("Cancelled"));
return (false);
}
instance.addListener(new UpdateCheckInstanceListener() {
@Override
public void cancelled(UpdateCheckInstance instance) {
}
@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) {
}
@Override
public void reportPercentComplete(ResourceDownloader downloader, int percentage) {
if (listener != null) {
listener.progress(percentage);
}
}
});
}
}
}
});
sem.reserve();
action_listener.actionComplete(result[0]);
return (result[0] instanceof Boolean);
} catch (Throwable e) {
if (listener != null) {
listener.finished();
}
action_listener.actionComplete(e);
}
return false;
}
use of com.biglybt.pif.installer.InstallablePlugin 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) {
// Ensure colors initialized
Colors.getInstance();
UIConfigDefaultsSWT.initialize();
UIConfigDefaultsSWTv3.initialize(core);
} 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);
}
}
if (core.canStart()) {
// 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);
}
}
});
} else {
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);
}
}
Aggregations