Search in sources :

Example 6 with TOTorrentException

use of com.biglybt.core.torrent.TOTorrentException in project BiglyBT by BiglySoftware.

the class ResourceDownloaderTorrentImpl method getSizeSupport.

protected long getSizeSupport() throws ResourceDownloaderException {
    try {
        if (torrent_holder[0] == null) {
            ResourceDownloader x = delegate.getClone(this);
            addReportListener(x);
            InputStream is = x.download();
            try {
                torrent_holder[0] = TOTorrentFactory.deserialiseFromBEncodedInputStream(is);
            } finally {
                try {
                    is.close();
                } catch (IOException e) {
                }
            }
            if (!torrent_holder[0].isSimpleTorrent()) {
                throw (new ResourceDownloaderException(this, "Only simple torrents supported"));
            }
        }
        try {
            String file_str = new String(torrent_holder[0].getName());
            int pos = file_str.lastIndexOf(".");
            String file_type;
            if (pos != -1) {
                file_type = file_str.substring(pos + 1);
            } else {
                file_type = null;
            }
            setProperty(ResourceDownloader.PR_STRING_CONTENT_TYPE, HTTPUtils.guessContentTypeFromFileType(file_type));
        } catch (Throwable e) {
            Debug.printStackTrace(e);
        }
        return (torrent_holder[0].getSize());
    } catch (TOTorrentException e) {
        throw (new ResourceDownloaderException(this, "Torrent deserialisation failed", e));
    }
}
Also used : TOTorrentException(com.biglybt.core.torrent.TOTorrentException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) IOException(java.io.IOException)

Example 7 with TOTorrentException

use of com.biglybt.core.torrent.TOTorrentException in project BiglyBT by BiglySoftware.

the class ImportTorrentWizard method performImport.

