Exemplo n.º 1
0
        public void RemoveLabelForTorrent(TorrentInfo ti, string label)
        {
            var t = check_label(label);

            t.UnregisterTorrent(ti);
            Labels[0].RefreshCount();
        }
Exemplo n.º 2
0
        public void Handle_AddExistingLabel(object sender, RoutedEventArgs 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 => { });

                MenuItem source = e.OriginalSource as MenuItem;

                if (source.Header is TorrentLabel)
                {
                    TorrentLabel l = (TorrentLabel)source.Header;
                    if (l.Name == null)
                    {
                        //clear the labels
                        f = new Action <TorrentInfo>(t => state.LabelManager.ClearLabels(t));
                    }
                    else
                    {
                        f = new Action <TorrentInfo>(t => state.LabelManager.AddLabelForTorrent(t, l));
                    }
                }

                foreach (var t in arr)
                {
                    f(t);
                }
            }
        }
Exemplo n.º 3
0
        private void PeersCommands_AddPeer(object sender, RoutedEventArgs e)
        {
            TorrentInfo ti = mainlist.SelectedItem as TorrentInfo;

            if (ti != null)
            {
                if (ti.Info.Private)
                {
                    MessageBox.Show("You cannot add external peers to a private torrent", "Add peer");
                }
                else
                {
                    MessageBox.Show("Not implemented yet");

                    /*
                     * var p = new UI.AddNewPeerDialog() { Owner = this, Icon = this.Icon };
                     *
                     * if (p.ShowDialog() == true)
                     * {
                     *
                     *  ti.Torrent.ManualAddPeer(p.IP.Split(':').First(), Convert.ToInt32(p.IP.Split(':').Last()));
                     * }*/
                }
            }
        }
Exemplo n.º 4
0
        //void LibTorrentAlerts_TorrentNetworkStatisticsUpdated(Ragnar.StatsAlert sa)
        //{
        //    string key = sa.Handle.InfoHash.ToHex();

        //    if (this._torrents.ContainsKey(key))
        //    {
        //        this._torrents[key].DoNetStatsUpdate(sa);
        //    }
        //}

        void LibTorrentAlerts_MetadataReceived(Ragnar.TorrentHandle handle)
        {
            string key = handle.InfoHash.ToHex();

            TorrentInfo ti = null;

            while (!this._torrents.ContainsKey(key))
            {
                ;                                      // HACK
            }
            ti = this._torrents[key];

            // This is critical, without it byteflood won't load this torrent at the next startup
            byte[] data = this.BackUpMangetLinkMetadata(handle.TorrentFile);

            ti.OriginalTorrentFilePath = this.SaveMagnetLink(data, handle.TorrentFile.Name);

            set_files_priorities(handle, 3);

            ti.DoMetadataDownloadComplete();

            //NotificationManager.Notify(new MagnetLinkNotification(MagnetLinkNotification.EventType.MetadataDownloadComplete, handle));

            handle_torrent_file_selection(ti);
        }
Exemplo n.º 5
0
 public void UnregisterTorrent(TorrentInfo ti)
 {
     if (this.Name != null)
     {
         my_torrent_list.Remove(ti);
     }
 }
Exemplo n.º 6
0
 public void ClearLabels(TorrentInfo ti)
 {
     for (int i = 1 /*skip the null label*/; i < Labels.Count; i++)
     {
         Labels[i].UnregisterTorrent(ti);
     }
     Labels[0].RegisterTorrent(ti); // the null label
 }
Exemplo n.º 7
0
 public int GetTorrentIndex(TorrentInfo ti)
 {
     if (App.Settings.EnableQueue && queue_info_store.ContainsKey(ti.InfoHash))
     {
         return(Array.IndexOf(queue_info_store.Keys.ToArray(), ti.InfoHash));
     }
     return(-1);
 }
Exemplo n.º 8
0
 public AddTorrentDialog(TorrentInfo torrent)
 {
     InitializeComponent();
     this.Closed         += (s, e) => { this.WindowClosed = true; };
     this.TorrentInfo     = torrent;
     this.TorrentFileInfo = torrent.Info;
     Load();
 }
