public static void OnFinishLoading(TorrentManager manager) { if (manager.State == TorrentState.Seeding) { manager.Pause(); } else if (manager.State == TorrentState.Downloading) { long size = 0; long downloaded = 0; if (manager.Torrent != null) { foreach (var f in manager.Torrent.Files) { if (f.Priority != Priority.DoNotDownload) { size += f.Length; downloaded += f.BytesDownloaded; } } } if (downloaded >= size) { manager.Pause(); } } Background.CheckToStopBackground(); }
public override void Pause() { if (manager != null) { manager.Pause(); } else { throw new InvalidOperationException("Transfer has not been started."); } }
public override void ViewDidLoad() { base.ViewDidLoad(); if (manager == null) { return; } Update(); tableView.DataSource = this; tableView.Delegate = this; Start.Clicked += delegate { manager.Start(); Update(); }; Pause.Clicked += delegate { manager.Pause(); Update(); }; Remove.Clicked += delegate { var message = manager.HasMetadata ? "Are you sure to remove " + manager.Torrent.Name + " torrent?" : "Are you sure to remove this magnet torrent?"; var actionController = UIAlertController.Create(null, message, UIAlertControllerStyle.ActionSheet); var removeAll = UIAlertAction.Create("Yes and remove data", UIAlertActionStyle.Destructive, delegate { if (manager.State == TorrentState.Stopped) { Manager.Singletone.UnregisterManager(manager); } else { manager.TorrentStateChanged += (sender, e) => { if (e.NewState == TorrentState.Stopped) { Manager.Singletone.UnregisterManager(manager); } }; manager.Stop(); } Manager.Singletone.managers.Remove(manager); Directory.Delete(Path.Combine(Manager.RootFolder, manager.Torrent.Name), true); File.Delete(manager.Torrent.TorrentPath); if (UIApplication.SharedApplication.KeyWindow.RootViewController is UISplitViewController splitController) { if (splitController.Collapsed) { (splitController.ViewControllers[0] as UINavigationController).PopViewController(true); } splitController.ShowDetailViewController(Utils.CreateEmptyViewController(), this); } });
private void OnStartItemActivated(object sender, EventArgs args) { if (selectedTorrent.State == TorrentState.Seeding || selectedTorrent.State == TorrentState.Downloading) { try{ selectedTorrent.Pause(); } catch (Exception) { logger.Warn("Unable to pause " + selectedTorrent.Torrent.Name); } } else { try{ selectedTorrent.Start(); }catch (Exception) { } logger.Warn("Unable to start " + selectedTorrent.Torrent.Name); } }
public void Pause() { manager.Pause(); }
public void Pause() => TorrentManager.Pause();
public void TorrentControl(int selected) { Dialog d = new Dialog(60, 8, "Torrent Control"); TorrentManager item = items [selected]; d.Add(new TrimLabel(1, 1, 60 - 6, item.Torrent.Name)); bool stopped = item.State == TorrentState.Stopped; Button bstartstop = new Button(stopped ? "Start" : "Stop"); bstartstop.Clicked += delegate { if (stopped) { item.Start(); } else { item.Stop(); } d.Running = false; }; d.AddButton(bstartstop); // Later, when we hook it up, look up the state bool paused = item.State == TorrentState.Paused; Button br = new Button(paused ? "Resume" : "Pause"); br.Clicked += delegate { if (paused) { item.Start(); } else { item.Pause(); } d.Running = false; }; d.AddButton(br); Button bd = new Button("Delete"); bd.Clicked += delegate { Application.Error("Not Implemented", "I have not implemented delete yet"); d.Running = false; }; d.AddButton(bd); Button bmap = new Button("Map"); bmap.Clicked += delegate { Application.Error("Not Implemented", "I have not implemented map yet"); d.Running = false; }; d.AddButton(bmap); Button bcancel = new Button("Cancel"); bcancel.Clicked += delegate { d.Running = false; }; Application.Run(d); UpdateStatus(); }
void RestoreTorrents() { SaveClass save = null; if (File.Exists(DatFile)) { save = Utils.DeSerializeObject <SaveClass>(DatFile); } if (Directory.Exists(ConfigFolder)) { foreach (var file in Directory.GetFiles(ConfigFolder)) { new Thread(() => { if (file.EndsWith(".torrent", StringComparison.Ordinal)) { Torrent torrent = Torrent.Load(file); TorrentManager manager = new TorrentManager(torrent, RootFolder, new TorrentSettings()); engine.Register(manager); if (save != null && save.data.ContainsKey(torrent.InfoHash.ToHex())) { if (save.data[torrent.InfoHash.ToHex()].resume != null) { manager.LoadFastResume(new FastResume(BEncodedValue.Decode(save.data[torrent.InfoHash.ToHex()].resume) as BEncodedDictionary)); switch (save.data[torrent.InfoHash.ToHex()].state) { case TorrentState.Downloading: manager.Start(); break; case TorrentState.Paused: manager.Pause(); break; case TorrentState.Stopped: manager.Stop(); break; } } foreach (var _file in torrent.Files) { if (save.data[torrent.InfoHash.ToHex()].downloading.ContainsKey(_file.Path)) { _file.Priority = save.data[torrent.InfoHash.ToHex()].downloading[_file.Path] ? Priority.Highest : Priority.DoNotDownload; } } } PiecePicker picker = new StandardPicker(); picker = new PriorityPicker(picker); manager.ChangePicker(picker); manager.TorrentStateChanged += delegate { Manager.OnFinishLoading(manager); }; foreach (TrackerTier tier in manager.TrackerManager) { foreach (Tracker t in tier.Trackers) { t.AnnounceComplete += delegate(object sender, AnnounceResponseEventArgs e) { Console.WriteLine(string.Format("{0}!: {1}", e.Successful, e.Tracker)); }; } } managers.Add(manager); UIApplication.SharedApplication.InvokeOnMainThread(() => { restoreAction?.Invoke(); }); } }).Start(); } } }
public void Pause() { manager.Pause(); Event.Raise(Paused, this, EventArgs.Empty); State = State.Paused; }