示例#1
0
        public TorrentList TorrentsByLabel(TorrentLabel _selectedLabel)
        {
            TorrentList list = new TorrentList();

            foreach (Sohvaperuna.TorrentEngine.Torrent torrent in _torrentsAll)
            {
                if (_selectedLabel.Name.CompareTo(torrent.Label) == 0)
                {
                    //label match!
                    list.Add(torrent);
                }
            }

            return(list);
        }
示例#2
0
    static void InitMonoTorrent()
    {
        queue            = new ArrayList();
        engine_settings  = new EngineSettings(config.DownloadDir, config.ListenPort);
        torrent_settings = new TorrentSettings(config.UploadSlots, config.MaxConnections,
                                               (int)config.UploadSpeed, (int)config.DownloadSpeed);

        engine = new ClientEngine(engine_settings);

        // Our store
        torrent_list = new TorrentList();
        foreach (TorrentDesc td in config.Torrents)
        {
            if (File.Exists(td.Filename))
            {
                torrent_list.Add(td.Filename);
            }
        }
    }
示例#3
0
        private async void TorrentAddedAlert(Core.torrent_added_alert a)
        {
            Interlocked.MemoryBarrier();
            using (Core.TorrentHandle th = a.handle)
                using (Core.TorrentStatus ts = th.status())
                {
                    Models.TorrentItem ti = new Models.TorrentItem(ts);
                    ti.PropertyChanged += torrentItem_PropertyChanged;

                    await Application.Current.Dispatcher.BeginInvoke(
                        System.Windows.Threading.DispatcherPriority.Send,
                        (Action) delegate()
                    {
                        TorrentList.Add(ti);
                        log.Debug("{0} added", ti.Name);
                        //Hardcodet.Wpf.TaskbarNotification.TaskbarIcon tbi = (Hardcodet.Wpf.TaskbarNotification.TaskbarIcon)App.Current.MainWindow.FindName("tsunamiNotifyIcon");
                        //string title = "Tsunami";
                        //string text = "New torrent added!";
                        //tbi.ShowBalloonTip(title, text, tbi.Icon, true);
                    });
                }
        }
示例#4
0
	static void InitMonoTorrent ()
	{
		queue = new ArrayList ();
		engine_settings = new EngineSettings (config.DownloadDir, config.ListenPort);
		torrent_settings = new TorrentSettings (config.UploadSlots, config.MaxConnections,
							(int) config.UploadSpeed, (int) config.DownloadSpeed);
		
		engine = new ClientEngine (engine_settings);

		// Our store
		torrent_list = new TorrentList ();
		foreach (TorrentDesc td in config.Torrents){
			if (File.Exists (td.Filename)){
				torrent_list.Add (td.Filename);
			}
		}
	}
        public bool UpdateData()
        {
            lock (lockUpdate)
            {
                string response = GetResponse("web.update_ui", DelugeAPI.UpdateParams);
                if (response == null || response.Length == 0)
                {
                    return(false);
                }
                TorrentLabelList lbls   = new TorrentLabelList();
                UpdateResponse   update = js.Deserialize <UpdateResponse>(response);

                foreach (object[] lbl in update.filters.label)
                {
                    TorrentLabel label = new TorrentLabel();
                    label.Name  = (string)lbl[0];
                    label.Count = (int)lbl[1];
                    lbls.Add(label);
                }
                _labels = lbls;
                TorrentList oldTorrentsAll = _torrentsAll;
                TorrentList newTorrentsAll = new TorrentList();
                foreach (KeyValuePair <string, DelugeTorrent> pair in update.torrents)
                {
                    DelugeTorrent tor     = pair.Value;
                    Torrent       torrent = new Torrent(this);
                    try
                    {
                        torrent.Hash              = pair.Key;
                        torrent.Status            = 0;// get Status code
                        torrent.Name              = tor.name;
                        torrent.Size              = tor.total_size;
                        torrent.Progress          = tor.progress;
                        torrent.Downloaded        = tor.total_done;
                        torrent.Uploaded          = tor.total_uploaded;
                        torrent.Ratio             = (long)Math.Round(tor.ratio);
                        torrent.UploadSpeed       = (long)Math.Round(tor.upload_payload_rate);
                        torrent.DownloadSpeed     = (long)Math.Round(tor.download_payload_rate);
                        torrent.ETA               = (int)Math.Round(tor.eta);
                        torrent.Label             = tor.label;
                        torrent.PeersConnected    = tor.num_peers;
                        torrent.PeersInSwarm      = tor.total_peers;
                        torrent.SeedsConnected    = tor.num_seeds;
                        torrent.SeedsInSwarm      = tor.total_seeds;
                        torrent.Availability      = (int)Math.Round(tor.distributed_copies);
                        torrent.TorrentQueueOrder = (int)Math.Round(tor.queue);
                        torrent.Remaining         = tor.total_size - tor.total_done;
                        torrent.DownloadURL       = "";
                        torrent.RSSFeedURL        = "";
                        torrent.StatusMessage     = tor.state;
                        torrent.StreamID          = "";
                        torrent.AddedOn           = (int)Math.Round(tor.time_added);
                        torrent.CompletedOn       = 0;
                        torrent.AppUpdateURL      = "";
                        torrent.TorrentSavePath   = tor.save_path;
                    }
                    catch { }


                    newTorrentsAll.Add(torrent);
                }

                TorrentList newTorrentsActive = new TorrentList();

                foreach (Torrent torrent in newTorrentsAll)
                {
                    if (torrent.HasStatus((int)Torrent.UTorrentStatus.Started))
                    {
                        newTorrentsActive.Add(torrent);
                    }

                    if (oldTorrentsAll != null)
                    {
                        Torrent oldTorrent = oldTorrentsAll.TorrentByHash(torrent.Hash);
                        if (oldTorrent == null)
                        {
                            //this is new torrent! Send event!
                            TimeSpan t   = (DateTime.UtcNow - new DateTime(1970, 1, 1));
                            int      now = (int)t.TotalSeconds;
                            if (TorrentAdded != null && ((now - torrent.AddedOn) < Math.Max(60, Convert.ToInt32(_outtimer) * 2)))
                            {
                                TorrentAdded(torrent);
                            }
                        }
                        else
                        {
                            if (torrent.Progress == 100 && oldTorrent.Progress < 100)
                            {
                                TorrentCompleted(torrent);
                            }
                            oldTorrentsAll.Remove(oldTorrent);
                        }
                    }
                }

                if (oldTorrentsAll != null && newTorrentsAll != null && oldTorrentsAll.Count != 0)
                {
                    if (newTorrentsAll.Count / oldTorrentsAll.Count > 0.95)
                    {
                        foreach (Torrent torrent in oldTorrentsAll)
                        {
                            //there are all removed torrents, send events!
                            if (TorrentRemoved != null)
                            {
                                TorrentRemoved(torrent);
                            }
                        }
                    }
                }

                //create no label label!
                TorrentLabel nolabel = new TorrentLabel();
                nolabel.Name = "";

                foreach (Torrent torrent in newTorrentsAll)
                {
                    if (torrent.Label == "")
                    {
                        torrent.Label = nolabel.Name;
                        nolabel.Count = nolabel.Count + 1;
                    }
                }
                if (!_labels.Exists(e => e.Name == ""))
                {
                    _labels.Insert(0, nolabel);
                }
                if (_torrentsAll == null)
                {
                    _torrentsAll = new TorrentList();
                }
                _torrentsAll.Clear();
                foreach (Torrent torrent in newTorrentsAll)
                {
                    _torrentsAll.Add(torrent);
                }
            }
            return(true);
        }
