Search in sources :

Example 31 with VuzeFile

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

the class TorrentOpener method mergeFileIntoTorrentInfo.

/**
 * Creates a TorrentInfo from a file.  Prompts user if the file is invalid,
 * torrent already exists
 *
 * @param sFileName
 * @param sOriginatingLocation
 * @return
 * @since 5.0.0.1
 */
// TODO: i18n
public static boolean mergeFileIntoTorrentInfo(String sFileName, final String sOriginatingLocation, TorrentOpenOptions torrentOptions) {
    TOTorrent torrent = null;
    File torrentFile;
    boolean bDeleteFileOnCancel = false;
    // actually made a copy.
    try {
        if (sFileName.startsWith("file://localhost/")) {
            sFileName = UrlUtils.decode(sFileName.substring(16));
        }
        final File fOriginal = new File(sFileName);
        if (!fOriginal.isFile() || !fOriginal.exists()) {
            UIFunctionsManager.getUIFunctions().showErrorMessage("OpenTorrentWindow.mb.openError", fOriginal.toString(), new String[] { UrlUtils.decode(sOriginatingLocation), "Not a File" });
            return false;
        }
        if (fOriginal.length() > TorrentUtils.MAX_TORRENT_FILE_SIZE) {
            UIFunctionsManager.getUIFunctions().showErrorMessage("OpenTorrentWindow.mb.openError", fOriginal.toString(), new String[] { UrlUtils.decode(sOriginatingLocation), "Too large to be a torrent" });
            return false;
        }
        torrentFile = TorrentUtils.copyTorrentFileToSaveDir(fOriginal, true);
        bDeleteFileOnCancel = !fOriginal.equals(torrentFile);
    // TODO if the files are still equal, and it isn't in the save
    // dir, we should copy it to a temp file in case something
    // re-writes it.  No need to copy a torrent coming from the
    // downloader though..
    } catch (IOException e1) {
        // Use torrent in wherever it is and hope for the best
        // XXX Should error instead?
        Debug.out(e1);
        torrentFile = new File(sFileName);
    }
    VuzeFileHandler vfh = VuzeFileHandler.getSingleton();
    VuzeFile vf = vfh.loadVuzeFile(torrentFile);
    if (vf != null) {
        vfh.handleFiles(new VuzeFile[] { vf }, VuzeFileComponent.COMP_TYPE_NONE);
        return false;
    }
    if (RSSUtils.isRSSFeed(torrentFile)) {
        boolean done = false;
        try {
            URL url = new URL(sOriginatingLocation);
            UIManager ui_manager = StaticUtilities.getUIManager(10 * 1000);
            if (ui_manager != null) {
                String details = MessageText.getString("subscription.request.add.message", new String[] { sOriginatingLocation });
                long res = ui_manager.showMessageBox("subscription.request.add.title", "!" + details + "!", UIManagerEvent.MT_YES | UIManagerEvent.MT_NO);
                if (res == UIManagerEvent.MT_YES) {
                    SubscriptionManager sm = PluginInitializer.getDefaultInterface().getUtilities().getSubscriptionManager();
                    sm.requestSubscription(url);
                    done = true;
                }
            }
        } catch (Throwable e) {
            Debug.out(e);
        }
        if (done) {
            if (bDeleteFileOnCancel) {
                torrentFile.delete();
            }
            return false;
        }
    }
    // Do a quick check to see if it's a torrent
    if (!TorrentUtil.isFileTorrent(sOriginatingLocation, torrentFile, torrentFile.getName(), !torrentOptions.getHideErrors())) {
        if (bDeleteFileOnCancel) {
            torrentFile.delete();
        }
        return false;
    }
    // Load up the torrent, see it it's real
    try {
        torrent = TorrentUtils.readFromFile(torrentFile, false);
    } catch (final TOTorrentException e) {
        UIFunctionsManager.getUIFunctions().showErrorMessage("OpenTorrentWindow.mb.openError", Debug.getStackTrace(e), new String[] { sOriginatingLocation, e.getMessage() });
        if (bDeleteFileOnCancel)
            torrentFile.delete();
        return false;
    }
    if (bDeleteFileOnCancel) {
        torrentOptions.setDeleteFileOnCancel(bDeleteFileOnCancel);
    }
    torrentOptions.sFileName = torrentFile.getAbsolutePath();
    torrentOptions.setTorrent(torrent);
    torrentOptions.sOriginatingLocation = sOriginatingLocation;
    return torrentOptions.getTorrent() != null;
}
Also used : UIManager(com.biglybt.pif.ui.UIManager) IOException(java.io.IOException) SubscriptionManager(com.biglybt.pif.utils.subscriptions.SubscriptionManager) URL(java.net.URL) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) TOTorrent(com.biglybt.core.torrent.TOTorrent) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File) VuzeFileHandler(com.biglybt.core.vuzefile.VuzeFileHandler)

