Changeset 5614


Ignore:
Timestamp:
Apr 14, 2008, 3:17:16 PM (14 years ago)
Author:
charles
Message:

get DND working in the benc resume files

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/resume.c

    r5613 r5614  
    2727#define KEY_CORRUPT     "corrupt"
    2828#define KEY_DESTINATION "destination"
     29#define KEY_DND         "dnd"
    2930#define KEY_DOWNLOADED  "downloaded"
    3031#define KEY_MAX_PEERS   "max-peers"
     
    101102
    102103static void
    103 savePriorities( tr_benc * dict, const tr_torrent * tor )
     104saveDND( tr_benc * dict, const tr_torrent * tor )
    104105{
    105106    const tr_info * inf = &tor->info;
     
    108109    tr_benc * list;
    109110
    110     list = tr_bencDictAddList( dict, KEY_PRIORITY, tor->info.fileCount );
     111    list = tr_bencDictAddList( dict, KEY_DND, n );
     112    for( i=0; i<n; ++i )
     113        tr_bencInitInt( tr_bencListAdd( list ), inf->files[i].dnd ? 1 : 0 );
     114}
     115
     116static uint64_t
     117loadDND( tr_benc * dict, tr_torrent * tor )
     118{
     119    uint64_t ret = 0;
     120    tr_info * inf = &tor->info;
     121    const tr_file_index_t n = inf->fileCount;
     122    tr_benc * list;
     123
     124    if( tr_bencDictFindList( dict, KEY_DND, &list )
     125        && ( list->val.l.count == (int)n ) )
     126    {
     127        int64_t tmp;
     128        tr_file_index_t * dl = tr_new( tr_file_index_t, n );
     129        tr_file_index_t * dnd = tr_new( tr_file_index_t, n );
     130        tr_file_index_t i, dlCount=0, dndCount=0;
     131
     132        for( i=0; i<n; ++i ) {
     133            if( tr_bencGetInt( &list->val.l.vals[i], &tmp ) && tmp )
     134                dnd[dndCount++] = i;
     135            else
     136                dl[dlCount++] = i;
     137        }
     138
     139        if( dndCount )
     140            tr_torrentInitFileDLs ( tor, dnd, dndCount, FALSE );
     141        if( dlCount )
     142            tr_torrentInitFileDLs ( tor, dl, dlCount, TRUE );
     143
     144        tr_free( dnd );
     145        tr_free( dl );
     146        ret = TR_FR_PRIORITY;
     147    }
     148
     149    return ret;
     150}
     151
     152/***
     153****
     154***/
     155
     156static void
     157savePriorities( tr_benc * dict, const tr_torrent * tor )
     158{
     159    const tr_info * inf = &tor->info;
     160    const tr_file_index_t n = inf->fileCount;
     161    tr_file_index_t i;
     162    tr_benc * list;
     163
     164    list = tr_bencDictAddList( dict, KEY_PRIORITY, n );
    111165    for( i=0; i<n; ++i )
    112166        tr_bencInitInt( tr_bencListAdd( list ), inf->files[i].priority );
     
    297351    savePeers( &top, tor );
    298352    savePriorities( &top, tor );
     353    saveDND( &top, tor );
    299354    saveProgress( &top, tor );
    300355    saveSpeedLimits( &top, tor );
     
    382437        fieldsLoaded |= loadProgress( &top, tor );
    383438
     439    if( fieldsToLoad & TR_FR_DND )
     440        fieldsLoaded |= loadDND( &top, tor );
     441
    384442    if( fieldsToLoad & TR_FR_SPEEDLIMIT )
    385443        fieldsLoaded |= loadSpeedLimits( &top, tor );
  • trunk/libtransmission/resume.h

    r5606 r5614  
    2121  TR_FR_PEERS        = (1<<3),
    2222  TR_FR_PROGRESS     = (1<<4),
    23   TR_FR_PRIORITY     = (1<<5),
    24   TR_FR_SPEEDLIMIT   = (1<<6),
    25   TR_FR_RUN          = (1<<7),
    26   TR_FR_DESTINATION  = (1<<8),
    27   TR_FR_MAX_PEERS    = (1<<9)
     23  TR_FR_DND          = (1<<5),
     24  TR_FR_PRIORITY     = (1<<6),
     25  TR_FR_SPEEDLIMIT   = (1<<7),
     26  TR_FR_RUN          = (1<<8),
     27  TR_FR_DESTINATION  = (1<<9),
     28  TR_FR_MAX_PEERS    = (1<<10)
    2829};
    2930
Note: See TracChangeset for help on using the changeset viewer.