Search in sources :

Example 6 with VuzeFileHandler

use of com.biglybt.core.vuzefile.VuzeFileHandler in project BiglyBT by BiglySoftware.

the class SubscriptionManagerImpl method updateSubscription.

protected void updateSubscription(final SubscriptionImpl subs, final int new_version) {
    log("Subscription " + subs.getString() + " - higher version found: " + new_version);
    if (!subs.canAutoUpgradeCheck()) {
        log("    Checked too recently or not updateable, ignoring");
        return;
    }
    if (subs.getHighestUserPromptedVersion() >= new_version) {
        log("    User has already been prompted for version " + new_version + " so ignoring");
        return;
    }
    byte[] sub_id = subs.getShortID();
    if (!subs.isAnonymous()) {
        try {
            PlatformSubscriptionsMessenger.subscriptionDetails details = PlatformSubscriptionsMessenger.getSubscriptionBySID(sub_id, false);
            if (!askIfCanUpgrade(subs, new_version)) {
                return;
            }
            VuzeFileHandler vfh = VuzeFileHandler.getSingleton();
            VuzeFile vf = vfh.loadVuzeFile(Base64.decode(details.getContent()));
            vfh.handleFiles(new VuzeFile[] { vf }, VuzeFileComponent.COMP_TYPE_SUBSCRIPTION);
            return;
        } catch (Throwable e) {
            log("Failed to read subscription from platform, trying DHT");
        }
    }
    log("Checking subscription '" + subs.getString() + "' upgrade to version " + new_version);
    final String key = "subscription:publish:" + ByteFormatter.encodeString(sub_id) + ":" + new_version;
    DHTPluginInterface dht_plugin = selectDHTPlugin(subs);
    dht_plugin.get(getKeyBytes(key), "Subs update read: " + Base32.encode(sub_id) + ":" + new_version, DHTPlugin.FLAG_SINGLE_VALUE, 12, 60 * 1000 * (subs.isAnonymous() ? 2 : 1), false, false, new DHTPluginOperationListener() {

        private byte[] verified_hash;

        private int verified_size;

        @Override
        public boolean diversified() {
            return (true);
        }

        @Override
        public void starts(byte[] key) {
        }

        @Override
        public void valueRead(DHTPluginContact originator, DHTPluginValue value) {
            byte[] data = value.getValue();
            try {
                Map details = decodeSubscriptionDetails(data);
                if (verified_hash == null && subs.getVerifiedPublicationVersion(details) == new_version) {
                    verified_hash = SubscriptionImpl.getPublicationHash(details);
                    verified_size = SubscriptionImpl.getPublicationSize(details);
                }
            } catch (Throwable e) {
            }
        }

        @Override
        public void valueWritten(DHTPluginContact target, DHTPluginValue value) {
        }

        @Override
        public void complete(byte[] original_key, boolean timeout_occurred) {
            if (verified_hash != null) {
                log("    Subscription '" + subs.getString() + " upgrade verified as authentic");
                updateSubscription(subs, new_version, verified_hash, verified_size);
            } else {
                log("    Subscription '" + subs.getString() + " upgrade not verified");
            }
        }
    });
}
Also used : PlatformSubscriptionsMessenger(com.biglybt.core.messenger.config.PlatformSubscriptionsMessenger) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) VuzeFileHandler(com.biglybt.core.vuzefile.VuzeFileHandler)

Example 7 with VuzeFileHandler

use of com.biglybt.core.vuzefile.VuzeFileHandler in project BiglyBT by BiglySoftware.

the class SubscriptionManagerImpl method updateSubscription.

protected void updateSubscription(SubscriptionImpl subs, File data_location) {
    log("Updating subscription '" + subs.getString() + " using '" + data_location + "'");
    VuzeFileHandler vfh = VuzeFileHandler.getSingleton();
    VuzeFile vf = vfh.loadVuzeFile(data_location.getAbsolutePath());
    vfh.handleFiles(new VuzeFile[] { vf }, VuzeFileComponent.COMP_TYPE_SUBSCRIPTION);
}
Also used : VuzeFile(com.biglybt.core.vuzefile.VuzeFile) VuzeFileHandler(com.biglybt.core.vuzefile.VuzeFileHandler)

Example 8 with VuzeFileHandler

use of com.biglybt.core.vuzefile.VuzeFileHandler in project BiglyBT by BiglySoftware.

the class VuzeListener method handleMessage.

