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); }
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); }
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(); } }