Beispiel #1
0
        public async Task <bool> RemoveAsync(TorrentManager manager)
        {
            CheckDisposed();
            Check.Manager(manager);

            await MainLoop;

            if (manager.Engine != this)
            {
                throw new TorrentException("The manager has not been registered with this engine");
            }

            if (manager.State != TorrentState.Stopped)
            {
                throw new TorrentException("The manager must be stopped before it can be unregistered");
            }

            allTorrents.Remove(manager);
            publicTorrents.Remove(manager);
            ConnectionManager.Remove(manager);
            listenManager.Remove(manager.InfoHash);

            manager.Engine = null;
            manager.DownloadLimiters.Remove(downloadLimiters);
            manager.UploadLimiters.Remove(uploadLimiters);
            return(true);
        }
        public async Task<bool> RemoveAsync (TorrentManager manager, RemoveMode mode)
        {
            CheckDisposed ();
            Check.Manager (manager);

            await MainLoop;
            if (manager.Engine != this)
                throw new TorrentException ("The manager has not been registered with this engine");

            if (manager.State != TorrentState.Stopped)
                throw new TorrentException ("The manager must be stopped before it can be unregistered");

            allTorrents.Remove (manager);
            publicTorrents.Remove (manager);
            ConnectionManager.Remove (manager);
            listenManager.Remove (manager.InfoHashes);

            manager.DownloadLimiters.Remove (downloadLimiters);
            manager.UploadLimiters.Remove (uploadLimiters);
            manager.Dispose ();

            if (mode.HasFlag (RemoveMode.CacheDataOnly)) {
                foreach (var path in new[] { Settings.GetFastResumePath (manager.InfoHashes), Settings.GetMetadataPath (manager.InfoHashes) })
                    if (File.Exists (path))
                        File.Delete (path);
            }
            if (mode.HasFlag (RemoveMode.DownloadedDataOnly)) {
                foreach (var path in manager.Files.Select (f => f.FullPath))
                    if (File.Exists (path))
                        File.Delete (path);
                // FIXME: Clear the empty directories.
            }
            return true;
        }