From 1578ebc904d94447dc8ab8c1597e9ebce2225301 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 14 Apr 2008 15:17:16 +0000 Subject: [PATCH] get DND working in the benc resume files --- libtransmission/resume.c | 60 +++++++++++++++++++++++++++++++++++++++- libtransmission/resume.h | 11 ++++---- 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/libtransmission/resume.c b/libtransmission/resume.c index d98e5cae8..a424f4fc2 100644 --- a/libtransmission/resume.c +++ b/libtransmission/resume.c @@ -26,6 +26,7 @@ #define KEY_CORRUPT "corrupt" #define KEY_DESTINATION "destination" +#define KEY_DND "dnd" #define KEY_DOWNLOADED "downloaded" #define KEY_MAX_PEERS "max-peers" #define KEY_PAUSED "paused" @@ -99,6 +100,59 @@ loadPeers( tr_benc * dict, tr_torrent * tor ) **** ***/ +static void +saveDND( tr_benc * dict, const tr_torrent * tor ) +{ + const tr_info * inf = &tor->info; + const tr_file_index_t n = inf->fileCount; + tr_file_index_t i; + tr_benc * list; + + list = tr_bencDictAddList( dict, KEY_DND, n ); + for( i=0; ifiles[i].dnd ? 1 : 0 ); +} + +static uint64_t +loadDND( tr_benc * dict, tr_torrent * tor ) +{ + uint64_t ret = 0; + tr_info * inf = &tor->info; + const tr_file_index_t n = inf->fileCount; + tr_benc * list; + + if( tr_bencDictFindList( dict, KEY_DND, &list ) + && ( list->val.l.count == (int)n ) ) + { + int64_t tmp; + tr_file_index_t * dl = tr_new( tr_file_index_t, n ); + tr_file_index_t * dnd = tr_new( tr_file_index_t, n ); + tr_file_index_t i, dlCount=0, dndCount=0; + + for( i=0; ival.l.vals[i], &tmp ) && tmp ) + dnd[dndCount++] = i; + else + dl[dlCount++] = i; + } + + if( dndCount ) + tr_torrentInitFileDLs ( tor, dnd, dndCount, FALSE ); + if( dlCount ) + tr_torrentInitFileDLs ( tor, dl, dlCount, TRUE ); + + tr_free( dnd ); + tr_free( dl ); + ret = TR_FR_PRIORITY; + } + + return ret; +} + +/*** +**** +***/ + static void savePriorities( tr_benc * dict, const tr_torrent * tor ) { @@ -107,7 +161,7 @@ savePriorities( tr_benc * dict, const tr_torrent * tor ) tr_file_index_t i; tr_benc * list; - list = tr_bencDictAddList( dict, KEY_PRIORITY, tor->info.fileCount ); + list = tr_bencDictAddList( dict, KEY_PRIORITY, n ); for( i=0; ifiles[i].priority ); } @@ -296,6 +350,7 @@ tr_torrentSaveResume( const tr_torrent * tor ) tor->isRunning ? 0 : 1 ); savePeers( &top, tor ); savePriorities( &top, tor ); + saveDND( &top, tor ); saveProgress( &top, tor ); saveSpeedLimits( &top, tor ); @@ -381,6 +436,9 @@ tr_torrentLoadResume( tr_torrent * tor, if( fieldsToLoad & TR_FR_PROGRESS ) fieldsLoaded |= loadProgress( &top, tor ); + if( fieldsToLoad & TR_FR_DND ) + fieldsLoaded |= loadDND( &top, tor ); + if( fieldsToLoad & TR_FR_SPEEDLIMIT ) fieldsLoaded |= loadSpeedLimits( &top, tor ); diff --git a/libtransmission/resume.h b/libtransmission/resume.h index b5a11558e..2bd24f27a 100644 --- a/libtransmission/resume.h +++ b/libtransmission/resume.h @@ -20,11 +20,12 @@ enum TR_FR_CORRUPT = (1<<2), TR_FR_PEERS = (1<<3), TR_FR_PROGRESS = (1<<4), - TR_FR_PRIORITY = (1<<5), - TR_FR_SPEEDLIMIT = (1<<6), - TR_FR_RUN = (1<<7), - TR_FR_DESTINATION = (1<<8), - TR_FR_MAX_PEERS = (1<<9) + TR_FR_DND = (1<<5), + TR_FR_PRIORITY = (1<<6), + TR_FR_SPEEDLIMIT = (1<<7), + TR_FR_RUN = (1<<8), + TR_FR_DESTINATION = (1<<9), + TR_FR_MAX_PEERS = (1<<10) }; /** -- 2.40.0