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; }
public void RecreateManager() { if (manager != null) { manager.Dispose(); if (engine.Contains(manager)) { engine.Unregister(manager); } } torrentDict = CreateTorrent(piecelength, files, tier); torrent = Torrent.Load(torrentDict); if (MetadataMode) { manager = new TorrentManager(torrent.infoHash, savePath, new TorrentSettings(), MetadataPath, new RawTrackerTiers()); } else { manager = new TorrentManager(torrent, savePath, new TorrentSettings()); } engine.Register(manager); }