public void Dispose()
 {
     if (TM != null && CE != null)
     {
         CE.Unregister(TM);
         Stop();
         TM.Dispose();
         TM = null;
     }
 }
Beispiel #2
0
        /// <summary>
        /// Removes torrent manager from the engine if no one file is downloading
        /// </summary>
        /// <param name="manager"></param>
        public void CancelTorrent(TorrentManager manager)
        {
            if (manager.Torrent == null || manager.Torrent.Files.All(f => f.Priority == Priority.DoNotDownload))
            {
                manager.Stop();
                _engine.Unregister(manager);
                _torrents.Remove(manager);
                manager.Dispose();

                if (manager.Torrent != null && manager.Torrent.TorrentPath.StartsWith(TorrentsFolder))
                {
                    File.Delete(manager.Torrent.TorrentPath);
                }
            }
        }
Beispiel #3
0
 public void RecreateManager()
 {
     if (_manager != null)
     {
         _manager.Dispose();
         if (_engine.Contains(_manager))
         {
             _engine.Unregister(_manager);
         }
     }
     _torrentDict = CreateTorrent(_piecelength, _files, _tier);
     _torrent     = Torrent.Load(_torrentDict);
     _manager     = MetadataMode
                    ? new TorrentManager(_torrent.infoHash, _savePath, new TorrentSettings(), MetadataPath, new RawTrackerTiers())
                    : new TorrentManager(_torrent, _savePath, new TorrentSettings());
     _engine.Register(_manager);
 }
Beispiel #4
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            Torrent torrent = Torrent.Load(entry.FilePath + ".torrent");

            // Create the manager which will download the torrent to savePath
            // using the default settings.
            TorrentManager manager = new TorrentManager(torrent, entry.downloadsPath, new TorrentSettings());

            engine = new ClientEngine();

            // Register the manager with the engine
            this.engine.Register(manager);

            // Begin the download. It is not necessary to call HashCheck on the manager
            // before starting the download. If a hash check has not been performed, the
            // manager will enter the Hashing state and perform a hash check before it
            // begins downloading.

            // If the torrent is fully downloaded already, calling 'Start' will place
            // the manager in the Seeding state.
            manager.StartAsync();

            while (progressBar1.Value < 100)
            {
                BeginInvoke(new MethodInvoker(delegate
                {
                    progressBar1.Value = (int)manager.Bitfield.PercentComplete;
                    label2.Text        = manager.Bitfield.PercentComplete.ToString() + "%";
                }));

                System.Threading.Thread.Sleep(200);
            }

            BeginInvoke(new MethodInvoker(delegate
            {
                button1.Text = "Загружено";
            }));



            manager.StopAsync();
            engine.Dispose();
            manager.Dispose();
        }
Beispiel #5
0
 public void Dispose()
 {
     engine.Dispose();
     manager.Dispose();
 }
Beispiel #6
0
 public void Dispose() => MonoTorrentManager.Dispose();