Search in sources :

Example 1 with BTInfoAdditionalMetadataHolder

use of com.frostwire.bittorrent.BTInfoAdditionalMetadataHolder in project frostwire by frostwire.

the class LibraryFilesTableDataLine method initialize.

/**
 * Initialize the object.
 * It will fail if not given a FileDesc or a File
 * (File is retained for compatibility with the Incomplete folder)
 */
public void initialize(File file) {
    super.initialize(file);
    String fullPath = file.getPath();
    try {
        fullPath = file.getCanonicalPath();
    } catch (IOException ignored) {
    }
    String _name = initializer.getName();
    _type = "";
    if (!file.isDirectory()) {
        // _isDirectory = false;
        int index = _name.lastIndexOf(".");
        int index2 = fullPath.lastIndexOf(File.separator);
        _path = fullPath.substring(0, index2);
        if (index != -1 && index != 0) {
            _type = _name.substring(index + 1);
            _name = _name.substring(0, index);
        }
    } else {
        _path = fullPath;
    // _isDirectory = true;
    }
    // directories implicitly set SizeHolder to null and display nothing
    if (initializer.isFile()) {
        long _size = initializer.length();
        _sizeHolder = new SizeHolder(_size);
    } else {
        _sizeHolder = ZERO_SIZED_HOLDER;
    }
    this.lastModified = new Date(initializer.lastModified());
    this.actionsHolder = new LibraryActionsHolder(this, false);
    this.nameCell = new NameHolder(_name);
    if (initializer != null && initializer.isFile() && FilenameUtils.getExtension(initializer.getName()) != null && FilenameUtils.getExtension(initializer.getName()).toLowerCase().endsWith("torrent")) {
        BTInfoAdditionalMetadataHolder additionalMetadataHolder = null;
        try {
            additionalMetadataHolder = new BTInfoAdditionalMetadataHolder(initializer, initializer.getName());
        } catch (Throwable t) {
            System.err.println("[InvalidTorrent] Can't create BTInfoAdditionalMetadataholder out of " + initializer.getAbsolutePath());
            t.printStackTrace();
        }
        boolean hasLicense = additionalMetadataHolder != null && additionalMetadataHolder.getLicenseBroker() != null;
        boolean hasPaymentOptions = additionalMetadataHolder != null && additionalMetadataHolder.getPaymentOptions() != null;
        if (hasLicense) {
            license = additionalMetadataHolder.getLicenseBroker().getLicenseName();
        }
        if (license == null) {
            license = "";
        }
        if (hasPaymentOptions) {
            paymentOptions = additionalMetadataHolder.getPaymentOptions();
        } else {
            paymentOptions = new PaymentOptions(null, null);
        }
        paymentOptions.setItemName(_name);
    }
}
Also used : NameHolder(com.limegroup.gnutella.gui.tables.NameHolder) BTInfoAdditionalMetadataHolder(com.frostwire.bittorrent.BTInfoAdditionalMetadataHolder) IOException(java.io.IOException) SizeHolder(com.limegroup.gnutella.gui.tables.SizeHolder) PaymentOptions(com.frostwire.bittorrent.PaymentOptions) Date(java.util.Date)

Aggregations

BTInfoAdditionalMetadataHolder (com.frostwire.bittorrent.BTInfoAdditionalMetadataHolder)1 PaymentOptions (com.frostwire.bittorrent.PaymentOptions)1 NameHolder (com.limegroup.gnutella.gui.tables.NameHolder)1 SizeHolder (com.limegroup.gnutella.gui.tables.SizeHolder)1 IOException (java.io.IOException)1 Date (java.util.Date)1