Esempio 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);
        }
Esempio n. 2
0
        void HandleShouldRemove(object sender, ShouldRemoveEventArgs e)
        {
            string title;
            string message;

            if (e.DeleteData) {
                title = _("Delete torrent");
                message = _("Remove torrent and delete all data?");
            } else {
                title = _("Remove torrent");
                message = _("Are you sure you want to remove the torrent?");
            }

            MessageDialog messageDialog = new MessageDialog (this,
                                                             DialogFlags.Modal,
                                                             MessageType.Question,
                                                             ButtonsType.YesNo, message);
            messageDialog.Title = title;
            e.ShouldRemove = (ResponseType) messageDialog.Run() == ResponseType.Yes;
            messageDialog.Hide();
            messageDialog.Destroy ();
        }
Esempio n. 3
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);
        }