#1101 (rpc): add individual file progress to torrent-get's "files" message

This commit is contained in:
Charles Kerr
2008-07-21 18:42:51 +00:00
parent 7372c4f39f
commit c06be77724
4 changed files with 17 additions and 6 deletions
+1 -1
View File
@@ -43,7 +43,7 @@
.Op Fl g Ar directory .Op Fl g Ar directory
.Op Fl h .Op Fl h
.Op Fl m | M .Op Fl m | M
.Op Fl p .Op Fl p Ar port
.Op Fl t .Op Fl t
.Op Fl u Ar number | Fl U .Op Fl u Ar number | Fl U
.Op Fl v .Op Fl v
+5 -2
View File
@@ -615,9 +615,10 @@ printFileList( tr_benc * top )
{ {
int j=0, jn=tr_bencListSize(files); int j=0, jn=tr_bencListSize(files);
printf( "%s (%d files):\n", name, jn ); printf( "%s (%d files):\n", name, jn );
printf("%3s %8s %3s %9s %s\n", "#", "Priority", "Get", "Size", "Name" ); printf("%3s %4s %8s %3s %9s %s\n", "#", "Done", "Priority", "Get", "Size", "Name" );
for( j=0, jn=tr_bencListSize( files ); j<jn; ++j ) for( j=0, jn=tr_bencListSize( files ); j<jn; ++j )
{ {
int64_t have;
int64_t length; int64_t length;
int64_t priority; int64_t priority;
int64_t wanted; int64_t wanted;
@@ -625,10 +626,12 @@ printFileList( tr_benc * top )
tr_benc * file = tr_bencListChild( files, j ); tr_benc * file = tr_bencListChild( files, j );
if( tr_bencDictFindInt( file, "length", &length ) && if( tr_bencDictFindInt( file, "length", &length ) &&
tr_bencDictFindStr( file, "name", &filename ) && tr_bencDictFindStr( file, "name", &filename ) &&
tr_bencDictFindInt( file, "bytesCompleted", &have ) &&
tr_bencGetInt( tr_bencListChild( priorities, j ), &priority ) && tr_bencGetInt( tr_bencListChild( priorities, j ), &priority ) &&
tr_bencGetInt( tr_bencListChild( wanteds, j ), &wanted ) ) tr_bencGetInt( tr_bencListChild( wanteds, j ), &wanted ) )
{ {
char sizestr[64]; char sizestr[64];
double percent = (double)have / length;
strlsize( sizestr, length, sizeof( sizestr ) ); strlsize( sizestr, length, sizeof( sizestr ) );
const char * pristr; const char * pristr;
switch( priority ) { switch( priority ) {
@@ -636,7 +639,7 @@ printFileList( tr_benc * top )
case TR_PRI_HIGH: pristr = "High"; break; case TR_PRI_HIGH: pristr = "High"; break;
default: pristr = "Normal"; break; default: pristr = "Normal"; break;
} }
printf( "%3d: %-8s %-3s %9s %s\n", (j+1), pristr, (wanted?"Yes":"No"), sizestr, filename ); printf( "%3d: %3.0f%% %-8s %-3s %9s %s\n", (j+1), percent, pristr, (wanted?"Yes":"No"), sizestr, filename );
} }
} }
} }
+1
View File
@@ -142,6 +142,7 @@
+----------+-------------------------------------- +----------+--------------------------------------
| files is an array of objects that contain: | files is an array of objects that contain:
+----------+------------------------+------------- +----------+------------------------+-------------
| number | bytesCompleted | tr_torrent
| number | length | tr_info | number | length | tr_info
| string | name | tr_info | string | name | tr_info
-------------------+----------+------------------------+------------- -------------------+----------+------------------------+-------------
+10 -3
View File
@@ -156,16 +156,23 @@ torrentVerify( tr_handle * h, tr_benc * args_in, tr_benc * args_out UNUSED )
***/ ***/
static void static void
addFiles( const tr_info * info, tr_benc * files ) addFiles( const tr_torrent * tor, tr_benc * list )
{ {
tr_file_index_t i; tr_file_index_t i;
tr_file_index_t n;
const tr_info * info = tr_torrentInfo( tor );
tr_file_stat * files = tr_torrentFiles( tor, &n );
for( i=0; i<info->fileCount; ++i ) for( i=0; i<info->fileCount; ++i )
{ {
const tr_file * file = &info->files[i]; const tr_file * file = &info->files[i];
tr_benc * d = tr_bencListAddDict( files, 2 ); tr_benc * d = tr_bencListAddDict( list, 3 );
tr_bencDictAddInt( d, "bytesCompleted", files[i].bytesCompleted );
tr_bencDictAddInt( d, "length", file->length ); tr_bencDictAddInt( d, "length", file->length );
tr_bencDictAddStr( d, "name", file->name ); tr_bencDictAddStr( d, "name", file->name );
} }
tr_torrentFilesFree( files, n );
} }
static void static void
@@ -227,7 +234,7 @@ addInfo( const tr_torrent * tor, tr_benc * d, uint64_t fields )
} }
if( fields & TR_RPC_TORRENT_FILES ) if( fields & TR_RPC_TORRENT_FILES )
addFiles( inf, tr_bencDictAddList( d, "files", inf->fileCount ) ); addFiles( tor, tr_bencDictAddList( d, "files", inf->fileCount ) );
if( fields & TR_RPC_TORRENT_HISTORY ) { if( fields & TR_RPC_TORRENT_HISTORY ) {
tr_bencDictAddInt( d, "activityDate", st->activityDate ); tr_bencDictAddInt( d, "activityDate", st->activityDate );