@Override
public void handleMessage(BrowserMessage message) {
    String opid = message.getOperationId();
    if (OP_LOAD_VUZE_FILE.equals(opid)) {
        Map decodedMap = message.getDecodedMap();
        String content = MapUtils.getMapString(decodedMap, "content", null);
        if (content == null) {
            throw new IllegalArgumentException("content missing");
        } else {
            byte[] bytes = Base32.decode(content);
            VuzeFileHandler vfh = VuzeFileHandler.getSingleton();
            VuzeFile vf = vfh.loadVuzeFile(bytes);
            if (vf == null) {
                throw new IllegalArgumentException("content invalid");
            } else {
                vfh.handleFiles(new VuzeFile[] { vf }, 0);
            }
        }
    } else if (OP_RUN_SPEED_TEST.equals(opid)) {
        SpeedTestSelector.runMLABTest(null);
    } else if (OP_GET_MODE.equals(opid)) {
        Map decodedMap = message.getDecodedMap();
        String callback = MapUtils.getMapString(decodedMap, "callback", null);
        if (callback != null) {
            context.executeInBrowser(callback + "('" + "free" + "')");
        } else {
            message.debug("bad or no callback param");
        }
    } else {
        throw new IllegalArgumentException("Unknown operation: " + opid);
    }
}
Also used : VuzeFile(com.biglybt.core.vuzefile.VuzeFile) Map(java.util.Map) VuzeFileHandler(com.biglybt.core.vuzefile.VuzeFileHandler)

Example 9 with VuzeFileHandler

use of com.biglybt.core.vuzefile.VuzeFileHandler in project BiglyBT by BiglySoftware.

the class TorrentOpener method openDroppedTorrents.

public static void openDroppedTorrents(DropTargetEvent event, boolean deprecated_sharing_param) {
    Object data = event.data;
    if (data == null) {
        return;
    }
    if (data instanceof String) {
        if (((String) data).contains("azcdid=" + RandomUtils.INSTANCE_ID)) {
            event.detail = DND.DROP_NONE;
            return;
        }
    } else if (data instanceof FixedURLTransfer.URLType) {
        String link = ((FixedURLTransfer.URLType) data).linkURL;
        if (link != null && link.contains("azcdid=" + RandomUtils.INSTANCE_ID)) {
            event.detail = DND.DROP_NONE;
            return;
        }
    }
    if (event.data instanceof String[] || event.data instanceof String) {
        final String[] sourceNames = (event.data instanceof String[]) ? (String[]) event.data : new String[] { (String) event.data };
        if (event.detail == DND.DROP_NONE)
            return;
        for (int i = 0; (i < sourceNames.length); i++) {
            final File source = new File(sourceNames[i]);
            String sURL = UrlUtils.parseTextForURL(sourceNames[i], true);
            if (sURL != null && !source.exists()) {
                UIFunctionsSWT uif = UIFunctionsManagerSWT.getUIFunctionsSWT();
                if (uif != null) {
                    uif.openTorrentOpenOptions(null, null, new String[] { sURL }, false, false);
                }
            } else if (source.isFile()) {
                // go async as vuze file handling can require UI access which then blocks
                // if this is happening during init
                new AEThread2("asyncOpen", true) {

                    @Override
                    public void run() {
                        String filename = source.getAbsolutePath();
                        VuzeFileHandler vfh = VuzeFileHandler.getSingleton();
                        if (vfh.loadAndHandleVuzeFile(filename, VuzeFileComponent.COMP_TYPE_NONE) != null) {
                            return;
                        }
                        UIFunctionsSWT uif = UIFunctionsManagerSWT.getUIFunctionsSWT();
                        if (uif != null) {
                            uif.openTorrentOpenOptions(null, null, new String[] { filename }, false, false);
                        }
                    }
                }.start();
            } else if (source.isDirectory()) {
                String dir_name = source.getAbsolutePath();
                UIFunctionsSWT uif = UIFunctionsManagerSWT.getUIFunctionsSWT();
                if (uif != null) {
                    uif.openTorrentOpenOptions(null, dir_name, null, false, false);
                }
            }
        }
    } else if (event.data instanceof FixedURLTransfer.URLType) {
        UIFunctionsSWT uif = UIFunctionsManagerSWT.getUIFunctionsSWT();
        if (uif != null) {
            uif.openTorrentOpenOptions(null, null, new String[] { ((FixedURLTransfer.URLType) event.data).linkURL }, false, false);
        }
    }
}
Also used : FixedURLTransfer(com.biglybt.ui.swt.FixedURLTransfer) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File) VuzeFileHandler(com.biglybt.core.vuzefile.VuzeFileHandler)

Example 10 with VuzeFileHandler

use of com.biglybt.core.vuzefile.VuzeFileHandler in project BiglyBT by BiglySoftware.

the class TorrentOpener method openTorrentsFromStrings.

/**
 * Adds torrents that are listed in torrents array.  torrent array can
 * can contain urls or file names.  File names get pathPrefix appended.
 * <P>
 * will open url download dialog, or warning dialogs
 *
 * @since 5.0.0.1
 */
