use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.
the class FMFileAccessController method setControlFile.
protected void setControlFile() {
TOTorrentFile tf = owner.getOwner().getTorrentFile();
if (tf == null) {
controlFileName = null;
control_dir = null;
} else {
TOTorrent torrent = tf.getTorrent();
TOTorrentFile[] files = torrent.getFiles();
int file_index = -1;
for (int i = 0; i < files.length; i++) {
if (files[i] == tf) {
file_index = i;
break;
}
}
if (file_index == -1) {
Debug.out("File '" + owner.getName() + "' not found in torrent!");
controlFileName = null;
control_dir = null;
} else {
control_dir = owner.getOwner().getControlFileDir();
controlFileName = StringInterner.intern("fmfile" + file_index + ".dat");
}
}
}
use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.
the class EnhancedDownloadManager method setProgressiveMode.
protected boolean setProgressiveMode(boolean active, boolean switching_progressive_downloads) {
TOTorrent torrent = download_manager.getTorrent();
DiskManagerFileInfo primaryFile = download_manager.getDownloadState().getPrimaryFile();
if (torrent == null || primaryFile == null) {
return (false);
}
EnhancedDownloadManagerFile enhanced_file = enhanced_files[primaryFile.getIndex()];
synchronized (this) {
if (progressive_active == active) {
return (true);
}
if (active && !supportsProgressiveMode()) {
Debug.out("Attempt to set progress mode on non-progressible content - " + getName());
return (false);
}
log("Progressive mode changed to " + active);
final GlobalManager gm = download_manager.getGlobalManager();
if (active) {
if (dmListener == null) {
dmListener = new DownloadManagerAdapter() {
@Override
public void downloadComplete(DownloadManager manager) {
enhancer.resume();
}
};
}
download_manager.addListener(dmListener);
// Check existing downloading torrents and turn off any
// existing progressive/downloading
Object[] dms = gm.getDownloadManagers().toArray();
for (int i = 0; i < dms.length; i++) {
DownloadManager dmCheck = (DownloadManager) dms[i];
if (dmCheck.equals(download_manager)) {
continue;
}
if (!dmCheck.isDownloadComplete(false)) {
int state = dmCheck.getState();
if (state == DownloadManager.STATE_DOWNLOADING || state == DownloadManager.STATE_QUEUED) {
enhancer.pause(dmCheck);
}
EnhancedDownloadManager edmCheck = enhancer.getEnhancedDownload(dmCheck);
if (edmCheck != null && edmCheck.getProgressiveMode()) {
edmCheck.setProgressiveMode(false, true);
}
}
}
if (download_manager.isPaused()) {
enhancer.resume(download_manager);
}
// and putting at top
if (download_manager.getState() == DownloadManager.STATE_STOPPED) {
download_manager.setStateWaiting();
}
if (download_manager.getPosition() != 1) {
download_manager.getGlobalManager().moveTo(download_manager, 1);
}
} else {
download_manager.removeListener(dmListener);
if (!switching_progressive_downloads) {
enhancer.resume();
}
}
progressive_active = active;
if (progressive_active) {
enhancer.progressiveActivated();
}
if (current_piece_pickler != null) {
if (progressive_active) {
buffer_provider.activate(current_piece_pickler);
progressive_stats.update(0);
} else {
buffer_provider.deactivate(current_piece_pickler);
progressive_stats = createProgressiveStats(download_manager, enhanced_file);
}
} else {
progressive_stats = createProgressiveStats(download_manager, enhanced_file);
}
if (!switching_progressive_downloads) {
if (active) {
RealTimeInfo.setProgressiveActive(progressive_stats.getStreamBytesPerSecondMax());
} else {
RealTimeInfo.setProgressiveInactive();
}
}
}
return (true);
}
use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.
the class DownloadManagerEnhancer method pause.
// --Commented out by Inspection START (5/22/2017 2:33 PM):
// protected Core
// getCore()
// {
// return( core );
// }
// --Commented out by Inspection STOP (5/22/2017 2:33 PM)
protected void pause(DownloadManager dm) {
TOTorrent torrent = dm.getTorrent();
if (torrent == null) {
return;
}
try {
HashWrapper hw = torrent.getHashWrapper();
synchronized (pause_set) {
if (pause_set.contains(hw)) {
return;
}
pause_set.add(hw);
}
dm.pause();
} catch (Throwable e) {
Debug.out(e);
}
}
use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.
the class MetaSearchManagerImpl method preInitialise.
public static void preInitialise() {
VuzeFileHandler.getSingleton().addProcessor(new VuzeFileProcessor() {
@Override
public void process(VuzeFile[] files, int expected_types) {
for (int i = 0; i < files.length; i++) {
VuzeFile vf = files[i];
VuzeFileComponent[] comps = vf.getComponents();
for (int j = 0; j < comps.length; j++) {
VuzeFileComponent comp = comps[j];
int comp_type = comp.getType();
if (comp_type == VuzeFileComponent.COMP_TYPE_METASEARCH_TEMPLATE) {
try {
Engine e = getSingleton().importEngine(comp.getContent(), (expected_types & VuzeFileComponent.COMP_TYPE_METASEARCH_TEMPLATE) == 0);
comp.setProcessed();
if (e != null) {
comp.setData(Engine.VUZE_FILE_COMPONENT_ENGINE_KEY, e);
}
} catch (Throwable e) {
Debug.printStackTrace(e);
}
} else if (comp_type == VuzeFileComponent.COMP_TYPE_METASEARCH_OPERATION) {
getSingleton().addOperation(comp.getContent());
comp.setProcessed();
}
}
}
}
});
TorrentUtils.addTorrentAttributeListener(new TorrentUtils.torrentAttributeListener() {
@Override
public void attributeSet(TOTorrent torrent, String attribute, Object value) {
if (attribute == TorrentUtils.TORRENT_AZ_PROP_OBTAINED_FROM && !TorrentUtils.isReallyPrivate(torrent)) {
try {
getSingleton().checkPotentialAssociations(torrent.getHash(), (String) value);
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
}
});
}
use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.
the class LWSDiskManager method getFileInfo.
protected DiskManagerFileInfoImpl[] getFileInfo(DMPieceMapperFile[] pm_files, File save_location) {
boolean ok = false;
DiskManagerFileInfoImpl[] local_files = new DiskManagerFileInfoImpl[pm_files.length];
try {
TOTorrent torrent = lws.getTOTorrent(false);
if (torrent.isSimpleTorrent()) {
save_location = save_location.getParentFile();
}
for (int i = 0; i < pm_files.length; i++) {
DMPieceMapperFile pm_info = pm_files[i];
File relative_file = pm_info.getDataFile();
long target_length = pm_info.getLength();
DiskManagerFileInfoImpl file_info = new DiskManagerFileInfoImpl(this, save_location.toString(), relative_file, i, pm_info.getTorrentFile(), DiskManagerFileInfo.ST_LINEAR);
local_files[i] = file_info;
CacheFile cache_file = file_info.getCacheFile();
File data_file = file_info.getFile(true);
if (!cache_file.exists()) {
throw (new Exception("File '" + data_file + "' doesn't exist"));
}
if (cache_file.getLength() != target_length) {
throw (new Exception("File '" + data_file + "' doesn't exist"));
}
pm_info.setFileInfo(file_info);
}
ok = true;
return (local_files);
} catch (Throwable e) {
setFailed("getFiles failed - " + Debug.getNestedExceptionMessage(e));
return (null);
} finally {
if (!ok) {
for (int i = 0; i < local_files.length; i++) {
if (local_files[i] != null) {
local_files[i].close();
}
}
}
}
}
Aggregations