use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.
the class CommentIconItem method refresh.
@Override
public void refresh(TableCell cell) {
if (cell.isDisposed()) {
return;
}
DownloadManager dm = (DownloadManager) cell.getDataSource();
String comment = null;
if (dm != null) {
comment = dm.getDownloadState().getUserComment();
if (comment != null && comment.length() == 0) {
comment = null;
}
}
Graphic oldGraphic = cell.getGraphic();
if (comment == null && oldGraphic != noGraphicComment) {
cell.setGraphic(noGraphicComment);
cell.setSortValue(null);
} else if (comment != null && oldGraphic != graphicComment) {
cell.setGraphic(graphicComment);
cell.setSortValue(comment);
}
}
use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.
the class DateAddedItem method refresh.
@Override
public void refresh(TableCell cell, long timestamp) {
DownloadManager dm = (DownloadManager) cell.getDataSource();
timestamp = (dm == null) ? 0 : dm.getDownloadState().getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_ADDED_TIME);
super.refresh(cell, timestamp);
// cell.setText(DisplayFormatters.formatDate(timestamp));
}
use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.
the class DateCompletedItem method cellHover.
/* (non-Javadoc)
* @see com.biglybt.ui.swt.views.tableitems.ColumnDateSizer#cellHover(com.biglybt.pif.ui.tables.TableCell)
*/
@Override
public void cellHover(TableCell cell) {
super.cellHover(cell);
Object oTooltip = cell.getToolTip();
String s = (oTooltip instanceof String) ? (String) oTooltip + "\n" : "";
DownloadManager dm = (DownloadManager) cell.getDataSource();
long dateAdded = (dm == null) ? 0 : dm.getDownloadState().getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_ADDED_TIME);
if (dateAdded != 0) {
s += MessageText.getString("TableColumn.header.date_added") + ": " + DisplayFormatters.formatDate(dateAdded) + " (" + DisplayFormatters.formatETA((SystemTime.getCurrentTime() - dateAdded) / 1000, false) + ")";
cell.setToolTip(s);
}
}
use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.
the class FileHashItemBase method updateHash.
private static void updateHash(final String hash_type, final DiskManagerFileInfo file) {
if (!isFileReady(file)) {
return;
}
synchronized (pending) {
Set<String> hashes = pending.get(file);
if (hashes != null && hashes.contains(hash_type)) {
return;
}
if (hashes == null) {
hashes = new HashSet<>();
pending.put(file, hashes);
}
hashes.add(hash_type);
}
dispatcher.dispatch(new AERunnable() {
@Override
public void runSupport() {
try {
DownloadManager dm = file.getDownloadManager();
if (dm == null) {
return;
}
if (!isFileReady(file)) {
return;
}
active_percent = 0;
active_hash = hash_type;
active = file;
File f = file.getFile(true);
CRC32 crc32 = null;
MessageDigest md = null;
if (hash_type == HT_CRC32) {
crc32 = new CRC32();
} else if (hash_type == HT_MD5) {
md = MessageDigest.getInstance("md5");
} else {
md = MessageDigest.getInstance("SHA1");
}
FileInputStream fis = new FileInputStream(f);
long size = f.length();
long done = 0;
if (size == 0) {
size = 1;
}
try {
byte[] buffer = new byte[512 * 1024];
while (true) {
int len = fis.read(buffer);
if (len <= 0) {
break;
}
if (crc32 != null) {
crc32.update(buffer, 0, len);
}
if (md != null) {
md.update(buffer, 0, len);
}
done += len;
active_percent = (int) ((1000 * done) / size);
}
byte[] hash;
if (crc32 != null) {
long val = crc32.getValue();
hash = ByteFormatter.intToByteArray(val);
} else {
hash = md.digest();
}
Map other_hashes = dm.getDownloadState().getMapAttribute(DownloadManagerState.AT_FILE_OTHER_HASHES);
if (other_hashes == null) {
other_hashes = new HashMap();
} else {
other_hashes = BEncoder.cloneMap(other_hashes);
}
Map file_hashes = (Map) other_hashes.get(String.valueOf(file.getIndex()));
if (file_hashes == null) {
file_hashes = new HashMap();
other_hashes.put(String.valueOf(file.getIndex()), file_hashes);
}
file_hashes.put(hash_type, hash);
dm.getDownloadState().setMapAttribute(DownloadManagerState.AT_FILE_OTHER_HASHES, other_hashes);
} finally {
fis.close();
}
} catch (Throwable e) {
Debug.out(e);
} finally {
synchronized (pending) {
Set<String> hashes = pending.get(file);
hashes.remove(hash_type);
if (hashes.size() == 0) {
pending.remove(file);
}
active = null;
}
}
}
});
}
use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.
the class AbstractTrackerCell method dispose.
@Override
public void dispose(TableCell cell) {
if (dm != null)
dm.removeTrackerListener(this);
DownloadManager dm = (DownloadManager) cell.getDataSource();
if (dm != null && dm != this.dm)
dm.removeTrackerListener(this);
dm = null;
cell = null;
}
Aggregations