Search in sources :

Example 21 with DownloadManager

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);
    }
}
Also used : Graphic(com.biglybt.pif.ui.Graphic) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 22 with DownloadManager

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));
}
Also used : DownloadManager(com.biglybt.core.download.DownloadManager)

Example 23 with DownloadManager

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);
    }
}
Also used : DownloadManager(com.biglybt.core.download.DownloadManager)

Example 24 with DownloadManager

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;
                }
            }
        }
    });
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) Set(java.util.Set) HashSet(java.util.HashSet) CRC32(java.util.zip.CRC32) HashMap(java.util.HashMap) DownloadManager(com.biglybt.core.download.DownloadManager) FileInputStream(java.io.FileInputStream) MessageDigest(java.security.MessageDigest) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 25 with DownloadManager

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;
}
Also used : DownloadManager(com.biglybt.core.download.DownloadManager)

Aggregations

DownloadManager (com.biglybt.core.download.DownloadManager)307 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)54 TOTorrent (com.biglybt.core.torrent.TOTorrent)35 GlobalManager (com.biglybt.core.global.GlobalManager)33 PEPeerManager (com.biglybt.core.peer.PEPeerManager)29 File (java.io.File)29 List (java.util.List)21 Core (com.biglybt.core.Core)17 Download (com.biglybt.pif.download.Download)17 Point (org.eclipse.swt.graphics.Point)17 UIFunctions (com.biglybt.ui.UIFunctions)16 Tag (com.biglybt.core.tag.Tag)15 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)14 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)13 ArrayList (java.util.ArrayList)13 DiskManager (com.biglybt.core.disk.DiskManager)12 DownloadManagerStats (com.biglybt.core.download.DownloadManagerStats)12 CoreRunningListener (com.biglybt.core.CoreRunningListener)11 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)11 PEPeer (com.biglybt.core.peer.PEPeer)11