Beispiel #1
0
        public TorrentItem(Core.TorrentStatus ts)
        {
            Formatter = x => ((int)x).ToString() + "%";
            FileList  = new ObservableCollection <FileEntry>();

            using (Core.Sha1Hash hash = ts.info_hash)
            {
                Hash = hash.ToString();
            }

            FileEntry fe;
            int       piecesOffset = 0;

            using (Core.TorrentInfo tf = ts.torrent_file())
                using (Core.FileStorage fs = tf.files())
                {
                    // per ogni file nel torrent
                    for (int i = 0; i <= tf.num_files() - 1; i++)
                    {
                        using (Core.FileEntry cfe = fs.at(i))
                            using (Core.Sha1Hash hash = cfe.filehash)
                            {
                                // lo inserisco
                                fe           = new FileEntry(cfe);
                                fe.FileName  = fs.file_name(i);
                                fe.IsValid   = fs.is_valid();
                                fe.PieceSize = fs.piece_size(i);

                                if (fe.PieceSize > fe.Size)
                                {
                                    // one piece
                                    fe.Pieces.Add(new Part()
                                    {
                                        Id = piecesOffset, Downloaded = false, Priority = 4
                                    });
                                }
                                else
                                {
                                    decimal piecesUsed = fe.Size / fe.PieceSize;
                                    for (int u = 0; u < piecesUsed; u++)
                                    {
                                        fe.Pieces.Add(new Part()
                                        {
                                            Id = piecesOffset, Downloaded = false, Priority = 4
                                        });
                                        piecesOffset++;
                                    }
                                }
                                FileList.Add(fe);
                            }
                    }
                }
            if (FileList.Count == 0)
            {
                // non ci sono file nel torrent
                fe          = new FileEntry();
                fe.FileName = ts.name;
                FileList.Add(fe);
            }

            SequentialDownload = ts.sequential_download;
            Update(ts);
        }