示例#1
0
        private TorrentDirectoryItem FindOrCreateDirectory(
            string path,
            Dictionary <string, TorrentDirectoryItem> dirs
            )
        {
            TorrentDirectoryItem dir;

            dirs.TryGetValue(path, out dir);

            if (dir != null)
            {
                // Found already added directory.
                return(dir);
            }
            else
            {
                // Directory doesn't exist, find or add parent one, then add this one.
                int sep_pos = path.LastIndexOf('/');

                string parent_path          = path.Substring(0, sep_pos == -1 ? 0 : sep_pos);
                TorrentDirectoryItem parent = FindOrCreateDirectory(parent_path, dirs);

                string name = path.Substring(sep_pos + 1);
                dir = new TorrentDirectoryItem(parent.Torrent, parent, name);

                parent.Files.Add(dir);
                dirs.Add(path, dir);

                return(dir);
            }
        }
示例#2
0
 public TorrentDirectoryItem(TorrentItem torrent, TorrentDirectoryItem parent, string name)
 {
     _torrent = torrent;
     _parent  = parent;
     _name    = name;
     _files   = new List <Item>();
 }
示例#3
0
 public TorrentItem(TransmissionAPI.TorrentInfo info)
 {
     _hash_string          = info.HashString;
     _name                 = info.Name;
     _comment              = info.Comment;
     _status               = info.Status;
     _size                 = info.TotalSize;
     _download_speed_limit = info.DownloadLimit;
     _upload_speed_limit   = info.UploadLimit;
     _root                 = new TorrentDirectoryItem(this, null, info.DownloadDir);
 }
示例#4
0
        public TorrentFileItem(
            TorrentItem torrent, int index, TorrentDirectoryItem parent,
            string name, TransmissionAPI.TorrentFileInfo info
            )
        {
            _torrent = torrent;
            _index   = index;

            _parent     = parent;
            _name       = name;
            _size       = info.Length;
            _downloaded = info.BytesCompleted;

            _wanted   = info.Wanted;
            _priority = info.Priority;
        }
示例#5
0
        public override void UpdateItems()
        {
            Log <TorrentItemSource> .Debug("Updating torrents list");

            // Clear current torrents list.
            _torrents.Clear();

            TransmissionAPI api = TransmissionPlugin.getTransmission();

            foreach (TransmissionAPI.TorrentInfo t in api.GetAllTorrents())
            {
                Log <TorrentItemSource> .Debug("Torrent: {0}", t.Name);

                TorrentItem torrent = new TorrentItem(t);

                // Transmission returns files as flat list with full names, this map
                // is used to organize files into hierarchy.
                // It maps directory path to directory item.
                Dictionary <string, TorrentDirectoryItem> dirs = new Dictionary <string, TorrentDirectoryItem>();
                dirs.Add("", torrent.Root);

                int index = 0;                 // File index within list.
                foreach (TransmissionAPI.TorrentFileInfo f in t.Files)
                {
                    // Split path and name.
                    int sep_pos = f.Name.LastIndexOf('/');

                    string name = f.Name.Substring(sep_pos + 1);
                    string path = f.Name.Substring(0, sep_pos == -1 ? 0 : sep_pos);
                    Log <TorrentItemSource> .Debug("File {0} in dir {1}", name, path);

                    TorrentDirectoryItem dir = FindOrCreateDirectory(path, dirs);

                    dir.Files.Add(new TorrentFileItem(torrent, index, dir, name, f));

                    ++index;
                }

                _torrents.Add(torrent);
            }
        }