use of com.biglybt.core.torrent.TOTorrentException 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.core.torrent.TOTorrentException in project BiglyBT by BiglySoftware.
the class ImportTorrentWizard method performImport.
protected boolean performImport() {
File input_file;
try {
input_file = new File(getImportFile()).getCanonicalFile();
} catch (IOException e) {
MessageBox mb = new MessageBox(getWizardWindow(), SWT.ICON_ERROR | SWT.OK);
mb.setText(MessageText.getString("importTorrentWizard.process.inputfilebad.title"));
mb.setMessage(MessageText.getString("importTorrentWizard.process.inputfilebad.message") + "\n" + e.toString());
mb.open();
return (false);
}
File output_file = new File(getTorrentFile());
if (output_file.exists()) {
MessageBox mb = new MessageBox(this.getWizardWindow(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
mb.setText(MessageText.getString("importTorrentWizard.process.outputfileexists.title"));
mb.setMessage(MessageText.getString("importTorrentWizard.process.outputfileexists.message"));
int result = mb.open();
if (result == SWT.NO) {
return (false);
}
}
String error_title;
String error_detail;
try {
TOTorrent torrent;
try {
torrent = TOTorrentFactory.deserialiseFromXMLFile(input_file);
try {
torrent.serialiseToBEncodedFile(output_file);
return (true);
} catch (TOTorrentException e) {
// e.printStackTrace();
error_title = MessageText.getString("importTorrentWizard.process.torrentfail.title");
error_detail = TorrentUtils.exceptionToText(e);
}
} catch (TOTorrentException e) {
// e.printStackTrace();
error_title = MessageText.getString("importTorrentWizard.process.importfail.title");
error_detail = TorrentUtils.exceptionToText(e);
}
} catch (Throwable e) {
error_title = MessageText.getString("importTorrentWizard.process.unknownfail.title");
Debug.printStackTrace(e);
error_detail = e.toString();
}
MessageBox mb = new MessageBox(this.getWizardWindow(), SWT.ICON_ERROR | SWT.OK);
mb.setText(error_title);
mb.setMessage(error_detail);
mb.open();
return (false);
}
use of com.biglybt.core.torrent.TOTorrentException in project BiglyBT by BiglySoftware.
the class DiskManagerImpl method deleteDataFileContents.
private static void deleteDataFileContents(TOTorrent torrent, String torrent_save_dir, String torrent_save_file, boolean force_no_recycle) throws TOTorrentException, UnsupportedEncodingException, LocaleUtilEncodingException {
LocaleUtilDecoder locale_decoder = LocaleTorrentUtil.getTorrentEncoding(torrent);
TOTorrentFile[] files = torrent.getFiles();
String root_path = torrent_save_dir + File.separator + torrent_save_file + File.separator;
boolean delete_if_not_in_dir = COConfigurationManager.getBooleanParameter("File.delete.include_files_outside_save_dir");
for (int i = 0; i < files.length; i++) {
byte[][] path_comps = files[i].getPathComponents();
String path_str = root_path;
for (int j = 0; j < path_comps.length; j++) {
try {
String comp = locale_decoder.decodeString(path_comps[j]);
comp = FileUtil.convertOSSpecificChars(comp, j != path_comps.length - 1);
path_str += (j == 0 ? "" : File.separator) + comp;
} catch (UnsupportedEncodingException e) {
Debug.out("file - unsupported encoding!!!!");
}
}
File file = new File(path_str);
File linked_file = FMFileManagerFactory.getSingleton().getFileLink(torrent, i, file);
boolean delete;
if (linked_file == file) {
delete = true;
} else {
try {
if (delete_if_not_in_dir || linked_file.getCanonicalPath().startsWith(new File(root_path).getCanonicalPath())) {
file = linked_file;
delete = true;
} else {
delete = false;
}
} catch (Throwable e) {
Debug.printStackTrace(e);
delete = false;
}
}
if (delete && file.exists() && !file.isDirectory()) {
try {
FileUtil.deleteWithRecycle(file, force_no_recycle);
} catch (Exception e) {
Debug.out(e.toString());
}
}
}
TorrentUtils.recursiveEmptyDirDelete(new File(torrent_save_dir, torrent_save_file));
}
use of com.biglybt.core.torrent.TOTorrentException in project BiglyBT by BiglySoftware.
the class PEPeerControlImpl method start.
@Override
public void start() {
// This torrent Hash
try {
_hash = PeerIdentityManager.createDataID(disk_mgr.getTorrent().getHash());
} catch (TOTorrentException e) {
// this should never happen
Debug.printStackTrace(e);
_hash = PeerIdentityManager.createDataID(new byte[20]);
}
// the recovered active pieces
for (int i = 0; i < _nbPieces; i++) {
final DiskManagerPiece dmPiece = dm_pieces[i];
if (!dmPiece.isDone() && dmPiece.getNbWritten() > 0) {
addPiece(new PEPieceImpl(piecePicker, dmPiece, 0), i, true, null);
}
}
// The peer connections
peer_transports_cow = new ArrayList();
// BtManager is threaded, this variable represents the
// current loop iteration. It's used by some components only called
// at some specific times.
mainloop_loop_count = 0;
// The current tracker state
// this could be start or update
_averageReceptionSpeed = Average.getInstance(1000, 30);
// the stats
_stats = new PEPeerManagerStatsImpl(this);
superSeedMode = (COConfigurationManager.getBooleanParameter("Use Super Seeding") && this.getRemaining() == 0);
superSeedModeCurrentPiece = 0;
if (superSeedMode) {
initialiseSuperSeedMode();
}
// initial check on finished state - future checks are driven by piece check results
// Moved out of mainLoop() so that it runs immediately, possibly changing
// the state to seeding.
checkFinished(true);
UploadSlotManager.getSingleton().registerHelper(upload_helper);
lastNeededUndonePieceChange = Long.MIN_VALUE;
_timeStarted = SystemTime.getCurrentTime();
_timeStarted_mono = SystemTime.getMonotonousTime();
is_running = true;
// activate after marked as running as we may synchronously add connections here due to pending activations
PeerManagerRegistration reg = adapter.getPeerManagerRegistration();
if (reg != null) {
reg.activate(this);
}
PeerNATTraverser.getSingleton().register(this);
PeerControlSchedulerFactory.getSingleton(partition_id).register(this);
}
use of com.biglybt.core.torrent.TOTorrentException in project BiglyBT by BiglySoftware.
the class TRTrackerDHTScraperImpl method scrape.
public TRTrackerScraperResponse scrape(TOTorrent torrent, URL unused_target_url, boolean unused_force) {
if (torrent != null) {
try {
HashWrapper hw = torrent.getHashWrapper();
TRTrackerDHTScraperResponseImpl response;
synchronized (responses) {
response = responses.get(hw);
}
if (response == null) {
TRTrackerScraperClientResolver resolver = scraper.getClientResolver();
if (resolver != null) {
int[] cache = resolver.getCachedScrape(hw);
if (cache != null) {
response = new TRTrackerDHTScraperResponseImpl(hw, torrent.getAnnounceURL());
response.setSeedsPeers(cache[0], cache[1]);
long now = SystemTime.getCurrentTime();
response.setScrapeStartTime(now);
response.setNextScrapeStartTime(now + 5 * 60 * 1000);
response.setStatus(TRTrackerScraperResponse.ST_ONLINE, MessageText.getString("Scrape.status.cached"));
synchronized (responses) {
responses.put(torrent.getHashWrapper(), response);
}
scraper.scrapeReceived(response);
}
}
}
return (response);
} catch (TOTorrentException e) {
Debug.printStackTrace(e);
}
}
return (null);
}
Aggregations