Exemplo n.º 9
0
 private void ResetDataContext()
 {
     this.SelectedTorrent = null;
     //peers_list.ItemsSource = null;
     files_tree.Model = null;
     //piece_bar.DetachTorrent();
     //webseeds_list.ItemsSource = null;
     //webseeds_tab.Visibility = Visibility.Collapsed;
 }
Exemplo n.º 10
0
 public void RegisterTorrent(TorrentInfo ti)
 {
     if (this.Name != null)
     {
         if (!my_torrent_list.Contains(ti))
         {
             my_torrent_list.Add(ti);
         }
     }
 }
Exemplo n.º 11
0
        public void AddTorrentByPath(string path, bool notifyIfAdded = true)
        {
            Ragnar.TorrentInfo torrent = null;

            try
            {
                torrent = new Ragnar.TorrentInfo(File.ReadAllBytes(path));

                if (!torrent.IsValid)
                {
                    torrent.Dispose();
                    MessageBox.Show(string.Format("Invalid torrent file {0}", path), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                if (this.ContainTorrent(torrent.InfoHash))
                {
                    if (notifyIfAdded)
                    {
                        NotificationManager.Notify(new TorrentAlreadyAddedNotification(torrent.Name, torrent.InfoHash));
                    }
                    return;
                }

                path = BackupTorrent(path, torrent);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Could not load torrent {0}\n{1}", path, ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var handle = this.LibtorrentSession.AddTorrent(new Ragnar.AddTorrentParams()
            {
                TorrentInfo = torrent,
                SavePath    = App.Settings.DefaultDownloadPath
            });

            handle.AutoManaged = false;
            handle.Pause();


            TorrentInfo ti = new TorrentInfo(handle);

            ti.OriginalTorrentFilePath = path;
            ti.ApplyTorrentSettings(App.Settings.DefaultTorrentProperties);

            // we don't want all files to have a "lowest" file priorities since initialize priorities with the value 1
            // we change it to 3, the priority "normal" as considered by byteflood.

            set_files_priorities(handle, 3);

            handle_torrent_file_selection(ti);
        }
Exemplo n.º 12
0
 public FileInfo(TorrentInfo owner, Ragnar.FileEntry file, int file_index)
 {
     this.file_path = file.Path.FixUTF8();
     this.RawSize   = file.Size;
     this.Owner     = owner;
     this.FileIndex = file_index;
     if (this.Owner != null)
     {
         this.Owner.FileInfoList.Add(this);
     }
 }
Exemplo n.º 13
0
 public bool HasTorrent(TorrentInfo ti)
 {
     if (this.Name == null)
     {
         return(false);
     }
     else
     {
         return(my_torrent_list.Contains(ti));
     }
 }
Exemplo n.º 14
0
 public string GetFirstLabelForTorrent(TorrentInfo ti)
 {
     for (int i = 1 /*skip the null label*/; i < Labels.Count; i++)
     {
         if (Labels[i].HasTorrent(ti))
         {
             return(Labels[i].Name);
         }
     }
     return(null);
 }
Exemplo n.º 15
0
 public bool TorrentHasAnyLabel(TorrentInfo ti)
 {
     for (int i = 1 /*skip the null label*/; i < Labels.Count; i++)
     {
         if (Labels[i].HasTorrent(ti))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 16
0
 private void SetDataContext(TorrentInfo ti)
 {
     this.SelectedTorrent = ti;
     //peers_list.ItemsSource = ti.Peers;
     files_tree.Model = ti.FilesTree;
     //piece_bar.AttachTorrent(ti);
     //if (ti.Torrent.Torrent.GetRightHttpSeeds.Count > 0)
     //{
     //    webseeds_tab.Visibility = Visibility.Visible;
     //    webseeds_list.ItemsSource = ti.Torrent.Torrent.GetRightHttpSeeds;
     //}
 }
Exemplo n.º 17
0
 void LibTorrentAlerts_TorrentAdded(Ragnar.TorrentHandle handle)
 {
     App.Current.Dispatcher.Invoke(new Action(() =>
     {
         if (!_torrents.ContainsKey(handle.InfoHash.ToHex()))
         {
             TorrentInfo ti = new TorrentInfo(handle);
             this._torrents.Add(handle.InfoHash.ToHex(), ti);
             this.Torrents.Add(ti);
         }
     }));
 }
Exemplo n.º 18
0
 private bool is_inactive(TorrentInfo ti)
 {
     if (ti.Torrent != null)
     {
         return
             (ti.Torrent.State == MonoTorrent.Common.TorrentState.Stopped ||
              ti.Torrent.State == MonoTorrent.Common.TorrentState.Error ||
              ti.Torrent.State == MonoTorrent.Common.TorrentState.Stopping ||
              !App.Settings.SeedingTorrentsAreActive && ti.Torrent.State == MonoTorrent.Common.TorrentState.Seeding);
     }
     return(false);
 }
Exemplo n.º 19
0
 /// <summary>
 /// The caller should stop/start/whatever on the torrent, since it's no longer in the queue
 /// </summary>
 public void DeQueueTorrent(TorrentInfo ti)
 {
     if (queue_info_store.ContainsKey(ti.InfoHash))
     {
         var cake = queue_info_store[ti.InfoHash];
         cake.Dequeue();
         queue_info_store.Remove(ti.InfoHash);
     }
     else
     {
         ti.QueueState = QueueState.NotQueued;
     }
 }
Exemplo n.º 20
0
 public bool Can_I_ShowUP(TorrentInfo ti)
 {
     if (this.EnableFilter)
     {
         if (_sl != null)
         {
             return(TorrentHasLabel(ti, SelectedLabel));
         }
         else
         {
             return(!TorrentHasAnyLabel(ti));
         }
     }
     return(true);
 }
Exemplo n.º 21
0
        public string[] GetLabelsForTorrent(TorrentInfo ti)
        {
            List <string> a = new List <string>();

            for (int i = 1 /*skip the null label*/; i < Labels.Count; i++)
            {
                TorrentLabel label = Labels[i];
                if (label.HasTorrent(ti))
                {
                    a.Add(label.Name);
                }
            }

            return(a.ToArray());
        }
Exemplo n.º 22
0
        public TorrentPropertiesEditor(TorrentInfo torrent)
        {
            InitializeComponent();

            if (torrent != null)
            {
                this.ti = torrent;
                this.TorrentProperties = torrent.TorrentSettings;
                this.Title             = string.Format("{0} - ({1})", this.Title, this.ti.Name);
            }
            else
            {
                throw new System.ArgumentNullException("torrent");
            }
        }
Exemplo n.º 23
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);
        }
Exemplo n.º 24
0
        public void ReDrawGraph()
        {
            if (mainlist.SelectedIndex == -1)
            {
                graph.Clear();
                return;
            }
            TorrentInfo ti = ((TorrentInfo)mainlist.Items[mainlist.SelectedIndex]);

            graph.Clear();
            bool drawdown = false;
            bool drawup   = false;
            int  index    = graph_selector.SelectedIndex;

            switch (index)
            {
            case 0:
                drawdown = drawup = true;
                break;

            case 1:
                drawdown = true;
                drawup   = false;
                break;

            case 2:
                drawdown = false;
                drawup   = true;
                break;

            default:
                drawdown = drawup = true;
                break;
            }
            graph.Draw(ti.DownSpeeds.ToArray(), ti.UpSpeeds.ToArray(), drawdown, drawup);
            Thickness size = Utility.SizeToMargin(graph.GetSize());

            if (App.Settings.DrawGrid)
            {
                graph.DrawGrid(size.Left, size.Top, size.Right, size.Bottom);
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// No use outside of TorrentInfo.PopulateFileList()
        /// </summary>
        /// <param name="branch"></param>
        /// <param name="trunk"></param>
        public static void ProcessFile(string branch, DirectoryKey trunk, TorrentInfo owner, Ragnar.FileEntry f, int index)
        {
            string[] parts = branch.Split('\\');
            if (parts.Length == 1)
            {
                //((FileList)trunk[DirectoryKey.FILE_MARKER]).Add(new FileInfo(owner, f));
                trunk.Add(f.Path, new FileInfo(owner, f, index));
            }
            else
            {
                string node  = parts[0];
                string other = branch.Substring(node.Length + 1);

                if (!trunk.ContainsKey(node))
                {
                    trunk[node] = new DirectoryKey(node, owner);
                }
                ProcessFile(other, (DirectoryKey)trunk[node], owner, f, index);
            }
        }
Exemplo n.º 26
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();
        }
Exemplo n.º 27
0
        private void DeleteData(TorrentInfo t)
        {
            return;

            /*List<string> directories = new List<string>();
             *
             * foreach (TorrentFile file in t.Torrent.Torrent.Files)
             * {
             *  if (System.IO.File.Exists(file.FullPath))
             *  {
             *      directories.Add(new System.IO.FileInfo(file.FullPath).Directory.FullName);
             *      System.IO.File.Delete(file.FullPath);
             *  }
             * }
             * directories = directories.Distinct().ToList();
             * foreach (string str in directories)
             * {
             *  System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(str);
             *  if (dir.GetFiles().Length == 0)
             *      dir.Delete();
             * }*/
        }
Exemplo n.º 28
0
        private void Torrent_RetrieveMovieInfo(object sender, RoutedEventArgs e)
        {
            TorrentInfo ti = mainlist.SelectedItem as TorrentInfo;

            if (ti.PickedMovieData != null && ti.PickedMovieData.Value != null)
            {
                var a = MessageBox.Show("The selected torrent already has movie infomation. Do you which to change it?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (a != MessageBoxResult.Yes)
                {
                    return;
                }
            }
            UI.MovieInfoChooser m = new UI.MovieInfoChooser()
            {
                Title       = string.Format("Pick info for torrent: {0}", ti.Name),
                Owner       = this,
                Icon        = this.Icon,
                SearchQuery = ti.Name,
                Torrent     = ti
            };
            m.Show();
        }
Exemplo n.º 29
0
 public TrackerInfo(Ragnar.AnnounceEntry t, TorrentInfo parent)
 {
     this.Tracker = t;
     this.Parent  = parent;
 }
Exemplo n.º 30
0
        public void SaveState(bool is_shuttingdown = false)
        {
            Directory.CreateDirectory(StateSaveDirectory);

            File.WriteAllBytes(this.LtSessionFilePath, this.LibtorrentSession.SaveState());

            for (int index = 0; index < this.Torrents.Count; index++)
            {
                try
                {
                    TorrentInfo          ti     = this.Torrents[index];
                    Ragnar.TorrentHandle handle = ti.Torrent;
                    if (!handle.HasMetadata)
                    {
                        continue;
                    }

                    if (handle.NeedSaveResumeData())
                    {
                        handle.SaveResumeData();
                    }

                    if (is_shuttingdown)
                    {
                        //save misc settings

                        JsonObject jo = new JsonObject();
                        jo.Add("SavePath", handle.QueryStatus().SavePath);

                        //jo.Add("PickedMovieData", ti.PickedMovieData.ToString());

                        jo.Add("RanCommand", ti.RanCommand);

                        jo.Add("RatioLimit", ti.RatioLimit);

                        jo.Add("CompletionCommand", ti.CompletionCommand);

                        jo.Add("CustomName", ti.Name);

                        jo.Add("OriginalTorrentFilePath", ti.OriginalTorrentFilePath);

                        jo.Add("IsStopped", ti.IsStopped);

                        jo.Add("Labels", this.LabelManager.GetLabelsForTorrent(ti));

                        using (TextWriter tw = File.CreateText(
                                   Path.Combine(State.TorrentsStateSaveDirectory, ti.InfoHash + ".tjson")))
                        {
                            JsonConvert.Export(jo, tw);
                        }
                    }
                }
                catch (System.IndexOutOfRangeException)
                {
                    break;
                }
                catch (Exception)
                {
                    continue;
                }
            }
        }