public static void openTorrentsFromStrings(TorrentOpenOptions optionsToClone, Shell parent, String pathPrefix, String[] torrents, String referrer, TorrentDownloaderCallBackInterface listener, boolean forceTorrentOptionsWindow) {
    // if no torrents, but pathPrefix is directory, collect all torrents in it
    if (torrents == null || torrents.length == 0) {
        if (pathPrefix == null) {
            return;
        }
        File path = new File(pathPrefix);
        if (!path.isDirectory()) {
            return;
        }
        List<String> newTorrents = new ArrayList<>();
        File[] listFiles = path.listFiles();
        for (File file : listFiles) {
            try {
                if (file.isFile() && TorrentUtils.isTorrentFile(file.getAbsolutePath())) {
                    newTorrents.add(file.getName());
                }
            } catch (FileNotFoundException e) {
            } catch (IOException e) {
            }
        }
        if (newTorrents.size() == 0) {
            return;
        }
        torrents = newTorrents.toArray(new String[0]);
    }
    // trim out any .vuze files
    final VuzeFileHandler vfh = VuzeFileHandler.getSingleton();
    List<VuzeFile> vuze_files = new ArrayList<>();
    for (String line : torrents) {
        line = line.trim();
        if (line.startsWith("\"") && line.endsWith("\"")) {
            if (line.length() < 3) {
                line = "";
            } else {
                line = line.substring(1, line.length() - 2);
            }
        }
        TorrentOpenOptions torrentOptions = optionsToClone == null ? new TorrentOpenOptions() : new TorrentOpenOptions(optionsToClone);
        File file = pathPrefix == null ? new File(line) : new File(pathPrefix, line);
        if (file.exists()) {
            try {
                VuzeFile vf = vfh.loadVuzeFile(file);
                if (vf != null) {
                    vuze_files.add(vf);
                    continue;
                }
            } catch (Throwable e) {
                Debug.printStackTrace(e);
            }
            try {
                File torrentDir = new File(COConfigurationManager.getDirectoryParameter("General_sDefaultTorrent_Directory"));
                if (COConfigurationManager.getBooleanParameter("Save Torrent Files") && torrentDir.exists() && file.getParentFile().equals(torrentDir)) {
                    torrentOptions.setDeleteFileOnCancel(false);
                }
            } catch (Throwable e) {
            }
            UIFunctions uif = UIFunctionsManager.getUIFunctions();
            if (TorrentOpener.mergeFileIntoTorrentInfo(file.getAbsolutePath(), null, torrentOptions)) {
                uif.addTorrentWithOptions(forceTorrentOptionsWindow, torrentOptions);
            }
            continue;
        }
        final String url = UrlUtils.parseTextForURL(line, true);
        if (url != null) {
            // we used to load any URL, but that results in double loading..
            if (VuzeFileHandler.isAcceptedVuzeFileName(url)) {
                new AEThread2("VuzeLoader") {

                    @Override
                    public void run() {
                        try {
                            // XXX This takes a while..
                            VuzeFile vf = vfh.loadVuzeFile(url);
                            if (vf != null) {
                                vfh.handleFiles(new VuzeFile[] { vf }, VuzeFileComponent.COMP_TYPE_NONE);
                            }
                        } catch (Throwable e) {
                            Debug.printStackTrace(e);
                        }
                    }
                }.start();
                continue;
            }
            new FileDownloadWindow(parent, url, referrer, null, torrentOptions, listener);
        }
    }
    if (vuze_files.size() > 0) {
        VuzeFile[] vfs = new VuzeFile[vuze_files.size()];
        vuze_files.toArray(vfs);
        vfh.handleFiles(vfs, VuzeFileComponent.COMP_TYPE_NONE);
    }
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) TorrentOpenOptions(com.biglybt.core.torrent.impl.TorrentOpenOptions) UIFunctions(com.biglybt.ui.UIFunctions) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File) VuzeFileHandler(com.biglybt.core.vuzefile.VuzeFileHandler)

Aggregations

VuzeFileHandler (com.biglybt.core.vuzefile.VuzeFileHandler)12 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)11 File (java.io.File)4 IOException (java.io.IOException)2 URL (java.net.URL)2 Shell (org.eclipse.swt.widgets.Shell)2 CoreRunningListener (com.biglybt.core.CoreRunningListener)1 ParameterListener (com.biglybt.core.config.ParameterListener)1 PlatformSubscriptionsMessenger (com.biglybt.core.messenger.config.PlatformSubscriptionsMessenger)1 SearchException (com.biglybt.core.metasearch.SearchException)1 SearchLoginException (com.biglybt.core.metasearch.SearchLoginException)1 SearchParameter (com.biglybt.core.metasearch.SearchParameter)1 WebEngine (com.biglybt.core.metasearch.impl.web.WebEngine)1 Subscription (com.biglybt.core.subs.Subscription)1 SubscriptionDownloadListener (com.biglybt.core.subs.SubscriptionDownloadListener)1 SubscriptionException (com.biglybt.core.subs.SubscriptionException)1 SubscriptionHistory (com.biglybt.core.subs.SubscriptionHistory)1 SubscriptionResult (com.biglybt.core.subs.SubscriptionResult)1 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)1