use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.
the class PlatformManagerImpl method startup.
@Override
public void startup(final Core core) throws PlatformManagerException {
AEDiagnostics.addWeakEvidenceGenerator(this);
if (!hasCapability(PlatformManagerCapabilities.AccessExplicitVMOptions)) {
return;
}
if (COConfigurationManager.getBooleanParameter("platform.win32.vmo.migrated", false)) {
try {
File local_options = checkAndGetLocalVMOptionFile();
if (local_options.exists()) {
File last_good = new File(local_options.getParentFile(), local_options.getName() + ".lastgood");
if (!last_good.exists() || local_options.lastModified() > last_good.lastModified()) {
FileUtil.copyFile(local_options, last_good);
}
}
} catch (Throwable e) {
Debug.out(e);
}
} else {
final int fail_count = COConfigurationManager.getIntParameter("platform.win32.vmo.migrated.fails", 0);
if (fail_count >= 3) {
Debug.out("Not attempting vmoption migration due to previous failures, please perform a full install to fix this");
return;
}
// we need an up-to-date version of this to do the migration...
PluginInterface pi = core.getPluginManager().getPluginInterfaceByID("azupdater");
if (pi != null && Constants.compareVersions(pi.getPluginVersion(), "1.8.15") >= 0) {
new AEThread2("win32.vmo", true) {
@Override
public void run() {
try {
String redirect = getJVMOptionRedirect();
File[] option_files = getJVMOptionFiles();
if (option_files.length != 2) {
return;
}
File shared_options = option_files[0];
File old_shared_options = new File(shared_options.getParentFile(), shared_options.getName() + ".old");
File local_options = option_files[1];
if (shared_options.exists()) {
String options = FileUtil.readFileAsString(shared_options, -1);
if (!options.contains(redirect)) {
if (!options.contains("-include-options")) {
if (FileUtil.canReallyWriteToAppDirectory()) {
if (old_shared_options.exists()) {
old_shared_options.delete();
}
if (shared_options.renameTo(old_shared_options)) {
if (!local_options.exists()) {
if (!FileUtil.copyFile(old_shared_options, local_options)) {
Debug.out("Failed to copy " + old_shared_options + " to " + local_options);
}
}
if (!FileUtil.writeStringAsFile(shared_options, redirect + "\r\n")) {
Debug.out("Failed to write to " + shared_options);
}
} else {
Debug.out("Rename of " + shared_options + " to " + old_shared_options + " failed");
}
} else {
// insufficient perms
UpdateInstaller installer = getInstaller(core);
if (installer == null) {
return;
}
if (!informUpdateRequired()) {
return;
}
if (old_shared_options.exists()) {
installer.addRemoveAction(old_shared_options.getAbsolutePath());
}
installer.addMoveAction(shared_options.getAbsolutePath(), old_shared_options.getAbsolutePath());
if (!local_options.exists()) {
installer.addResource("local_options", new ByteArrayInputStream(options.getBytes("UTF-8")));
installer.addMoveAction("local_options", local_options.getAbsolutePath());
}
installer.addResource("redirect", new ByteArrayInputStream((redirect + "\r\n").getBytes("UTF-8")));
installer.addMoveAction("redirect", shared_options.getAbsolutePath());
final AESemaphore sem = new AESemaphore("vmopt");
final UpdateException[] error = { null };
installer.installNow(new UpdateInstallerListener() {
@Override
public void reportProgress(String str) {
}
@Override
public void complete() {
sem.release();
}
@Override
public void failed(UpdateException e) {
error[0] = e;
sem.release();
}
});
sem.reserve();
if (error[0] != null) {
throw (error[0]);
}
}
}
} else {
if (old_shared_options.exists() && !local_options.exists()) {
if (!FileUtil.copyFile(old_shared_options, local_options)) {
Debug.out("Failed to copy " + old_shared_options + " to " + local_options);
}
}
}
} else {
if (FileUtil.canReallyWriteToAppDirectory()) {
if (!FileUtil.writeStringAsFile(shared_options, redirect + "\r\n")) {
Debug.out("Failed to write to " + shared_options);
}
} else {
// insufficient perms
UpdateInstaller installer = getInstaller(core);
if (installer == null) {
return;
}
if (!informUpdateRequired()) {
return;
}
installer.addResource("redirect", new ByteArrayInputStream((redirect + "\r\n").getBytes("UTF-8")));
installer.addMoveAction("redirect", shared_options.getAbsolutePath());
final AESemaphore sem = new AESemaphore("vmopt");
final UpdateException[] error = { null };
installer.installNow(new UpdateInstallerListener() {
@Override
public void reportProgress(String str) {
}
@Override
public void complete() {
sem.release();
}
@Override
public void failed(UpdateException e) {
error[0] = e;
sem.release();
}
});
sem.reserve();
if (error[0] != null) {
throw (error[0]);
}
}
}
COConfigurationManager.setParameter("platform.win32.vmo.migrated", true);
} catch (Throwable e) {
COConfigurationManager.setParameter("platform.win32.vmo.migrated.fails", fail_count + 1);
Debug.out("vmoption migration failed", e);
}
}
}.start();
}
}
}
use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.
the class SFPluginDetailsLoaderImpl method loadPluginDetails.
protected void loadPluginDetails(SFPluginDetailsImpl details) throws SFPluginDetailsException {
try {
String page_url_to_use = site_prefix + "update/pluginlist3.php?plugin=" + UrlUtils.encode(details.getId()) + "&" + base_url_params;
page_url_to_use = addEPIDS(page_url_to_use);
try {
PluginInterface defPI = PluginInitializer.getDefaultInterface();
PluginInterface pi = defPI == null ? null : defPI.getPluginManager().getPluginInterfaceByID(details.getId(), false);
if (pi != null) {
String existing_version = pi.getPluginVersion();
if (existing_version != null) {
page_url_to_use += "&ver_" + details.getId() + "=" + UrlUtils.encode(existing_version);
}
}
} catch (Throwable e) {
Debug.out(e);
}
URL original_url = new URL(page_url_to_use);
URL url = original_url;
Proxy proxy = null;
PluginProxy plugin_proxy = null;
boolean tried_proxy = false;
boolean ok = false;
if (COConfigurationManager.getBooleanParameter("update.anonymous")) {
tried_proxy = true;
plugin_proxy = AEProxyFactory.getPluginProxy("loading plugin details", url);
if (plugin_proxy == null) {
throw (new SFPluginDetailsException("Proxy not available"));
} else {
url = plugin_proxy.getURL();
proxy = plugin_proxy.getProxy();
}
}
try {
while (true) {
try {
ResourceDownloader p_dl = rd_factory.create(url, proxy);
if (proxy != null) {
p_dl.setProperty("URL_HOST", original_url.getHost());
}
p_dl = rd_factory.getRetryDownloader(p_dl, 5);
p_dl.addListener(this);
InputStream is = p_dl.download();
try {
if (!processPluginStream(details, is)) {
throw (new SFPluginDetailsException("Plugin details load fails for '" + details.getId() + "': data not found"));
}
ok = true;
break;
} finally {
is.close();
}
} catch (Throwable e) {
if (!tried_proxy) {
tried_proxy = true;
plugin_proxy = AEProxyFactory.getPluginProxy("loading plugin details", url);
if (plugin_proxy == null) {
throw (e);
} else {
url = plugin_proxy.getURL();
proxy = plugin_proxy.getProxy();
}
} else {
throw (e);
}
}
}
} finally {
if (plugin_proxy != null) {
plugin_proxy.setOK(ok);
}
}
} catch (Throwable e) {
Debug.printStackTrace(e);
throw (new SFPluginDetailsException("Plugin details load fails", e));
}
}
use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.
the class SFPluginDetailsLoaderImpl method addEPIDS.
private String addEPIDS(String str) {
try {
String pids = "";
PluginInterface[] pis = PluginInitializer.getDefaultInterface().getPluginManager().getPluginInterfaces();
for (PluginInterface pi : pis) {
PluginState ps = pi.getPluginState();
if (!(ps.isBuiltIn() || ps.isDisabled())) {
String version = pi.getPluginVersion();
if (version != null && Constants.compareVersions(version, "0") > 0) {
String pid = pi.getPluginID();
if (pid != null && pid.length() > 0) {
pids += pid + ":";
}
}
}
}
str += "&epids=" + UrlUtils.encode(pids);
} catch (Throwable e) {
Debug.out(e);
}
return (str);
}
use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.
the class MySharesView method refreshToolBarItems.
@Override
public void refreshToolBarItems(Map<String, Long> list) {
boolean start = false, stop = false, remove = false;
if (!CoreFactory.isCoreRunning()) {
return;
}
List items = getSelectedItems();
if (items.size() > 0) {
PluginInterface pi = PluginInitializer.getDefaultInterface();
com.biglybt.pif.download.DownloadManager dm = pi.getDownloadManager();
remove = true;
for (int i = 0; i < items.size(); i++) {
ShareItem item = (ShareItem) items.get(i);
try {
Torrent t = item.getTorrent();
Download download = dm.getDownload(t);
if (download == null) {
continue;
}
int dl_state = download.getState();
if (dl_state == Download.ST_ERROR) {
} else if (dl_state != Download.ST_STOPPED) {
stop = true;
} else {
start = true;
}
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
}
list.put("start", start ? UIToolBarItem.STATE_ENABLED : 0);
list.put("stop", stop ? UIToolBarItem.STATE_ENABLED : 0);
list.put("remove", remove ? UIToolBarItem.STATE_ENABLED : 0);
}
use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.
the class MyTorrentsView method createTableView.
protected TableViewSWT<DownloadManager> createTableView(Class<?> forDataSourceType, String tableID, TableColumnCore[] basicItems) {
int tableExtraStyle = COConfigurationManager.getIntParameter("MyTorrentsView.table.style");
TableViewSWT<DownloadManager> table = TableViewFactory.createTableViewSWT(forDataSourceType, tableID, getPropertiesPrefix(), basicItems, "#", tableExtraStyle | SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL | SWT.CASCADE);
// config??
boolean enable_tab_views = !Utils.isAZ2UI() && supportsTabs && COConfigurationManager.getBooleanParameter("Library.ShowTabsInTorrentView");
List<String> restrictTo = new ArrayList<>();
restrictTo.addAll(Arrays.asList(GeneralView.MSGID_PREFIX, TrackerView.MSGID_PREFIX, PeersView.MSGID_PREFIX, PeersGraphicView.MSGID_PREFIX, PiecesView.MSGID_PREFIX, DownloadActivityView.MSGID_PREFIX, PieceInfoView.MSGID_PREFIX, FilesView.MSGID_PREFIX, TaggingView.MSGID_PREFIX, PrivacyView.MSGID_PREFIX));
// sub-tab hacks
restrictTo.add("azbuddy.ui.menu.chat");
PluginManager pm = CoreFactory.getSingleton().getPluginManager();
PluginInterface pi = pm.getPluginInterfaceByID("aercm", true);
if (pi != null) {
String pluginInfo = pi.getPluginconfig().getPluginStringParameter("plugin.info", "");
if (pluginInfo.equals("e")) {
restrictTo.add("rcm.subview.torrentdetails.name");
}
}
pi = pm.getPluginInterfaceByID("3dview", true);
if (pi != null) {
restrictTo.add("view3d.subtab.name");
}
if (Logger.isEnabled()) {
restrictTo.add(LoggerView.MSGID_PREFIX);
}
table.setEnableTabViews(enable_tab_views, false, restrictTo.toArray(new String[0]));
UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
if (uiFunctions != null) {
UISWTInstance pluginUI = uiFunctions.getUISWTInstance();
registerPluginViews(pluginUI);
}
return (table);
}
Aggregations