示例#6
0
        public bool UpdateData()
        {
            lock (lockUpdate)
            {
                prot.DownloadManager.Update();
                TorrentList __torrentsAll    = new TorrentList();
                TorrentList __torrentsActive = new TorrentList();
                Dictionary <string, global::AzureusEngine.AzCommunication.Download> _torrentMapping = new Dictionary <string, global::AzureusEngine.AzCommunication.Download>();
                Dictionary <string, int> categories = new Dictionary <string, int>();

                foreach (Download dl in prot.DownloadManager.Downloads)
                {
                    Sohvaperuna.TorrentEngine.Torrent tor = toUtorrent(dl);
                    if (!categories.ContainsKey(tor.Label))
                    {
                        categories.Add(tor.Label, 1);
                    }
                    else
                    {
                        categories[tor.Label] = categories[tor.Label] + 1;
                    }
                    __torrentsAll.Add(tor);
                    if (!torrentMapping.ContainsKey(tor.Hash))
                    {
                        torrentMapping.Add(tor.Hash, dl);
                        if (TorrentAdded != null)
                        {
                            TorrentAdded(tor);
                        }
                    }
                    if (tor.Status == 1)
                    {
                        __torrentsActive.Add(tor);
                    }
                }
                foreach (Sohvaperuna.TorrentEngine.Torrent tor in __torrentsAll)
                {
                    Sohvaperuna.TorrentEngine.Torrent _tor = _torrentsAll.TorrentByHash(tor.Hash);
                    if (tor != null)
                    {
                        _torrentsAll.Remove(tor);
                    }
                }


                _torrentsActive = __torrentsActive;
                _torrentsAll    = __torrentsAll;

                TorrentLabelList labels = new TorrentLabelList();
                //_labels.Clear();
                foreach (string s in categories.Keys)
                {
                    TorrentLabel lbl = new TorrentLabel();
                    lbl.Name  = s;
                    lbl.Count = categories[s];
                    labels.Add(lbl);
                }
                _labels = labels;

                /*
                 * string response = GetResponse("list=1");
                 * Regex re = new Regex("\\[\"(.*?)\",([0-9])+]");
                 * MatchCollection matches = re.Matches(response);
                 * _labels = new UTorrentLabelList();
                 * foreach (Match match in matches)
                 * {
                 *  UTorrentLabel label = new UTorrentLabel();
                 *  label.Name = match.Groups[1].Value.Replace(@"\\", @"\"); ;
                 *  label.Count = Convert.ToInt32( match.Groups[2].Value );
                 *  _labels.Add(label);
                 * }
                 *
                 * re = new Regex("\\[\"(.*?)\",([0-9-]+),\"(.*)\",([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),\"(.*)\",([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+)]");
                 * matches = re.Matches(response);
                 *
                 * UTorrentList oldTorrentsAll = _torrentsAll;
                 * UTorrentList newTorrentsAll = new UTorrentList();
                 * foreach (Match match in matches)
                 * {
                 *  UTorrent torrent = new UTorrent( this );
                 *  torrent.Hash = match.Groups[1].Value;
                 *  torrent.Status = Convert.ToInt32(match.Groups[2].Value);
                 *  torrent.Name = match.Groups[3].Value;
                 *  torrent.Size = Convert.ToInt64(match.Groups[4].Value);
                 *  torrent.Progress = Convert.ToInt32(match.Groups[5].Value) / 10.0;
                 *  torrent.Downloaded = Convert.ToInt64(match.Groups[6].Value);
                 *  torrent.Uploaded = Convert.ToInt64(match.Groups[7].Value);
                 *  torrent.Ratio = Convert.ToInt64(match.Groups[8].Value);
                 *  torrent.UploadSpeed = Convert.ToInt64(match.Groups[9].Value);
                 *  torrent.DownloadSpeed = Convert.ToInt64(match.Groups[10].Value);
                 *  torrent.ETA = Convert.ToInt32(match.Groups[11].Value);
                 *  torrent.Label = match.Groups[12].Value.Replace( @"\\", @"\" );
                 *  torrent.PeersConnected = Convert.ToInt32(match.Groups[13].Value);
                 *  torrent.PeersInSwarm = Convert.ToInt32(match.Groups[14].Value);
                 *  torrent.SeedsConnected = Convert.ToInt32(match.Groups[15].Value);
                 *  torrent.SeedsInSwarm = Convert.ToInt32(match.Groups[16].Value);
                 *  torrent.Availability = Convert.ToInt32(match.Groups[17].Value);
                 *  torrent.TorrentQueueOrder = Convert.ToInt32(match.Groups[18].Value);
                 *  torrent.Remaining = Convert.ToInt64(match.Groups[19].Value);
                 *
                 *  newTorrentsAll.Add(torrent);
                 * }
                 *
                 * UTorrentList newTorrentsActive = new UTorrentList();
                 *
                 * foreach (UTorrent torrent in newTorrentsAll)
                 * {
                 *  if (torrent.HasStatus((int)UTorrent.UTorrentStatus.Started))
                 *  {
                 *      newTorrentsActive.Add(torrent);
                 *  }
                 *
                 *  if (oldTorrentsAll != null)
                 *  {
                 *      UTorrent oldTorrent = oldTorrentsAll.TorrentByHash(torrent.Hash);
                 *      if (oldTorrent == null)
                 *      {
                 *          //this is new torrent! Send event!
                 *          if (TorrentAdded != null)
                 *          {
                 *              TorrentAdded(torrent);
                 *          }
                 *      }
                 *      else
                 *      {
                 *          oldTorrentsAll.Remove(oldTorrent);
                 *      }
                 *  }
                 * }
                 *
                 * if (oldTorrentsAll != null)
                 * {
                 *  foreach (UTorrent torrent in oldTorrentsAll)
                 *  {
                 *      //there are all removed torrents, send events!
                 *      if (TorrentRemoved != null)
                 *      {
                 *          TorrentRemoved(torrent);
                 *      }
                 *  }
                 * }
                 *
                 * //create no label label!
                 * UTorrentLabel nolabel = new UTorrentLabel();
                 * nolabel.Name = "";
                 *
                 * foreach (UTorrent torrent in newTorrentsAll)
                 * {
                 *  if (torrent.Label == "")
                 *  {
                 *      torrent.Label = nolabel.Name;
                 *      nolabel.Count = nolabel.Count + 1;
                 *  }
                 * }
                 *
                 * _labels.Insert(0, nolabel);
                 *
                 * if (_torrentsActive == null)
                 * {
                 *  _torrentsActive = new UTorrentList();
                 * }
                 * _torrentsActive.Clear();
                 * foreach (UTorrent torrent in newTorrentsActive)
                 * {
                 *  _torrentsActive.Add(torrent);
                 * }
                 * if (_torrentsAll == null)
                 * {
                 *  _torrentsAll = new UTorrentList();
                 * }
                 * _torrentsAll.Clear();
                 * foreach (UTorrent torrent in newTorrentsAll)
                 * {
                 *  _torrentsAll.Add(torrent);
                 * }*/
            }
            return(true);
        }