Example #1
0
        public List <Models.FileEntry> getTorrentFiles(string hash)
        {
            List <Models.FileEntry> feList = new List <Models.FileEntry>();

            Models.FileEntry   fe;
            Core.TorrentHandle th = getTorrentHandle(hash);
            using (Core.TorrentInfo ti = th.torrent_file())
            {
                if (ti == null)
                {
                    // non ci sono file nel torrent
                    fe          = new Models.FileEntry();
                    fe.FileName = th.ToString();
                    feList.Add(fe);
                }
                else
                {
                    for (int i = 0; i <= ti.num_files() - 1; i++)
                    {
                        fe           = new Models.FileEntry(ti.files().at(i));
                        fe.FileName  = ti.files().file_name(i);
                        fe.IsValid   = ti.files().is_valid();
                        fe.PieceSize = ti.piece_size(i);
                        //ti.files().name(); ???
                        //ti.trackers();
                        feList.Add(fe);
                    }
                }
            }
            //Core.TorrentHandle th = getTorrentHandle(hash);
            //Core.TorrentInfo ti = th.torrent_file();
            return(feList);
        }
Example #2
0
        public string GetFilePathFromHash(string hash, int fileIndex)
        {
            Core.TorrentHandle th = getTorrentHandle(hash);
            var    ti             = th.torrent_file();
            var    files          = ti.files();
            var    fileEntry      = files.at(fileIndex);
            string path           = Settings.User.PathDownload + "\\" + fileEntry.path;

            return(path);
        }
Example #3
0
        public static List <Models.FileEntry> getTorrentFiles(string hash)
        {
            List <Models.FileEntry> feList = new List <Models.FileEntry>();

            Models.FileEntry fe;

            Core.TorrentHandle th = getTorrentHandle(hash);
            Core.TorrentInfo   ti = th.torrent_file();
            for (int i = 0; i <= ti.num_files() - 1; i++)
            {
                fe           = new Models.FileEntry(ti.files().at(i));
                fe.FileName  = ti.files().file_name(i);
                fe.IsValid   = ti.files().is_valid();
                fe.PieceSize = ti.piece_size(i);
                //ti.files().name(); ???
                //ti.trackers();
                feList.Add(fe);
            }
            return(feList);
        }
Example #4
0
        public static void StreamTorrent(Core.TorrentHandle handle, int fileIndex)
        {
            var ti    = handle.torrent_file();
            var files = ti.files();

            if (fileIndex < 0 || fileIndex > files.num_files())
            {
                throw new ArgumentOutOfRangeException();
            }
            var fileEntry    = files.at(fileIndex);
            var peer_req     = ti.map_file(fileIndex, 0, 1048576);
            var startPiece   = peer_req.piece;
            var piece_length = ti.piece_length();
            var num_pieces   = (int)Math.Ceiling((double)(fileEntry.size / piece_length));
            var end_piece    = Math.Min(startPiece + num_pieces, ti.num_pieces() - 1);

            for (int i = startPiece; i < end_piece; i++)
            {
                handle.piece_priority(i, 0);
            }

            //set first piece with higher priority
            handle.piece_priority(startPiece, 7);
            var lastPiece = startPiece;

            start_window = startPiece;
            end_window   = Math.Min(end_window, lastPiece);
            for (int i = start_window; i <= end_window; i++)
            {
                handle.piece_priority(i, 1);
            }
            while (start_window <= end_window)
            {
                if (handle.have_piece(start_window))
                {
                    handle.piece_priority(++start_window, 7);
                    continue;
                }
                Thread.Sleep(200);
            }
        }
Example #5
0
        public StreamTorrent(string hash, int fileIndex, EventHandler <string> _callback)
        {
            if (_callback != null)
            {
                BufferReady += _callback;
            }
            _hash          = hash;
            _torrentHandle = SessionManager.Instance.getTorrentHandle(hash);
            if (!_torrentHandle.has_metadata())
            {
                return;
            }
            Core.TorrentInfo ti = _torrentHandle.torrent_file();
            var files           = ti.files();

            if (fileIndex < 0 || fileIndex > files.num_files())
            {
                throw new ArgumentOutOfRangeException();
            }
            var fileEntry = files.at(fileIndex);

            file_path = Settings.User.PathDownload + "\\" + fileEntry.path;
            var peer_req = ti.map_file(fileIndex, 0, 1048576);

            starting_point = last_have_piece = peer_req.piece;
            piece_length   = ti.piece_length();
            num_pieces     = (int)Math.Ceiling((double)(fileEntry.size / piece_length));
            end_piece      = Math.Min(last_have_piece + num_pieces, ti.num_pieces() - 1);

            //set first piece with higher priority
            _torrentHandle.piece_priority(last_have_piece, 7);
            _onStreaming = true;
            if (_torrentHandle.have_piece(last_have_piece))
            {
                CountHavePieces();
                InvokeStreaming();
            }
        }