Beispiel #1
0
static void
loadCumulativeStats( const tr_session * session,
                     tr_session_stats * setme )
{
    tr_benc top;
	char * path;
    char * filename;
    bool loaded = false;

    path = filename = getFilename( session );
#ifdef WIN32
	path = ConvertUtf8ToTChar(filename);
#endif
    loaded = !tr_bencLoadFile( &top, TR_FMT_JSON, path );
#ifdef WIN32
	tr_free(path);
#endif
    tr_free( filename );

    if( !loaded )
    {
        path = filename = getOldFilename( session );
#ifdef WIN32
		path = ConvertUtf8ToTChar(filename);
#endif
        loaded = !tr_bencLoadFile( &top, TR_FMT_BENC, path );
#ifdef WIN32
		tr_free(path);
#endif
        tr_free( filename );
    }

    if( loaded )
    {
        int64_t i;

        if( tr_bencDictFindInt( &top, "downloaded-bytes", &i ) )
            setme->downloadedBytes = (uint64_t) i;
        if( tr_bencDictFindInt( &top, "files-added", &i ) )
            setme->filesAdded = (uint64_t) i;
        if( tr_bencDictFindInt( &top, "seconds-active", &i ) )
            setme->secondsActive = (uint64_t) i;
        if( tr_bencDictFindInt( &top, "session-count", &i ) )
            setme->sessionCount = (uint64_t) i;
        if( tr_bencDictFindInt( &top, "uploaded-bytes", &i ) )
            setme->uploadedBytes = (uint64_t) i;

        tr_bencFree( &top );
    }
}
Beispiel #2
0
static void loadCumulativeStats(tr_session const* session, tr_session_stats* setme)
{
    tr_variant top;
    char* filename;
    bool loaded = false;

    filename = getFilename(session);
    loaded = tr_variantFromFile(&top, TR_VARIANT_FMT_JSON, filename, NULL);
    tr_free(filename);

    if (!loaded)
    {
        filename = getOldFilename(session);
        loaded = tr_variantFromFile(&top, TR_VARIANT_FMT_BENC, filename, NULL);
        tr_free(filename);
    }

    if (loaded)
    {
        int64_t i;

        if (tr_variantDictFindInt(&top, TR_KEY_downloaded_bytes, &i))
        {
            setme->downloadedBytes = (uint64_t)i;
        }

        if (tr_variantDictFindInt(&top, TR_KEY_files_added, &i))
        {
            setme->filesAdded = (uint64_t)i;
        }

        if (tr_variantDictFindInt(&top, TR_KEY_seconds_active, &i))
        {
            setme->secondsActive = (uint64_t)i;
        }

        if (tr_variantDictFindInt(&top, TR_KEY_session_count, &i))
        {
            setme->sessionCount = (uint64_t)i;
        }

        if (tr_variantDictFindInt(&top, TR_KEY_uploaded_bytes, &i))
        {
            setme->uploadedBytes = (uint64_t)i;
        }

        tr_variantFree(&top);
    }
}
Beispiel #3
0
static void
loadCumulativeStats( const tr_session * session,
                     tr_session_stats * setme )
{
    tr_benc top;
    char * filename;
    bool loaded = false;

    filename = getFilename( session );
    loaded = !tr_bencLoadFile( &top, TR_FMT_JSON, filename );
    tr_free( filename );

    if( !loaded )
    {
        filename = getOldFilename( session );
        loaded = !tr_bencLoadFile( &top, TR_FMT_BENC, filename );
        tr_free( filename );
    }

    if( loaded )
    {
        int64_t i;

        if( tr_bencDictFindInt( &top, "downloaded-bytes", &i ) )
            setme->downloadedBytes = (uint64_t) i;
        if( tr_bencDictFindInt( &top, "files-added", &i ) )
            setme->filesAdded = (uint64_t) i;
        if( tr_bencDictFindInt( &top, "seconds-active", &i ) )
            setme->secondsActive = (uint64_t) i;
        if( tr_bencDictFindInt( &top, "session-count", &i ) )
            setme->sessionCount = (uint64_t) i;
        if( tr_bencDictFindInt( &top, "uploaded-bytes", &i ) )
            setme->uploadedBytes = (uint64_t) i;

        tr_bencFree( &top );
    }
}