use of com.biglybt.pif.utils.resourcedownloader.ResourceDownloader in project BiglyBT by BiglySoftware.
the class PluginUpdatePlugin method addUpdate.
public Update addUpdate(final PluginInterface pi_for_update, final UpdateChecker checker, final String update_name, final String[] update_details, final String old_version, final String new_version, final ResourceDownloader resource_downloader, final boolean is_jar, final int restart_type, final boolean verify) {
final Update update = checker.addUpdate(update_name, update_details, old_version, new_version, resource_downloader, restart_type);
update.setUserObject(pi_for_update);
resource_downloader.addListener(new ResourceDownloaderAdapter() {
@Override
public boolean completed(final ResourceDownloader downloader, InputStream data) {
// during the update phase report any messages
// to the downloader
LoggerChannelListener list = new LoggerChannelListener() {
@Override
public void messageLogged(int type, String content) {
downloader.reportActivity(content);
}
@Override
public void messageLogged(String str, Throwable error) {
downloader.reportActivity(str);
}
};
try {
log.addListener(list);
installUpdate(checker, update, pi_for_update, restart_type == Update.RESTART_REQUIRED_NO, is_jar, old_version, new_version, data, verify);
return (true);
} finally {
log.removeListener(list);
}
}
@Override
public void failed(ResourceDownloader downloader, ResourceDownloaderException e) {
if (!downloader.isCancelled()) {
Debug.out(downloader.getName() + " failed", e);
}
update.complete(false);
}
});
return (update);
}
use of com.biglybt.pif.utils.resourcedownloader.ResourceDownloader 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.utils.resourcedownloader.ResourceDownloader in project BiglyBT by BiglySoftware.
the class BiglyBTURLConnection method connect.
@Override
public void connect() throws IOException {
String str = url.toExternalForm();
int pos = str.indexOf("body=");
if (pos >= 0) {
str = str.substring(pos + 5);
byte[] bytes = str.getBytes(Constants.BYTE_ENCODING);
VuzeFile vf = VuzeFileHandler.getSingleton().loadVuzeFile(bytes);
if (vf == null) {
throw (new IOException("Invalid biglybt url"));
}
input_stream = new ByteArrayInputStream(bytes);
} else {
String host = url.getHost();
String httpsURL;
if (host.equalsIgnoreCase("install-plugin") && url.getPath().length() > 1) {
String plugin_id = url.getPath().substring(1);
httpsURL = Constants.PLUGINS_WEB_SITE + "getplugin.php?plugin=" + plugin_id + "&" + SFPluginDetailsLoaderImpl.getBaseUrlParams();
} else if (host.contains(".")) {
httpsURL = "https" + str.substring("biglybt".length());
} else {
throw (new IOException("Invalid biglybt url"));
}
ResourceDownloader rd = StaticUtilities.getResourceDownloaderFactory().create(new URL(httpsURL));
try {
if (ONLY_VUZE_FILE) {
VuzeFile vf = VuzeFileHandler.getSingleton().loadVuzeFile(rd.download());
if (vf == null) {
throw (new IOException("Invalid biglybt url"));
}
boolean hasPlugin = false;
VuzeFileComponent[] components = vf.getComponents();
for (VuzeFileComponent component : components) {
if (component.getType() == VuzeFileComponent.COMP_TYPE_PLUGIN) {
hasPlugin = true;
break;
}
}
if (!hasPlugin) {
throw (new IOException("Biglybt url does not contain plugin"));
}
input_stream = new ByteArrayInputStream(vf.exportToBytes());
} else {
input_stream = rd.download();
}
} catch (ResourceDownloaderException e) {
throw new IOException(e);
}
}
}
use of com.biglybt.pif.utils.resourcedownloader.ResourceDownloader in project BiglyBT by BiglySoftware.
the class VuzeFileHandler method loadVuzeFile.
public VuzeFile loadVuzeFile(String target) {
try {
File test_file = new File(target);
test_file = migrateFile(test_file);
if (test_file.isFile()) {
return (getVuzeFile(new FileInputStream(test_file)));
} else {
URL url = new URI(target).toURL();
String protocol = url.getProtocol().toLowerCase();
if (protocol.equals("http") || protocol.equals("https") || protocol.equals("biglybt")) {
ResourceDownloader rd = StaticUtilities.getResourceDownloaderFactory().create(url);
return (getVuzeFile(rd.download()));
}
}
} catch (Throwable e) {
}
return (null);
}
use of com.biglybt.pif.utils.resourcedownloader.ResourceDownloader 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;
}
Aggregations