use of com.biglybt.pif.utils.resourcedownloader.ResourceDownloader in project BiglyBT by BiglySoftware.
the class SFPluginDetailsLoaderImpl method loadPluginList.
protected void loadPluginList() throws SFPluginDetailsException {
try {
String page_url_to_use = addEPIDS(page_url);
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 dl = rd_factory.create(url, proxy);
if (plugin_proxy != null) {
dl.setProperty("URL_HOST", plugin_proxy.getURLHostRewrite());
}
dl = rd_factory.getRetryDownloader(dl, 5);
dl.addListener(this);
Properties details = new Properties();
InputStream is = dl.download();
details.load(is);
is.close();
Iterator it = details.keySet().iterator();
while (it.hasNext()) {
String plugin_id = (String) it.next();
String data = (String) details.get(plugin_id);
int pos = 0;
List bits = new ArrayList();
while (pos < data.length()) {
int p1 = data.indexOf(';', pos);
if (p1 == -1) {
bits.add(data.substring(pos).trim());
break;
} else {
bits.add(data.substring(pos, p1).trim());
pos = p1 + 1;
}
}
if (bits.size() < 3) {
Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR, "SF loadPluginList failed for plugin '" + plugin_id + "'. Details array is " + bits.size() + " (3 min)"));
} else {
String version = (String) bits.get(0);
String cvs_version = (String) bits.get(1);
String name = (String) bits.get(2);
String category = "";
if (bits.size() > 3) {
category = (String) bits.get(3);
}
plugin_ids.add(plugin_id);
plugin_map.put(plugin_id.toLowerCase(MessageText.LOCALE_ENGLISH), new SFPluginDetailsImpl(this, plugin_id, version, cvs_version, name, category));
}
}
ok = true;
break;
} 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);
}
}
plugin_ids_loaded = true;
plugin_ids_loaded_at = SystemTime.getCurrentTime();
} catch (Throwable e) {
Debug.printStackTrace(e);
throw (new SFPluginDetailsException("Plugin list load failed", e));
}
}
use of com.biglybt.pif.utils.resourcedownloader.ResourceDownloader in project BiglyBT by BiglySoftware.
the class ResourceDownloaderFactoryImpl method getSuffixBasedDownloader.
@Override
public ResourceDownloader getSuffixBasedDownloader(ResourceDownloader _downloader) {
ResourceDownloaderBaseImpl dl = (ResourceDownloaderBaseImpl) _downloader;
URL target = null;
while (true) {
List kids = dl.getChildren();
if (kids.size() == 0) {
target = ((ResourceDownloaderURLImpl) dl).getURL();
break;
}
dl = (ResourceDownloaderBaseImpl) kids.get(0);
}
ResourceDownloader result;
if (target == null) {
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID, "ResourceDownloader: suffix " + "based downloader failed to find leaf"));
result = _downloader;
} else {
if (target.getPath().toLowerCase().endsWith(".torrent")) {
result = getTorrentDownloader(_downloader, true);
} else {
result = _downloader;
}
}
if (COConfigurationManager.getBooleanParameter("update.anonymous")) {
try {
((ResourceDownloaderBaseImpl) result).setPropertyRecursive(ResourceDownloader.PR_BOOLEAN_ANONYMOUS, true);
} catch (Throwable e) {
Debug.out(e);
}
}
return (result);
}
use of com.biglybt.pif.utils.resourcedownloader.ResourceDownloader in project BiglyBT by BiglySoftware.
the class ResourceDownloaderMetaRefreshImpl method getSizeSupport.
protected long getSizeSupport() throws ResourceDownloaderException {
try {
ResourceDownloader x = delegate.getClone(this);
addReportListener(x);
HTMLPage page = HTMLPageFactory.loadPage(x.download());
URL base_url = (URL) x.getProperty("URL_URL");
URL redirect = page.getMetaRefreshURL(base_url);
if (redirect == null) {
ResourceDownloaderBaseImpl c = delegate.getClone(this);
addReportListener(c);
long res = c.getSize();
setProperties(c);
return (res);
} else {
ResourceDownloaderURLImpl c = new ResourceDownloaderURLImpl(getParent(), redirect);
addReportListener(c);
long res = c.getSize();
setProperties(c);
return (res);
}
} catch (HTMLException e) {
throw (new ResourceDownloaderException(this, "getSize failed", e));
}
}
use of com.biglybt.pif.utils.resourcedownloader.ResourceDownloader in project BiglyBT by BiglySoftware.
the class ResourceDownloaderTorrentImpl method getSizeSupport.
protected long getSizeSupport() throws ResourceDownloaderException {
try {
if (torrent_holder[0] == null) {
ResourceDownloader x = delegate.getClone(this);
addReportListener(x);
InputStream is = x.download();
try {
torrent_holder[0] = TOTorrentFactory.deserialiseFromBEncodedInputStream(is);
} finally {
try {
is.close();
} catch (IOException e) {
}
}
if (!torrent_holder[0].isSimpleTorrent()) {
throw (new ResourceDownloaderException(this, "Only simple torrents supported"));
}
}
try {
String file_str = new String(torrent_holder[0].getName());
int pos = file_str.lastIndexOf(".");
String file_type;
if (pos != -1) {
file_type = file_str.substring(pos + 1);
} else {
file_type = null;
}
setProperty(ResourceDownloader.PR_STRING_CONTENT_TYPE, HTTPUtils.guessContentTypeFromFileType(file_type));
} catch (Throwable e) {
Debug.printStackTrace(e);
}
return (torrent_holder[0].getSize());
} catch (TOTorrentException e) {
throw (new ResourceDownloaderException(this, "Torrent deserialisation failed", e));
}
}
use of com.biglybt.pif.utils.resourcedownloader.ResourceDownloader in project BiglyBT by BiglySoftware.
the class CorePatchChecker method patch.
protected void patch(UpdateCheckInstance instance, Update updater_update, PluginInterface updater_plugin) {
try {
// use the update plugin to log stuff....
ResourceDownloader rd_log = updater_update.getDownloaders()[0];
File[] files = new File(updater_plugin.getPluginDirectoryName()).listFiles();
if (files == null) {
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID, "Core Patcher: no files in plugin dir!!!"));
return;
}
String patch_prefix = "BiglyBT_" + Constants.getBaseVersion() + "_P";
int highest_p = -1;
File highest_p_file = null;
for (int i = 0; i < files.length; i++) {
String name = files[i].getName();
if (name.startsWith(patch_prefix) && name.endsWith(".pat")) {
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID, "Core Patcher: found patch file '" + name + "'"));
try {
int this_p = Integer.parseInt(name.substring(patch_prefix.length(), name.indexOf(".pat")));
if (this_p > highest_p) {
highest_p = this_p;
highest_p_file = files[i];
}
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
}
if (CorePatchLevel.getCurrentPatchLevel() >= highest_p) {
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID, "Core Patcher: no applicable patch found (highest = " + highest_p + ")"));
if (updater_update.getRestartRequired() == Update.RESTART_REQUIRED_MAYBE) {
updater_update.setRestartRequired(Update.RESTART_REQUIRED_NO);
}
} else {
rd_log.reportActivity("Applying patch '" + highest_p_file.getName() + "'");
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID, "Core Patcher: applying patch '" + highest_p_file.toString() + "'"));
InputStream pis = new FileInputStream(highest_p_file);
try {
patchBiglyBT(instance, pis, "P" + highest_p, plugin_interface.getLogger().getChannel("CorePatcher"));
Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_INFORMATION, "Patch " + highest_p_file.getName() + " ready to be applied"));
String done_file = highest_p_file.toString();
done_file = done_file.substring(0, done_file.length() - 1) + "x";
highest_p_file.renameTo(new File(done_file));
// flip the original update over to 'restart required'
updater_update.setRestartRequired(Update.RESTART_REQUIRED_YES);
} finally {
try {
pis.close();
} catch (Throwable e) {
}
}
}
} catch (Throwable e) {
Debug.printStackTrace(e);
Logger.log(new LogAlert(LogAlert.UNREPEATABLE, "Core Patcher failed", e));
}
}
Aggregations