mirror of
https://github.com/libretro/RetroArch
synced 2025-02-06 09:40:06 +00:00
Simple http request function to download badges.
This commit is contained in:
parent
8b9ad28ecb
commit
63090ae2e4
@ -1,9 +1,58 @@
|
||||
#include "badges.h"
|
||||
#include "../menu/menu_driver.h"
|
||||
#include <file/file_path.h>
|
||||
#include <streams/file_stream.h>
|
||||
|
||||
#include "../verbosity.h"
|
||||
#include "../network/net_http_special.h"
|
||||
|
||||
#include "badges.h"
|
||||
|
||||
badges_ctx_t badges_ctx;
|
||||
|
||||
bool download_badge(const char* filename)
|
||||
{
|
||||
char fullpath[PATH_MAX_LENGTH];
|
||||
|
||||
strcpy(fullpath, "badges/");
|
||||
strcat(fullpath, filename);
|
||||
|
||||
if(path_file_exists(fullpath))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t mysize = 1024 * 100;
|
||||
size_t *size;
|
||||
size = &mysize;
|
||||
|
||||
const char **buffer = malloc(sizeof(*buffer) * mysize);
|
||||
char url[PATH_MAX_LENGTH];
|
||||
strcpy(url, "http://i.retroachievements.org/Badge/");
|
||||
strcat(url, filename);
|
||||
|
||||
retro_time_t *timeout;
|
||||
retro_time_t timesecs = 10000000; //10 seconds
|
||||
timeout = ×ecs;
|
||||
|
||||
if(net_http_get(buffer, size, url, timeout) != NET_HTTP_GET_OK)
|
||||
{
|
||||
printf("[CHEEVOS]: Download to %s failed.\n", fullpath);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!filestream_write_file(fullpath, *buffer, *size))
|
||||
{
|
||||
printf("[CHEEVOS]: Write to %s failed.\n", fullpath);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("[CHEEVOS]: %s downloaded.\n", fullpath);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void set_badge_menu_texture(badges_ctx_t * badges, int i)
|
||||
{
|
||||
const char * locked_suffix = (badges->badge_locked[i] == true) ? "_lock.png" : ".png";
|
||||
|
@ -19,6 +19,7 @@ typedef struct
|
||||
void set_badge_menu_texture(badges_ctx_t * badges, int i);
|
||||
extern void set_badge_info (badges_ctx_t *badge_struct, int id, const char *badge_id, bool active);
|
||||
extern menu_texture_item get_badge_texture(int id);
|
||||
extern bool download_badge(const char* filename);
|
||||
|
||||
extern badges_ctx_t badges_ctx;
|
||||
|
||||
|
@ -2573,11 +2573,12 @@ static int cheevos_iterate(coro_t* coro)
|
||||
FILL_MD5 = -7,
|
||||
GET_GAMEID = -8,
|
||||
GET_CHEEVOS = -9,
|
||||
LOGIN = -10,
|
||||
HTTP_GET = -11,
|
||||
DEACTIVATE = -12,
|
||||
PLAYING = -13,
|
||||
DELAY = -14
|
||||
GET_BADGES = -10,
|
||||
LOGIN = -11,
|
||||
HTTP_GET = -12,
|
||||
DEACTIVATE = -13,
|
||||
PLAYING = -14,
|
||||
DELAY = -15
|
||||
};
|
||||
|
||||
static const uint32_t genesis_exts[] =
|
||||
@ -2817,6 +2818,7 @@ static int cheevos_iterate(coro_t* coro)
|
||||
|
||||
if ((void*)CHEEVOS_VAR_JSON)
|
||||
free((void*)CHEEVOS_VAR_JSON);
|
||||
|
||||
cheevos_loaded = true;
|
||||
|
||||
/*
|
||||
@ -3153,6 +3155,33 @@ static int cheevos_iterate(coro_t* coro)
|
||||
RARCH_LOG("[CHEEVOS]: got achievements for game id %u.\n", CHEEVOS_VAR_GAMEID);
|
||||
CORO_RET();
|
||||
|
||||
/**************************************************************************
|
||||
* Info Gets the achievements from Retro Achievements
|
||||
* Inputs CHEEVOS_VAR_GAMEID
|
||||
* Outputs CHEEVOS_VAR_JSON
|
||||
*************************************************************************/
|
||||
CORO_SUB(GET_BADGES)
|
||||
|
||||
char badge_filename[16];
|
||||
cheevo_t *cheevo = cheevos_locals.core.cheevos;
|
||||
const cheevo_t *end = cheevos_locals.core.cheevos +
|
||||
cheevos_locals.core.count;
|
||||
|
||||
for (unsigned i = 0; cheevo < end ; cheevo++)
|
||||
{
|
||||
strcpy(badge_filename, cheevo->badge);
|
||||
strcat(badge_filename, ".png");
|
||||
if (!download_badge(badge_filename))
|
||||
break;
|
||||
|
||||
strcpy(badge_filename, cheevo->badge);
|
||||
strcat(badge_filename, "_lock.png");
|
||||
if (!download_badge(badge_filename))
|
||||
break;
|
||||
}
|
||||
|
||||
CORO_RET();
|
||||
|
||||
/**************************************************************************
|
||||
* Info Logs in the user at Retro Achievements
|
||||
*************************************************************************/
|
||||
@ -3340,12 +3369,8 @@ static int cheevos_iterate(coro_t* coro)
|
||||
else
|
||||
RARCH_ERR("[CHEEVOS]: error deactivating unlocked achievements in softcore mode.\n");
|
||||
|
||||
<<<<<<< HEAD
|
||||
if ((void*)CHEEVOS_VAR_JSON)
|
||||
free((void*)CHEEVOS_VAR_JSON);
|
||||
=======
|
||||
free((void*)CHEEVOS_VAR_JSON);
|
||||
>>>>>>> Initial test for badge icon
|
||||
}
|
||||
else
|
||||
RARCH_ERR("[CHEEVOS]: error retrieving list of unlocked achievements in softcore mode.\n");
|
||||
@ -3373,12 +3398,8 @@ static int cheevos_iterate(coro_t* coro)
|
||||
else
|
||||
RARCH_ERR("[CHEEVOS]: error deactivating unlocked achievements in hardcore mode.\n");
|
||||
|
||||
<<<<<<< HEAD
|
||||
if ((void*)CHEEVOS_VAR_JSON)
|
||||
free((void*)CHEEVOS_VAR_JSON);
|
||||
=======
|
||||
free((void*)CHEEVOS_VAR_JSON);
|
||||
>>>>>>> Initial test for badge icon
|
||||
}
|
||||
else
|
||||
RARCH_ERR("[CHEEVOS]: error retrieving list of unlocked achievements in hardcore mode.\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user