Example 32 with VuzeFile

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

the class BiglyBTURLConnection method connect.

@Override
public void connect() throws IOException {
    String str = url.toExternalForm();
    int pos = str.indexOf("body=");
    if (pos >= 0) {
        str = str.substring(pos + 5);
        byte[] bytes = str.getBytes(Constants.BYTE_ENCODING);
        VuzeFile vf = VuzeFileHandler.getSingleton().loadVuzeFile(bytes);
        if (vf == null) {
            throw (new IOException("Invalid biglybt url"));
        }
        input_stream = new ByteArrayInputStream(bytes);
    } else {
        String host = url.getHost();
        String httpsURL;
        if (host.equalsIgnoreCase("install-plugin") && url.getPath().length() > 1) {
            String plugin_id = url.getPath().substring(1);
            httpsURL = Constants.PLUGINS_WEB_SITE + "getplugin.php?plugin=" + plugin_id + "&" + SFPluginDetailsLoaderImpl.getBaseUrlParams();
        } else if (host.contains(".")) {
            httpsURL = "https" + str.substring("biglybt".length());
        } else {
            throw (new IOException("Invalid biglybt url"));
        }
        ResourceDownloader rd = StaticUtilities.getResourceDownloaderFactory().create(new URL(httpsURL));
        try {
            if (ONLY_VUZE_FILE) {
                VuzeFile vf = VuzeFileHandler.getSingleton().loadVuzeFile(rd.download());
                if (vf == null) {
                    throw (new IOException("Invalid biglybt url"));
                }
                boolean hasPlugin = false;
                VuzeFileComponent[] components = vf.getComponents();
                for (VuzeFileComponent component : components) {
                    if (component.getType() == VuzeFileComponent.COMP_TYPE_PLUGIN) {
                        hasPlugin = true;
                        break;
                    }
                }
                if (!hasPlugin) {
                    throw (new IOException("Biglybt url does not contain plugin"));
                }
                input_stream = new ByteArrayInputStream(vf.exportToBytes());
            } else {
                input_stream = rd.download();
            }
        } catch (ResourceDownloaderException e) {
            throw new IOException(e);
        }
    }
}
Also used : VuzeFileComponent(com.biglybt.core.vuzefile.VuzeFileComponent) ByteArrayInputStream(java.io.ByteArrayInputStream) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) IOException(java.io.IOException) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) URL(java.net.URL)

Example 33 with VuzeFile

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

the class SearchUtils method importFromClipboard.

private static void importFromClipboard() {
    final Shell shell = Utils.findAnyShell();
    shell.getDisplay().asyncExec(new AERunnable() {

        @Override
        public void runSupport() {
            try {
                Clipboard clipboard = new Clipboard(Display.getDefault());
                String text = (String) clipboard.getContents(TextTransfer.getInstance());
                clipboard.dispose();
                if (text != null) {
                    InputStream is = new ByteArrayInputStream(text.getBytes("UTF-8"));
                    try {
                        VuzeFileHandler vfh = VuzeFileHandler.getSingleton();
                        VuzeFile vf = vfh.loadVuzeFile(is);
                        if (vf != null) {
                            vfh.handleFiles(new VuzeFile[] { vf }, VuzeFileComponent.COMP_TYPE_NONE);
                        }
                    } finally {
                        is.close();
                    }
                }
            } catch (Throwable e) {
                Debug.out(e);
            }
        }
    });
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) Shell(org.eclipse.swt.widgets.Shell) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) Clipboard(org.eclipse.swt.dnd.Clipboard) VuzeFileHandler(com.biglybt.core.vuzefile.VuzeFileHandler)

