From 7456f2d03230fcbfce370f79e68f450c703744a8 Mon Sep 17 00:00:00 2001 From: Andre Leiradella Date: Fri, 16 Oct 2015 22:51:09 -0300 Subject: [PATCH] even better error handling --- cheevos.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/cheevos.c b/cheevos.c index 81fc9807a6..d9c95ccd44 100644 --- a/cheevos.c +++ b/cheevos.c @@ -560,7 +560,7 @@ static int new_cheevo( cheevos_readud_t* ud ) cheevo->badge = dupstr( &ud->badge ); cheevo->points = strtol( ud->points.string, NULL, 10 ); cheevo->dirty = 0; - cheevo->active = flags == 3; + cheevo->active = 1; /* flags == 3; */ cheevo->modified = 0; if ( !cheevo->title || !cheevo->description || !cheevo->author || !cheevo->badge ) @@ -1328,9 +1328,10 @@ static int cheevos_login( void ) return 0; } } + + RARCH_LOG( "CHEEVOS error getting user token\n" ); } - RARCH_LOG( "CHEEVOS error getting user token\n" ); return -1; } @@ -1338,24 +1339,26 @@ int cheevos_get_by_game_id( const char** json, unsigned game_id ) { char request[ 256 ]; - cheevos_login(); - - snprintf( - request, sizeof( request ), - "http://retroachievements.org/dorequest.php?r=patch&u=%s&g=%u&f=3&l=1&t=%s", - config_get_ptr()->cheevos.user_name, game_id, token - ); - - request[ sizeof( request ) - 1 ] = 0; - *json = cheevos_http_get( request, NULL ); - - if ( *json ) + if ( !cheevos_login() ) { - RARCH_LOG( "CHEEVOS got achievements for game id %u\n", game_id ); - return 0; + snprintf( + request, sizeof( request ), + "http://retroachievements.org/dorequest.php?r=patch&u=%s&g=%u&f=3&l=1&t=%s", + config_get_ptr()->cheevos.user_name, game_id, token + ); + + request[ sizeof( request ) - 1 ] = 0; + *json = cheevos_http_get( request, NULL ); + + if ( *json ) + { + RARCH_LOG( "CHEEVOS got achievements for game id %u\n", game_id ); + return 0; + } + + RARCH_LOG( "CHEEVOS error getting achievements for game id %u\n", game_id ); } - RARCH_LOG( "CHEEVOS error getting achievements for game id %u\n", game_id ); return -1; } @@ -1439,5 +1442,5 @@ int cheevos_get_by_content( const char** json, const void* data, size_t size ) game_id = cheevos_get_game_id( hash ); } - return cheevos_get_by_game_id( json, game_id ); + return game_id ? cheevos_get_by_game_id( json, game_id ) : -1; }