use of com.biglybt.core.vuzefile.VuzeFileHandler 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;
}
use of com.biglybt.core.vuzefile.VuzeFileHandler 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);
}
}
});
}
Aggregations