Example 34 with VuzeFile

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

the class PluginInstallerImpl method extractFromVuzeFile.

private File extractFromVuzeFile(File file) throws PluginException {
    VuzeFile vf = VuzeFileHandler.getSingleton().loadVuzeFile(file);
    VuzeFileComponent[] comps = vf.getComponents();
    for (int j = 0; j < comps.length; j++) {
        VuzeFileComponent comp = comps[j];
        if (comp.getType() == VuzeFileComponent.COMP_TYPE_PLUGIN) {
            try {
                Map content = comp.getContent();
                String id = new String((byte[]) content.get("id"), "UTF-8");
                String version = new String((byte[]) content.get("version"), "UTF-8");
                String suffix = ((Long) content.get("is_jar")).longValue() == 1 ? "jar" : "zip";
                byte[] plugin_file = (byte[]) content.get("file");
                File temp_dir = AETemporaryFileHandler.createTempDir();
                File temp_file = new File(temp_dir, id + "_" + version + "." + suffix);
                FileUtil.copyFile(new ByteArrayInputStream(plugin_file), temp_file);
                return (temp_file);
            } catch (Throwable e) {
                throw (new PluginException("Not a valid Vuze file", e));
            }
        }
    }
    return (file);
}
Also used : VuzeFileComponent(com.biglybt.core.vuzefile.VuzeFileComponent) ByteArrayInputStream(java.io.ByteArrayInputStream) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File)

Example 35 with VuzeFile

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

the class SubscriptionSelectedContent method getTorrent.

@Override
public TOTorrent getTorrent() {
    synchronized (this) {
        if (torrent == null) {
            try {
                VuzeFile vf = subs.getVuzeFile();
                if (vf != null) {
                    File f1 = AETemporaryFileHandler.createTempFile();
                    File f = new File(f1.getParent(), "Update Vuze to access this share_" + f1.getName());
                    f1.delete();
                    try {
                        vf.write(f);
                        TOTorrentCreator cr = TOTorrentFactory.createFromFileOrDirWithComputedPieceLength(f, new URL("dht://"));
                        TOTorrent temp = cr.create();
                        Map vuze_map = vf.exportToMap();
                        Map torrent_map = temp.serialiseToMap();
                        torrent_map.putAll(vuze_map);
                        torrent = TOTorrentFactory.deserialiseFromMap(torrent_map);
                    } finally {
                        f.delete();
                    }
                }
            } catch (Throwable e) {
                Debug.out(e);
            }
        }
    }
    return (torrent);
}
Also used : TOTorrent(com.biglybt.core.torrent.TOTorrent) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) TOTorrentCreator(com.biglybt.core.torrent.TOTorrentCreator) File(java.io.File) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) Map(java.util.Map) URL(java.net.URL)

Aggregations

VuzeFile (com.biglybt.core.vuzefile.VuzeFile)36 File (java.io.File)12 VuzeFileHandler (com.biglybt.core.vuzefile.VuzeFileHandler)10 VuzeFileComponent (com.biglybt.core.vuzefile.VuzeFileComponent)9 URL (java.net.URL)9 RSSEngine (com.biglybt.core.metasearch.impl.web.rss.RSSEngine)5 TOTorrent (com.biglybt.core.torrent.TOTorrent)5 IOException (java.io.IOException)5 PluginEngine (com.biglybt.core.metasearch.impl.plugin.PluginEngine)4 WebEngine (com.biglybt.core.metasearch.impl.web.WebEngine)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Map (java.util.Map)4 Subscription (com.biglybt.core.subs.Subscription)3 VuzeFileProcessor (com.biglybt.core.vuzefile.VuzeFileProcessor)3 UIManager (com.biglybt.pif.ui.UIManager)3 Engine (com.biglybt.core.metasearch.Engine)2 SubscriptionException (com.biglybt.core.subs.SubscriptionException)2 ResourceDownloader (com.biglybt.pif.utils.resourcedownloader.ResourceDownloader)2 ResourceDownloaderFactory (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderFactory)2 InputStream (java.io.InputStream)2