Exemplo n.º 1
0
        private byte[] BackUpMangetLinkMetadata(Ragnar.TorrentInfo info)
        {
            Ragnar.TorrentCreator tc = new Ragnar.TorrentCreator(info);
            byte[] f = tc.Generate();
            tc.Dispose();
            string path = System.IO.Path.Combine(State.TorrentsStateSaveDirectory, info.InfoHash + ".torrent");

            File.WriteAllBytes(path, f);
            return(f);
        }
Exemplo n.º 2
0
 private byte[] BackUpMangetLinkMetadata(Ragnar.TorrentInfo info)
 {
     Ragnar.TorrentCreator tc = new Ragnar.TorrentCreator(info);
     byte[] f = tc.Generate();
     tc.Dispose();
     string path = System.IO.Path.Combine(State.TorrentsStateSaveDirectory, info.InfoHash + ".torrent");
     File.WriteAllBytes(path, f);
     return f;
 }
Exemplo n.º 3
0
        private void TorrentListCommands_ActionOnSelectedTorrents(object sender, ExecutedRoutedEventArgs e)
        {
            if (mainlist.SelectedItems.Count > 0)
            {
                TorrentInfo[] arr = new TorrentInfo[mainlist.SelectedItems.Count];
                mainlist.SelectedItems.CopyTo(arr, 0);
                Action <TorrentInfo> f = new Action <TorrentInfo>(t => { });

                string action = Convert.ToString(e.Parameter);
                switch (action)
                {
                case "OpenDownloadDirectory":
                    f = new Action <TorrentInfo>(t =>
                    {
                        System.IO.Directory.CreateDirectory(t.SavePath);
                        Process.Start("explorer.exe", "/select, \"" + t.SavePath + "\"");
                    });
                    break;

                case "EditProperties":
                    f = new Action <TorrentInfo>(t =>
                    {
                        if (t.HasMetadata)
                        {
                            var editor = new TorrentPropertiesEditor(t)
                            {
                                Owner = this, Icon = this.Icon
                            };
                            editor.ShowDialog();
                        }
                        else
                        {
                            MessageBox.Show("Cannot edit properties because torrent has no metadata");
                        }
                    });
                    break;

                case "Start":
                    f = new Action <TorrentInfo>(t => t.Start());
                    break;

                case "Pause":
                    f = new Action <TorrentInfo>(t => t.Pause());
                    break;

                case "Stop":
                    f = new Action <TorrentInfo>(t => t.Stop());
                    break;

                case "ForcePause":
                    f = new Action <TorrentInfo>(t => t.ForcePause());
                    break;

                case "ForceStart":
                    f = new Action <TorrentInfo>(t => t.ForceStart());
                    break;

                case "Recheck":
                    f = new Action <TorrentInfo>(t => t.Recheck());
                    break;

                case "CopyMagnetLink":
                    if (this.SelectedTorrent != null)
                    {
                        Clipboard.SetText(this.SelectedTorrent.GetMagnetLink());
                    }
                    break;

                case "SaveTorrentFile":
                    if (this.SelectedTorrent != null)
                    {
                        if (this.SelectedTorrent.HasMetadata)
                        {
                            SaveFileDialog sfd = new SaveFileDialog();
                            sfd.Filter           = "Torrent file|*.torrent";
                            sfd.FileName         = this.SelectedTorrent.Name;
                            sfd.InitialDirectory = App.Settings.SaveTorrentDialogLastPath;
                            if (sfd.ShowDialog() == true)
                            {
                                Ragnar.TorrentCreator tc = new Ragnar.TorrentCreator(this.SelectedTorrent.Info);
                                byte[] data = tc.Generate();
                                tc.Dispose();
                                System.IO.File.WriteAllBytes(sfd.FileName, data);
                                App.Settings.SaveTorrentDialogLastPath = System.IO.Path.GetDirectoryName(sfd.FileName);
                            }
                        }
                    }
                    break;

                case "AddLabel":
                    UI.AddLabelDialog dl = new UI.AddLabelDialog()
                    {
                        Owner = this, Icon = this.Icon
                    };

                    if (dl.ShowDialog() == true)
                    {
                        f = new Action <TorrentInfo>(t => state.LabelManager.AddLabelForTorrent(t, dl.LabelText));
                    }
                    else
                    {
                        return;
                    }

                    break;

                case "remove_torrent_unlist":
                case "remove_torrent_torrentonly":
                case "remove_torrent_dataonly":
                case "remove_torrent_both":
                    f = new Action <TorrentInfo>(t => { RemoveTorrent(t, action); });
                    break;

                default:
                    break;
                }
                foreach (TorrentInfo ti in arr)
                {
                    f(ti);
                }
            }
        }