Beispiel #1
0
        /// <summary>
        /// This will bring up the AddTorrentDialog, ask the user about the download path
        /// and enable file selection. This will only work if the torrent has metadata.
        /// </summary>
        /// <param name="ti"></param>
        private void handle_torrent_file_selection(TorrentInfo ti)
        {
            uiContext.Send(x =>
            {
                App.Current.MainWindow.Activate();
                AddTorrentDialog atd = new AddTorrentDialog(ti)
                {
                    Owner = App.Current.MainWindow, Icon = App.Current.MainWindow.Icon
                };
                atd.ShowDialog();
                if (atd.UserOK)
                {
                    ti.Name = atd.TorrentName;

                    if (atd.TorrentSavePath != ti.SavePath)
                    {
                        ti.ChangeSavePath(atd.TorrentSavePath);
                    }

                    if (atd.AutoStartTorrent)
                    {
                        ti.Start();
                    }
                    else
                    {
                        ti.Stop();
                    }

                    ti.RatioLimit = atd.RatioLimit;

                    if (!this._torrents.ContainsKey(ti.InfoHash))
                    {
                        this._torrents.Add(ti.InfoHash, ti);
                        this.Torrents.Add(ti);
                    }
                }
                else
                {
                    this.Torrents.Remove(ti);
                    this._torrents.Remove(ti.InfoHash);
                    this.LibtorrentSession.RemoveTorrent(ti.Torrent, true);
                    this.DeleteTorrentStateData(ti.InfoHash);
                    ti.OffMyself();
                }
            }, null);
        }
Beispiel #2
0
        private void RemoveTorrent(TorrentInfo t, string action)
        {
            t.Invisible = true;
            t.UpdateList("Invisible", "ShowOnList");
            string hash = t.InfoHash;

            t.Torrent.AutoManaged = false;
            t.Torrent.Pause();

            this.state.LibtorrentSession.RemoveTorrent(t.Torrent);
            this.state.DeleteTorrentStateData(hash);

            uiContext.Send(x =>
            {
                state._torrents.Remove(hash);
                state.Torrents.Remove(t);
                state.LabelManager.ClearLabels(t);
            }, null);

            switch (action)
            {
            case "remove_torrent_torrentonly":
                DeleteTorrent(t);
                break;

            case "remove_torrent_dataonly":
                DeleteData(t);
                break;

            case "remove_torrent_both":
                DeleteData(t);
                DeleteTorrent(t);
                break;

            default:
                break;
            }


            t.OffMyself();
        }