Changeset 8144


Ignore:
Timestamp:
Apr 5, 2009, 2:20:13 PM (13 years ago)
Author:
charles
Message:

(1.5x libT) backport the tr_sessionSaveSettings()-overwrites-client-benc bugfix to 1.5x

Location:
branches/1.5x/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/1.5x/libtransmission/session.c

    r8049 r8144  
    341341
    342342void
    343 tr_sessionSaveSettings( tr_session * session, const char * configDir, tr_benc * settings )
    344 {
    345     tr_benc fileSettings;
    346     char * filename;
    347 
    348     assert( tr_bencIsDict( settings ) );
    349  
    350     filename = tr_buildPath( configDir, "settings.json", NULL );
    351 
    352     tr_sessionGetSettings( session, settings );
    353 
    354     if( tr_bencLoadJSONFile( filename, &fileSettings ) ) {
    355         tr_bencSaveJSONFile( filename, settings );
    356     } else {
    357         tr_bencMergeDicts( &fileSettings, settings );
    358         tr_bencSaveJSONFile( filename, &fileSettings );
    359         tr_bencFree( &fileSettings );
    360     }
    361 
     343tr_sessionSaveSettings( tr_session    * session,
     344                        const char    * configDir,
     345                        const tr_benc * clientSettings )
     346{
     347    tr_benc settings;
     348    char * filename = tr_buildPath( configDir, "settings.json", NULL );
     349
     350    assert( tr_bencIsDict( clientSettings ) );
     351
     352    tr_bencInitDict( &settings, 0 );
     353
     354    /* the existing file settings are the fallback values */
     355    {
     356        tr_benc fileSettings;
     357        if( !tr_bencLoadJSONFile( filename, &fileSettings ) )
     358        {
     359            tr_bencMergeDicts( &settings, &fileSettings );
     360            tr_bencFree( &fileSettings );
     361        }
     362    }
     363
     364    /* the client's settings override the file settings */
     365    tr_bencMergeDicts( &settings, clientSettings );
     366
     367    /* the session's true values override the file & client settings */
     368    {
     369        tr_benc sessionSettings;
     370        tr_bencInitDict( &sessionSettings, 0 );
     371        tr_sessionGetSettings( session, &sessionSettings );
     372        tr_bencMergeDicts( &settings, &sessionSettings );
     373        tr_bencFree( &sessionSettings );
     374    }
     375
     376    /* save the result */
     377    tr_bencSaveJSONFile( filename, &settings );
    362378    tr_inf( "Saved \"%s\"", filename );
     379
     380    /* cleanup */
    363381    tr_free( filename );
     382    tr_bencFree( &settings );
    364383}
    365384
  • branches/1.5x/libtransmission/transmission.h

    r7931 r8144  
    250250 * @see tr_sessionLoadSettings()
    251251 */
    252 void tr_sessionSaveSettings( tr_session     * session,
    253                              const char     * configDir,
    254                              struct tr_benc * dictonary );
     252void tr_sessionSaveSettings( tr_session             * session,
     253                             const char             * configDir,
     254                             const struct tr_benc *  dictonary );
    255255
    256256/**
Note: See TracChangeset for help on using the changeset viewer.