Ejemplo n.º 1
0
 /// <summary>
 /// Creates a StreamProvider for the given <see cref="Torrent"/> so that files
 /// contained within the torrent can be accessed as they are downloading.
 /// </summary>
 /// <param name="engine">The engine used to host the download.</param>
 /// <param name="saveDirectory">The directory where the torrents data will be saved</param>
 /// <param name="torrent">The torrent to download</param>
 public StreamProvider(ClientEngine engine, string saveDirectory, Torrent torrent)
 {
     Engine  = engine;
     Manager = new TorrentManager(torrent, saveDirectory);
     Manager.ChangePicker(Requester = new StreamingPieceRequester());
     Files = Manager.Files;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a StreamProvider for the given <see cref="MagnetLink"/> so that files
        /// contained within the torrent can be accessed as they are downloading.
        /// </summary>
        /// <param name="engine">The engine used to host the download.</param>
        /// <param name="saveDirectory">The directory where the torrents data will be saved</param>
        /// <param name="magnetLink">The MagnetLink to download</param>
        /// <param name="metadataSaveDirectory">The directory where the metadata will be saved. The
        /// filename will be constucted by appending '.torrent' to the value returned by <see cref="InfoHash.ToHex ()"/>
        /// </param>
        public StreamProvider(ClientEngine engine, string saveDirectory, MagnetLink magnetLink, string metadataSaveDirectory)
        {
            Engine = engine;
            var path = Path.Combine(metadataSaveDirectory, $"{magnetLink.InfoHash.ToHex ()}.torrent");

            Manager = new TorrentManager(magnetLink, saveDirectory, new TorrentSettings(), path);
            Manager.ChangePicker(Requester = new StreamingPieceRequester());

            // If the metadata for this MagnetLink has been downloaded/cached already, we will synchronously
            // load it here and will have access to the list of Files. Otherwise we need to wait.
            if (Manager.HasMetadata)
            {
                Files = Manager.Files;
            }
        }
Ejemplo n.º 3
0
 internal StreamProvider(TorrentManager manager, StreamingPieceRequester pieceRequester)
 {
     Cancellation   = new CancellationTokenSource();
     Manager        = manager;
     PieceRequester = pieceRequester;
 }