コード例 #1
0
 public FileEntry(Core.FileEntry fe)
 {
     Pieces = new ObservableCollection <Part>();
     using (Core.Sha1Hash hash = fe.filehash)
     {
         Filehash = hash.ToString();
     }
     Size = fe.size;
     Update(fe);
 }
コード例 #2
0
 public void Update(Core.FileEntry fe)
 {
     //ExecutableAttribute = fe.executable_attribute;
     //FileBase = fe.file_base;
     //HiddenAttribute = fe.hidden_attribute;
     //Mtime = fe.mtime;
     //Offset = fe.offset;
     //PadFile = fe.pad_file;
     //Path = fe.path;
     //SymlinkAttribute = fe.symlink_attribute;
     //SymlinkPath = fe.symlink_path;
 }
コード例 #3
0
ファイル: TorrentItem.cs プロジェクト: windygu/Tsunami-wpf
        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);
        }