mirror of
https://github.com/libretro/RetroArch
synced 2025-02-11 15:40:28 +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 <file/file_path.h>
|
||||||
#include "../menu/menu_driver.h"
|
#include <streams/file_stream.h>
|
||||||
|
|
||||||
#include "../verbosity.h"
|
#include "../verbosity.h"
|
||||||
|
#include "../network/net_http_special.h"
|
||||||
|
|
||||||
|
#include "badges.h"
|
||||||
|
|
||||||
badges_ctx_t badges_ctx;
|
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)
|
void set_badge_menu_texture(badges_ctx_t * badges, int i)
|
||||||
{
|
{
|
||||||
const char * locked_suffix = (badges->badge_locked[i] == true) ? "_lock.png" : ".png";
|
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);
|
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 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 menu_texture_item get_badge_texture(int id);
|
||||||
|
extern bool download_badge(const char* filename);
|
||||||
|
|
||||||
extern badges_ctx_t badges_ctx;
|
extern badges_ctx_t badges_ctx;
|
||||||
|
|
||||||
|
@ -2573,11 +2573,12 @@ static int cheevos_iterate(coro_t* coro)
|
|||||||
FILL_MD5 = -7,
|
FILL_MD5 = -7,
|
||||||
GET_GAMEID = -8,
|
GET_GAMEID = -8,
|
||||||
GET_CHEEVOS = -9,
|
GET_CHEEVOS = -9,
|
||||||
LOGIN = -10,
|
GET_BADGES = -10,
|
||||||
HTTP_GET = -11,
|
LOGIN = -11,
|
||||||
DEACTIVATE = -12,
|
HTTP_GET = -12,
|
||||||
PLAYING = -13,
|
DEACTIVATE = -13,
|
||||||
DELAY = -14
|
PLAYING = -14,
|
||||||
|
DELAY = -15
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint32_t genesis_exts[] =
|
static const uint32_t genesis_exts[] =
|
||||||
@ -2817,6 +2818,7 @@ static int cheevos_iterate(coro_t* coro)
|
|||||||
|
|
||||||
if ((void*)CHEEVOS_VAR_JSON)
|
if ((void*)CHEEVOS_VAR_JSON)
|
||||||
free((void*)CHEEVOS_VAR_JSON);
|
free((void*)CHEEVOS_VAR_JSON);
|
||||||
|
|
||||||
cheevos_loaded = true;
|
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);
|
RARCH_LOG("[CHEEVOS]: got achievements for game id %u.\n", CHEEVOS_VAR_GAMEID);
|
||||||
CORO_RET();
|
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
|
* Info Logs in the user at Retro Achievements
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
@ -3340,12 +3369,8 @@ static int cheevos_iterate(coro_t* coro)
|
|||||||
else
|
else
|
||||||
RARCH_ERR("[CHEEVOS]: error deactivating unlocked achievements in softcore mode.\n");
|
RARCH_ERR("[CHEEVOS]: error deactivating unlocked achievements in softcore mode.\n");
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
if ((void*)CHEEVOS_VAR_JSON)
|
if ((void*)CHEEVOS_VAR_JSON)
|
||||||
free((void*)CHEEVOS_VAR_JSON);
|
free((void*)CHEEVOS_VAR_JSON);
|
||||||
=======
|
|
||||||
free((void*)CHEEVOS_VAR_JSON);
|
|
||||||
>>>>>>> Initial test for badge icon
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
RARCH_ERR("[CHEEVOS]: error retrieving list of unlocked achievements in softcore mode.\n");
|
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
|
else
|
||||||
RARCH_ERR("[CHEEVOS]: error deactivating unlocked achievements in hardcore mode.\n");
|
RARCH_ERR("[CHEEVOS]: error deactivating unlocked achievements in hardcore mode.\n");
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
if ((void*)CHEEVOS_VAR_JSON)
|
if ((void*)CHEEVOS_VAR_JSON)
|
||||||
free((void*)CHEEVOS_VAR_JSON);
|
free((void*)CHEEVOS_VAR_JSON);
|
||||||
=======
|
|
||||||
free((void*)CHEEVOS_VAR_JSON);
|
|
||||||
>>>>>>> Initial test for badge icon
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
RARCH_ERR("[CHEEVOS]: error retrieving list of unlocked achievements in hardcore mode.\n");
|
RARCH_ERR("[CHEEVOS]: error retrieving list of unlocked achievements in hardcore mode.\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user