use of com.biglybt.core.vuzefile.VuzeFile in project BiglyBT by BiglySoftware.
the class VuzeURLConnection method connect.
@Override
public void connect() throws IOException {
String str = url.toExternalForm();
int pos = str.indexOf("=");
str = str.substring(pos + 1);
byte[] bytes = str.getBytes(Constants.BYTE_ENCODING);
VuzeFile vf = VuzeFileHandler.getSingleton().loadVuzeFile(bytes);
if (vf == null) {
throw (new IOException("Invalid vuze file"));
}
input_stream = new ByteArrayInputStream(bytes);
}
use of com.biglybt.core.vuzefile.VuzeFile in project BiglyBT by BiglySoftware.
the class CustomizationManagerImpl method exportCustomization.
protected void exportCustomization(CustomizationImpl cust, File to_file) throws CustomizationException {
if (to_file.isDirectory()) {
to_file = new File(to_file, VuzeFileHandler.getVuzeFileName(cust.getName() + "_" + cust.getVersion()));
}
if (!VuzeFileHandler.isAcceptedVuzeFileName(to_file.getName())) {
to_file = new File(to_file.getParentFile(), VuzeFileHandler.getVuzeFileName(to_file.getName()));
}
try {
Map contents = new HashMap();
byte[] data = FileUtil.readFileAsByteArray(cust.getContents());
contents.put("name", cust.getName());
contents.put("version", cust.getVersion());
contents.put("data", data);
VuzeFile vf = VuzeFileHandler.getSingleton().create();
vf.addComponent(VuzeFileComponent.COMP_TYPE_CUSTOMIZATION, contents);
vf.write(to_file);
} catch (Throwable e) {
throw (new CustomizationException("Failed to export customization", e));
}
}
use of com.biglybt.core.vuzefile.VuzeFile in project BiglyBT by BiglySoftware.
the class EngineImpl method exportToVuzeFile.
@Override
public void exportToVuzeFile(File target) throws IOException {
VuzeFile vf = VuzeFileHandler.getSingleton().create();
vf.addComponent(VuzeFileComponent.COMP_TYPE_METASEARCH_TEMPLATE, exportToBencodedMap());
vf.write(target);
}
use of com.biglybt.core.vuzefile.VuzeFile in project BiglyBT by BiglySoftware.
the class MetaSearchImpl method updateEngine.
protected boolean updateEngine(EngineImpl engine) {
String update_url = engine.getUpdateURL();
int pos = update_url.indexOf('?');
if (pos == -1) {
update_url += "?";
} else {
update_url += "&";
}
update_url += "az_template_uid=" + engine.getUID() + "&az_template_version=" + engine.getVersion() + "&az_version=" + Constants.AZUREUS_VERSION + "&az_locale=" + MessageText.getCurrentLocale().toString() + "&az_rand=" + RandomUtils.nextAbsoluteLong();
log("Engine " + engine.getName() + ": auto-update check via " + update_url);
try {
ResourceDownloaderFactory rdf = StaticUtilities.getResourceDownloaderFactory();
ResourceDownloader url_rd = rdf.create(new URL(update_url));
ResourceDownloader rd = rdf.getMetaRefreshDownloader(url_rd);
InputStream is = rd.download();
try {
Map<String, Object> map = BDecoder.decode(new BufferedInputStream(is));
log(" update check reply: " + map);
// reply is either "response" meaning "no update" and giving possibly changed update secs
// or Vuze file with updated template
Map<String, Object> response = (Map<String, Object>) map.get("response");
if (response != null) {
Long update_secs = (Long) response.get("update_url_check_secs");
if (update_secs == null) {
engine.setLocalUpdateCheckSecs(0);
} else {
int check_secs = update_secs.intValue();
if (check_secs < MIN_UPDATE_CHECK_SECS) {
log(" update check secs for to small, min is " + MIN_UPDATE_CHECK_SECS);
check_secs = MIN_UPDATE_CHECK_SECS;
}
engine.setLocalUpdateCheckSecs(check_secs);
}
return (true);
} else {
VuzeFile vf = VuzeFileHandler.getSingleton().loadVuzeFile(map);
if (vf == null) {
log(" failed to decode vuze file");
return (false);
}
Engine[] updated_engines = manager.loadFromVuzeFile(vf);
if (updated_engines.length > 0) {
String existing_uid = engine.getUID();
boolean found = false;
String engine_str = "";
for (int i = 0; i < updated_engines.length; i++) {
Engine updated_engine = updated_engines[i];
engine_str += (i == 0 ? "" : ",") + updated_engine.getName() + ": uid=" + updated_engine.getUID() + ",version=" + updated_engine.getVersion();
if (updated_engine.getUID().equals(existing_uid)) {
found = true;
}
}
if (!found) {
log(" existing engine not found in updated set, deleting");
engine.delete();
}
log(" update complete: new engines=" + engine_str);
} else {
log(" no engines found in vuze file");
}
return (true);
}
} finally {
is.close();
}
} catch (Throwable e) {
log(" update check failed", e);
return (false);
}
}
use of com.biglybt.core.vuzefile.VuzeFile in project BiglyBT by BiglySoftware.
the class MetaSearchManagerImpl method main.
public static void main(String[] args) {
try {
VuzeFile vf = VuzeFileHandler.getSingleton().create();
Map contents = new HashMap();
contents.put("type", new Long(1));
contents.put("term", "donkey");
vf.addComponent(VuzeFileComponent.COMP_TYPE_METASEARCH_OPERATION, contents);
vf.write(new File("C:\\temp\\search.vuze"));
} catch (Throwable e) {
e.printStackTrace();
}
}
Aggregations