protected boolean performImport() {
    File input_file;
    try {
        input_file = new File(getImportFile()).getCanonicalFile();
    } catch (IOException e) {
        MessageBox mb = new MessageBox(getWizardWindow(), SWT.ICON_ERROR | SWT.OK);
        mb.setText(MessageText.getString("importTorrentWizard.process.inputfilebad.title"));
        mb.setMessage(MessageText.getString("importTorrentWizard.process.inputfilebad.message") + "\n" + e.toString());
        mb.open();
        return (false);
    }
    File output_file = new File(getTorrentFile());
    if (output_file.exists()) {
        MessageBox mb = new MessageBox(this.getWizardWindow(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
        mb.setText(MessageText.getString("importTorrentWizard.process.outputfileexists.title"));
        mb.setMessage(MessageText.getString("importTorrentWizard.process.outputfileexists.message"));
        int result = mb.open();
        if (result == SWT.NO) {
            return (false);
        }
    }
    String error_title;
    String error_detail;
    try {
        TOTorrent torrent;
        try {
            torrent = TOTorrentFactory.deserialiseFromXMLFile(input_file);
            try {
                torrent.serialiseToBEncodedFile(output_file);
                return (true);
            } catch (TOTorrentException e) {
                // e.printStackTrace();
                error_title = MessageText.getString("importTorrentWizard.process.torrentfail.title");
                error_detail = TorrentUtils.exceptionToText(e);
            }
        } catch (TOTorrentException e) {
            // e.printStackTrace();
            error_title = MessageText.getString("importTorrentWizard.process.importfail.title");
            error_detail = TorrentUtils.exceptionToText(e);
        }
    } catch (Throwable e) {
        error_title = MessageText.getString("importTorrentWizard.process.unknownfail.title");
        Debug.printStackTrace(e);
        error_detail = e.toString();
    }
    MessageBox mb = new MessageBox(this.getWizardWindow(), SWT.ICON_ERROR | SWT.OK);
    mb.setText(error_title);
    mb.setMessage(error_detail);
    mb.open();
    return (false);
}
Also used : TOTorrentException(com.biglybt.core.torrent.TOTorrentException) TOTorrent(com.biglybt.core.torrent.TOTorrent) IOException(java.io.IOException) File(java.io.File) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 8 with TOTorrentException

use of com.biglybt.core.torrent.TOTorrentException in project BiglyBT by BiglySoftware.

the class DiskManagerImpl method deleteDataFileContents.

private static void deleteDataFileContents(TOTorrent torrent, String torrent_save_dir, String torrent_save_file, boolean force_no_recycle) throws TOTorrentException, UnsupportedEncodingException, LocaleUtilEncodingException {
    LocaleUtilDecoder locale_decoder = LocaleTorrentUtil.getTorrentEncoding(torrent);
    TOTorrentFile[] files = torrent.getFiles();
    String root_path = torrent_save_dir + File.separator + torrent_save_file + File.separator;
    boolean delete_if_not_in_dir = COConfigurationManager.getBooleanParameter("File.delete.include_files_outside_save_dir");
    for (int i = 0; i < files.length; i++) {
        byte[][] path_comps = files[i].getPathComponents();
        String path_str = root_path;
        for (int j = 0; j < path_comps.length; j++) {
            try {
                String comp = locale_decoder.decodeString(path_comps[j]);
                comp = FileUtil.convertOSSpecificChars(comp, j != path_comps.length - 1);
                path_str += (j == 0 ? "" : File.separator) + comp;
            } catch (UnsupportedEncodingException e) {
                Debug.out("file - unsupported encoding!!!!");
            }
        }
        File file = new File(path_str);
        File linked_file = FMFileManagerFactory.getSingleton().getFileLink(torrent, i, file);
        boolean delete;
        if (linked_file == file) {
            delete = true;
        } else {
            try {
                if (delete_if_not_in_dir || linked_file.getCanonicalPath().startsWith(new File(root_path).getCanonicalPath())) {
                    file = linked_file;
                    delete = true;
                } else {
                    delete = false;
                }
            } catch (Throwable e) {
                Debug.printStackTrace(e);
                delete = false;
            }
        }
        if (delete && file.exists() && !file.isDirectory()) {
            try {
                FileUtil.deleteWithRecycle(file, force_no_recycle);
            } catch (Exception e) {
                Debug.out(e.toString());
            }
        }
    }
    TorrentUtils.recursiveEmptyDirDelete(new File(torrent_save_dir, torrent_save_file));
}
Also used : TOTorrentFile(com.biglybt.core.torrent.TOTorrentFile) LocaleUtilDecoder(com.biglybt.core.internat.LocaleUtilDecoder) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TOTorrentFile(com.biglybt.core.torrent.TOTorrentFile) CacheFile(com.biglybt.core.diskmanager.cache.CacheFile) File(java.io.File) LocaleUtilEncodingException(com.biglybt.core.internat.LocaleUtilEncodingException) CacheFileManagerException(com.biglybt.core.diskmanager.cache.CacheFileManagerException) PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) DownloadManagerException(com.biglybt.core.download.DownloadManagerException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 9 with TOTorrentException

use of com.biglybt.core.torrent.TOTorrentException in project BiglyBT by BiglySoftware.

the class PEPeerControlImpl method start.

@Override
public void start() {
    // This torrent Hash
    try {
        _hash = PeerIdentityManager.createDataID(disk_mgr.getTorrent().getHash());
    } catch (TOTorrentException e) {
        // this should never happen
        Debug.printStackTrace(e);
        _hash = PeerIdentityManager.createDataID(new byte[20]);
    }
    // the recovered active pieces
    for (int i = 0; i < _nbPieces; i++) {
        final DiskManagerPiece dmPiece = dm_pieces[i];
        if (!dmPiece.isDone() && dmPiece.getNbWritten() > 0) {
            addPiece(new PEPieceImpl(piecePicker, dmPiece, 0), i, true, null);
        }
    }
    // The peer connections
    peer_transports_cow = new ArrayList();
    // BtManager is threaded, this variable represents the
    // current loop iteration. It's used by some components only called
    // at some specific times.
    mainloop_loop_count = 0;
    // The current tracker state
    // this could be start or update
    _averageReceptionSpeed = Average.getInstance(1000, 30);
    // the stats
    _stats = new PEPeerManagerStatsImpl(this);
    superSeedMode = (COConfigurationManager.getBooleanParameter("Use Super Seeding") && this.getRemaining() == 0);
    superSeedModeCurrentPiece = 0;
    if (superSeedMode) {
        initialiseSuperSeedMode();
    }
    // initial check on finished state - future checks are driven by piece check results
    // Moved out of mainLoop() so that it runs immediately, possibly changing
    // the state to seeding.
    checkFinished(true);
    UploadSlotManager.getSingleton().registerHelper(upload_helper);
    lastNeededUndonePieceChange = Long.MIN_VALUE;
    _timeStarted = SystemTime.getCurrentTime();
    _timeStarted_mono = SystemTime.getMonotonousTime();
    is_running = true;
    // activate after marked as running as we may synchronously add connections here due to pending activations
    PeerManagerRegistration reg = adapter.getPeerManagerRegistration();
    if (reg != null) {
        reg.activate(this);
    }
    PeerNATTraverser.getSingleton().register(this);
    PeerControlSchedulerFactory.getSingleton(partition_id).register(this);
}
Also used : TOTorrentException(com.biglybt.core.torrent.TOTorrentException) PeerManagerRegistration(com.biglybt.core.peermanager.PeerManagerRegistration)

Example 10 with TOTorrentException

use of com.biglybt.core.torrent.TOTorrentException in project BiglyBT by BiglySoftware.

the class TRTrackerDHTScraperImpl method scrape.

public TRTrackerScraperResponse scrape(TOTorrent torrent, URL unused_target_url, boolean unused_force) {
    if (torrent != null) {
        try {
            HashWrapper hw = torrent.getHashWrapper();
            TRTrackerDHTScraperResponseImpl response;
            synchronized (responses) {
                response = responses.get(hw);
            }
            if (response == null) {
                TRTrackerScraperClientResolver resolver = scraper.getClientResolver();
                if (resolver != null) {
                    int[] cache = resolver.getCachedScrape(hw);
                    if (cache != null) {
                        response = new TRTrackerDHTScraperResponseImpl(hw, torrent.getAnnounceURL());
                        response.setSeedsPeers(cache[0], cache[1]);
                        long now = SystemTime.getCurrentTime();
                        response.setScrapeStartTime(now);
                        response.setNextScrapeStartTime(now + 5 * 60 * 1000);
                        response.setStatus(TRTrackerScraperResponse.ST_ONLINE, MessageText.getString("Scrape.status.cached"));
                        synchronized (responses) {
                            responses.put(torrent.getHashWrapper(), response);
                        }
                        scraper.scrapeReceived(response);
                    }
                }
            }
            return (response);
        } catch (TOTorrentException e) {
            Debug.printStackTrace(e);
        }
    }
    return (null);
}
Also used : TOTorrentException(com.biglybt.core.torrent.TOTorrentException) HashWrapper(com.biglybt.core.util.HashWrapper) TRTrackerScraperClientResolver(com.biglybt.core.tracker.client.TRTrackerScraperClientResolver)

Aggregations

TOTorrentException (com.biglybt.core.torrent.TOTorrentException)45 TOTorrent (com.biglybt.core.torrent.TOTorrent)23 File (java.io.File)15 IOException (java.io.IOException)9 URL (java.net.URL)8 DownloadManager (com.biglybt.core.download.DownloadManager)7 Core (com.biglybt.core.Core)3 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)3 GlobalManager (com.biglybt.core.global.GlobalManager)3 TOTorrentFile (com.biglybt.core.torrent.TOTorrentFile)3 SimpleXMLParserDocumentNode (com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode)3 List (java.util.List)3 Map (java.util.Map)3 CoreRunningListener (com.biglybt.core.CoreRunningListener)2 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)2 LogEvent (com.biglybt.core.logging.LogEvent)2 TOTorrentProgressListener (com.biglybt.core.torrent.TOTorrentProgressListener)2 TRHostTorrent (com.biglybt.core.tracker.host.TRHostTorrent)2 TorrentImpl (com.biglybt.pifimpl.local.torrent.TorrentImpl)2 TrackerEditorListener (com.biglybt.ui.swt.maketorrent.TrackerEditorListener)2