Ejemplo n.º 1
0
        public void RemoveTorrent(bool deleteTorrent, bool deleteData)
        {
            EventHandler <ShouldRemoveEventArgs> h = ShouldRemove;

            if (h != null)
            {
                ShouldRemoveEventArgs e = new ShouldRemoveEventArgs(SelectedDownloads, deleteData, deleteTorrent);
                h(this, e);
                if (!e.ShouldRemove)
                {
                    return;
                }
            }

            foreach (Download torrent in SelectedDownloads)
            {
                if (torrent.State != Monsoon.State.Stopped)
                {
                    torrent.Stop();
                }

                allTorrents.Remove(torrent);

                if (deleteData)
                {
                    logger.Info("Deleting {0} data", torrent.Torrent.Name);
                    try{
                        if (Directory.Exists(Path.Combine(torrent.SavePath, torrent.Torrent.Name)))
                        {
                            Directory.Delete(Path.Combine(torrent.SavePath, torrent.Torrent.Name), true);
                        }
                        else
                        {
                            File.Delete(Path.Combine(torrent.SavePath, torrent.Torrent.Name));
                        }
                    } catch (Exception e) {
                        logger.Error("Failed to delete {0}: {1}", Path.Combine(torrent.SavePath, torrent.Torrent.Name), e.Message);
                    }
                }

                if (deleteTorrent)
                {
                    try{
                        logger.Info("Deleting torrent file {0} ", torrent.Torrent.TorrentPath);
                        File.Delete(torrent.Torrent.TorrentPath);
                    } catch {
                        logger.Error("Unable to delete " + torrent.Torrent.TorrentPath);
                    }

                    // FIXME: Fast resume is central now, not individual for each torrent.
                    try{
                        logger.Info("Deleting torrent fast resume file " + torrent.Torrent.TorrentPath);
                        File.Delete(torrent.Torrent.TorrentPath + ".fresume");
                    } catch {
                        logger.Error("Unable to delete " + torrent.Torrent.TorrentPath + ".fresume");
                    }
                }

                engine.Unregister(torrent.Manager);
                fastResume.RemoveAll(delegate(FastResume f) {
                    return(f.Infohash == torrent.InfoHash);
                });

                logger.Info("Removed torrent " + torrent.Torrent.Name);
            }
            foreach (Download download in new List <Download> (SelectedDownloads))
            {
                Event.Raise <DownloadAddedEventArgs> (Removed, this, new DownloadAddedEventArgs(download));
            }
            SelectedDownloads.Clear();
            Select(SelectedDownloads);
        }
Ejemplo n.º 2
0
 public void Select(IEnumerable <Download> downloads)
 {
     SelectedDownloads.Clear();
     SelectedDownloads.AddRange(downloads);
     Event.Raise(SelectionChanged, this, EventArgs.Empty);
 }