Cheevos badges
This commit is contained in:
parent
63090ae2e4
commit
cfe59bcf2a
|
@ -1,6 +1,7 @@
|
||||||
#include <file/file_path.h>
|
#include <file/file_path.h>
|
||||||
#include <streams/file_stream.h>
|
#include <streams/file_stream.h>
|
||||||
|
|
||||||
|
#include "../file_path_special.h"
|
||||||
#include "../verbosity.h"
|
#include "../verbosity.h"
|
||||||
#include "../network/net_http_special.h"
|
#include "../network/net_http_special.h"
|
||||||
|
|
||||||
|
@ -8,49 +9,12 @@
|
||||||
|
|
||||||
badges_ctx_t badges_ctx;
|
badges_ctx_t badges_ctx;
|
||||||
|
|
||||||
bool download_badge(const char* filename)
|
bool badge_exists(const char* filepath)
|
||||||
{
|
{
|
||||||
char fullpath[PATH_MAX_LENGTH];
|
if(path_file_exists(filepath))
|
||||||
|
|
||||||
strcpy(fullpath, "badges/");
|
|
||||||
strcat(fullpath, filename);
|
|
||||||
|
|
||||||
if(path_file_exists(fullpath))
|
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
return false;
|
||||||
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)
|
||||||
|
@ -63,8 +27,12 @@ void set_badge_menu_texture(badges_ctx_t * badges, int i)
|
||||||
snprintf(badge_file, bufferSize, "%s", badges->badge_id_list[i]);
|
snprintf(badge_file, bufferSize, "%s", badges->badge_id_list[i]);
|
||||||
strcat(badge_file, locked_suffix);
|
strcat(badge_file, locked_suffix);
|
||||||
|
|
||||||
// Badge directory should probably use a definition
|
char fullpath[PATH_MAX_LENGTH];
|
||||||
menu_display_reset_textures_list(badge_file, "badges", &badges->menu_texture_list[i],TEXTURE_FILTER_MIPMAP_LINEAR);
|
fill_pathname_application_special(fullpath,
|
||||||
|
PATH_MAX_LENGTH * sizeof(char),
|
||||||
|
APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_CHEEVOS_BADGES);
|
||||||
|
|
||||||
|
menu_display_reset_textures_list(badge_file, fullpath, &badges->menu_texture_list[i],TEXTURE_FILTER_MIPMAP_LINEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_badge_info (badges_ctx_t *badge_struct, int id, const char *badge_id, bool active)
|
void set_badge_info (badges_ctx_t *badge_struct, int id, const char *badge_id, bool active)
|
||||||
|
|
|
@ -16,10 +16,10 @@ typedef struct
|
||||||
menu_texture_item menu_texture_list[CHEEVOS_BADGE_LIMIT];
|
menu_texture_item menu_texture_list[CHEEVOS_BADGE_LIMIT];
|
||||||
} badges_ctx_t;
|
} badges_ctx_t;
|
||||||
|
|
||||||
|
bool badge_exists(const char* filepath);
|
||||||
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;
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include <file/file_path.h>
|
||||||
#include <formats/jsonsax.h>
|
#include <formats/jsonsax.h>
|
||||||
#include <streams/file_stream.h>
|
#include <streams/file_stream.h>
|
||||||
#include <features/features_cpu.h>
|
#include <features/features_cpu.h>
|
||||||
|
@ -40,6 +41,7 @@
|
||||||
#include "var.h"
|
#include "var.h"
|
||||||
#include "cond.h"
|
#include "cond.h"
|
||||||
|
|
||||||
|
#include "../file_path_special.h"
|
||||||
#include "../command.h"
|
#include "../command.h"
|
||||||
#include "../dynamic.h"
|
#include "../dynamic.h"
|
||||||
#include "../configuration.h"
|
#include "../configuration.h"
|
||||||
|
@ -77,6 +79,9 @@
|
||||||
* THE USER'S PASSWORD, TAKE CARE! */
|
* THE USER'S PASSWORD, TAKE CARE! */
|
||||||
#undef CHEEVOS_LOG_PASSWORD
|
#undef CHEEVOS_LOG_PASSWORD
|
||||||
|
|
||||||
|
/* Define this macro to log downloaded badge images. */
|
||||||
|
#undef CHEEVOS_LOG_BADGES
|
||||||
|
|
||||||
/* C89 wants only int values in enums. */
|
/* C89 wants only int values in enums. */
|
||||||
#define CHEEVOS_JSON_KEY_GAMEID 0xb4960eecU
|
#define CHEEVOS_JSON_KEY_GAMEID 0xb4960eecU
|
||||||
#define CHEEVOS_JSON_KEY_ACHIEVEMENTS 0x69749ae1U
|
#define CHEEVOS_JSON_KEY_ACHIEVEMENTS 0x69749ae1U
|
||||||
|
@ -2856,6 +2861,8 @@ static int cheevos_iterate(coro_t* coro)
|
||||||
runloop_msg_queue_push(msg, 0, 6 * 60, false);
|
runloop_msg_queue_push(msg, 0, 6 * 60, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CORO_GOSUB(GET_BADGES);
|
||||||
|
|
||||||
CORO_STOP();
|
CORO_STOP();
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
|
@ -3163,24 +3170,54 @@ static int cheevos_iterate(coro_t* coro)
|
||||||
CORO_SUB(GET_BADGES)
|
CORO_SUB(GET_BADGES)
|
||||||
|
|
||||||
char badge_filename[16];
|
char badge_filename[16];
|
||||||
|
char fullpath[PATH_MAX_LENGTH];
|
||||||
|
FILE* file;
|
||||||
cheevo_t *cheevo = cheevos_locals.core.cheevos;
|
cheevo_t *cheevo = cheevos_locals.core.cheevos;
|
||||||
const cheevo_t *end = cheevos_locals.core.cheevos +
|
const cheevo_t *end = cheevos_locals.core.cheevos +
|
||||||
cheevos_locals.core.count;
|
cheevos_locals.core.count;
|
||||||
|
|
||||||
for (unsigned i = 0; cheevo < end ; cheevo++)
|
for (unsigned i = 0; cheevo < end ; cheevo++)
|
||||||
{
|
{
|
||||||
strcpy(badge_filename, cheevo->badge);
|
for (unsigned j = 0; j < 2; j++)
|
||||||
strcat(badge_filename, ".png");
|
{
|
||||||
if (!download_badge(badge_filename))
|
strcpy(badge_filename, cheevo->badge);
|
||||||
break;
|
if (j == 0) strcat(badge_filename, ".png");
|
||||||
|
else strcat(badge_filename, "_lock.png");
|
||||||
|
|
||||||
strcpy(badge_filename, cheevo->badge);
|
fill_pathname_application_special(fullpath,
|
||||||
strcat(badge_filename, "_lock.png");
|
PATH_MAX_LENGTH * sizeof(char),
|
||||||
if (!download_badge(badge_filename))
|
APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_CHEEVOS_BADGES);
|
||||||
break;
|
|
||||||
|
if (!path_is_directory(fullpath))
|
||||||
|
path_mkdir(fullpath);
|
||||||
|
|
||||||
|
strcat(fullpath, badge_filename);
|
||||||
|
|
||||||
|
if (!badge_exists(fullpath))
|
||||||
|
{
|
||||||
|
snprintf(
|
||||||
|
CHEEVOS_VAR_URL, sizeof(CHEEVOS_VAR_URL),
|
||||||
|
"http://i.retroachievements.org/Badge/%s",
|
||||||
|
badge_filename
|
||||||
|
);
|
||||||
|
|
||||||
|
CORO_GOSUB(HTTP_GET);
|
||||||
|
|
||||||
|
if (CHEEVOS_VAR_K > 5)
|
||||||
|
{
|
||||||
|
file = fopen (fullpath, "wb");
|
||||||
|
fwrite(CHEEVOS_VAR_JSON, 1, CHEEVOS_VAR_K, file);
|
||||||
|
fclose(file);
|
||||||
|
#ifdef CHEEVOS_LOG_BADGES
|
||||||
|
RARCH_LOG("[CHEEVOS]: downloaded badge %s.\n", badge_filename);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CORO_RET();
|
CORO_RET();
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Info Logs in the user at Retro Achievements
|
* Info Logs in the user at Retro Achievements
|
||||||
|
@ -3323,6 +3360,7 @@ static int cheevos_iterate(coro_t* coro)
|
||||||
CHEEVOS_VAR_JSON[length] = 0;
|
CHEEVOS_VAR_JSON[length] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CHEEVOS_VAR_K = length;
|
||||||
net_http_delete(CHEEVOS_VAR_HTTP);
|
net_http_delete(CHEEVOS_VAR_HTTP);
|
||||||
net_http_connection_free(CHEEVOS_VAR_CONN);
|
net_http_connection_free(CHEEVOS_VAR_CONN);
|
||||||
CORO_RET();
|
CORO_RET();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* RetroArch - A frontend for libretro.
|
/* RetroArch - A frontend for libretro.
|
||||||
* Copyright (C) 2011-2017 - Daniel De Matteis
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
||||||
*
|
*
|
||||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||||
* of the GNU General Public License as published by the Free Software Found-
|
* of the GNU General Public License as published by the Free Software Found-
|
||||||
* ation, either version 3 of the License, or (at your option) any later version.
|
* ation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
@ -119,7 +119,7 @@ void fill_pathname_abbreviate_special(char *out_path,
|
||||||
* Keep application dir in front of home, moving app dir to a
|
* Keep application dir in front of home, moving app dir to a
|
||||||
* new location inside home would break otherwise. */
|
* new location inside home would break otherwise. */
|
||||||
|
|
||||||
/* ugly hack - use application_dir pointer
|
/* ugly hack - use application_dir pointer
|
||||||
* before filling it in. C89 reasons */
|
* before filling it in. C89 reasons */
|
||||||
candidates[0] = application_dir;
|
candidates[0] = application_dir;
|
||||||
candidates[1] = home;
|
candidates[1] = home;
|
||||||
|
@ -129,23 +129,23 @@ void fill_pathname_abbreviate_special(char *out_path,
|
||||||
notations [1] = "~";
|
notations [1] = "~";
|
||||||
notations [2] = NULL;
|
notations [2] = NULL;
|
||||||
|
|
||||||
fill_pathname_application_path(application_dir,
|
fill_pathname_application_path(application_dir,
|
||||||
PATH_MAX_LENGTH * sizeof(char));
|
PATH_MAX_LENGTH * sizeof(char));
|
||||||
path_basedir_wrapper(application_dir);
|
path_basedir_wrapper(application_dir);
|
||||||
|
|
||||||
for (i = 0; candidates[i]; i++)
|
for (i = 0; candidates[i]; i++)
|
||||||
{
|
{
|
||||||
if (!string_is_empty(candidates[i]) &&
|
if (!string_is_empty(candidates[i]) &&
|
||||||
strstr(in_path, candidates[i]) == in_path)
|
strstr(in_path, candidates[i]) == in_path)
|
||||||
{
|
{
|
||||||
size_t src_size = strlcpy(out_path, notations[i], size);
|
size_t src_size = strlcpy(out_path, notations[i], size);
|
||||||
|
|
||||||
retro_assert(src_size < size);
|
retro_assert(src_size < size);
|
||||||
|
|
||||||
out_path += src_size;
|
out_path += src_size;
|
||||||
size -= src_size;
|
size -= src_size;
|
||||||
in_path += strlen(candidates[i]);
|
in_path += strlen(candidates[i]);
|
||||||
|
|
||||||
if (!path_char_is_slash(*in_path))
|
if (!path_char_is_slash(*in_path))
|
||||||
{
|
{
|
||||||
retro_assert(strlcpy(out_path,
|
retro_assert(strlcpy(out_path,
|
||||||
|
@ -242,7 +242,7 @@ void fill_pathname_application_path(char *s, size_t len)
|
||||||
CFStringGetCString(bundle_path, s, len, kCFStringEncodingUTF8);
|
CFStringGetCString(bundle_path, s, len, kCFStringEncodingUTF8);
|
||||||
CFRelease(bundle_path);
|
CFRelease(bundle_path);
|
||||||
CFRelease(bundle_url);
|
CFRelease(bundle_url);
|
||||||
|
|
||||||
retro_assert(strlcat(s, "nobin", len) < len);
|
retro_assert(strlcat(s, "nobin", len) < len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -269,7 +269,7 @@ void fill_pathname_application_path(char *s, size_t len)
|
||||||
char link_path[255];
|
char link_path[255];
|
||||||
|
|
||||||
link_path[0] = *s = '\0';
|
link_path[0] = *s = '\0';
|
||||||
pid = getpid();
|
pid = getpid();
|
||||||
|
|
||||||
/* Linux, BSD and Solaris paths. Not standardized. */
|
/* Linux, BSD and Solaris paths. Not standardized. */
|
||||||
for (i = 0; i < ARRAY_SIZE(exts); i++)
|
for (i = 0; i < ARRAY_SIZE(exts); i++)
|
||||||
|
@ -287,7 +287,7 @@ void fill_pathname_application_path(char *s, size_t len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RARCH_ERR("Cannot resolve application path! This should not happen.\n");
|
RARCH_ERR("Cannot resolve application path! This should not happen.\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -335,7 +335,7 @@ void fill_pathname_application_special(char *s,
|
||||||
char *s1 = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
char *s1 = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||||
s1[0] = '\0';
|
s1[0] = '\0';
|
||||||
|
|
||||||
fill_pathname_application_special(s1,
|
fill_pathname_application_special(s1,
|
||||||
PATH_MAX_LENGTH * sizeof(char),
|
PATH_MAX_LENGTH * sizeof(char),
|
||||||
APPLICATION_SPECIAL_DIRECTORY_ASSETS_ZARCH);
|
APPLICATION_SPECIAL_DIRECTORY_ASSETS_ZARCH);
|
||||||
fill_pathname_join(s,
|
fill_pathname_join(s,
|
||||||
|
@ -349,7 +349,7 @@ void fill_pathname_application_special(char *s,
|
||||||
#ifdef HAVE_ZARCH
|
#ifdef HAVE_ZARCH
|
||||||
{
|
{
|
||||||
settings_t *settings = config_get_ptr();
|
settings_t *settings = config_get_ptr();
|
||||||
fill_pathname_join(s,
|
fill_pathname_join(s,
|
||||||
settings->paths.directory_assets,
|
settings->paths.directory_assets,
|
||||||
"zarch",
|
"zarch",
|
||||||
len);
|
len);
|
||||||
|
@ -501,6 +501,31 @@ void fill_pathname_application_special(char *s,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
case APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_CHEEVOS_BADGES:
|
||||||
|
{
|
||||||
|
char *s1 = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||||
|
char *s2 = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||||
|
settings_t *settings = config_get_ptr();
|
||||||
|
|
||||||
|
s1[0] = s2[0] = '\0';
|
||||||
|
|
||||||
|
fill_pathname_join(s1,
|
||||||
|
settings->paths.directory_thumbnails,
|
||||||
|
"cheevos",
|
||||||
|
len);
|
||||||
|
fill_pathname_join(s2,
|
||||||
|
s1, "badges",
|
||||||
|
PATH_MAX_LENGTH * sizeof(char)
|
||||||
|
);
|
||||||
|
fill_pathname_slash(s2,
|
||||||
|
PATH_MAX_LENGTH * sizeof(char)
|
||||||
|
);
|
||||||
|
strlcpy(s, s2, len);
|
||||||
|
free(s1);
|
||||||
|
free(s2);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case APPLICATION_SPECIAL_NONE:
|
case APPLICATION_SPECIAL_NONE:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* RetroArch - A frontend for libretro.
|
/* RetroArch - A frontend for libretro.
|
||||||
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
||||||
* Copyright (C) 2011-2016 - Daniel De Matteis
|
* Copyright (C) 2011-2016 - Daniel De Matteis
|
||||||
*
|
*
|
||||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||||
* of the GNU General Public License as published by the Free Software Found-
|
* of the GNU General Public License as published by the Free Software Found-
|
||||||
* ation, either version 3 of the License, or (at your option) any later version.
|
* ation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
@ -104,7 +104,8 @@ enum application_special_type
|
||||||
APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_FONT,
|
APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_FONT,
|
||||||
APPLICATION_SPECIAL_DIRECTORY_ASSETS_ZARCH,
|
APPLICATION_SPECIAL_DIRECTORY_ASSETS_ZARCH,
|
||||||
APPLICATION_SPECIAL_DIRECTORY_ASSETS_ZARCH_FONT,
|
APPLICATION_SPECIAL_DIRECTORY_ASSETS_ZARCH_FONT,
|
||||||
APPLICATION_SPECIAL_DIRECTORY_ASSETS_ZARCH_ICONS
|
APPLICATION_SPECIAL_DIRECTORY_ASSETS_ZARCH_ICONS,
|
||||||
|
APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_CHEEVOS_BADGES
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2245,9 +2245,11 @@ static uintptr_t xmb_icon_get_id(xmb_handle_t *xmb,
|
||||||
if ((type >= MENU_SETTINGS_CHEEVOS_START) &&
|
if ((type >= MENU_SETTINGS_CHEEVOS_START) &&
|
||||||
(type < MENU_SETTINGS_NETPLAY_ROOMS_START))
|
(type < MENU_SETTINGS_NETPLAY_ROOMS_START))
|
||||||
{
|
{
|
||||||
//return badges_ctx.menu_texture_list[type - MENU_SETTINGS_CHEEVOS_START];
|
|
||||||
int new_id = type - MENU_SETTINGS_CHEEVOS_START;
|
int new_id = type - MENU_SETTINGS_CHEEVOS_START;
|
||||||
return get_badge_texture( new_id );
|
if ( get_badge_texture(new_id) != 0 )
|
||||||
|
return get_badge_texture( new_id );
|
||||||
|
else
|
||||||
|
return xmb->textures.list[XMB_TEXTURE_SUBSETTING]; // Should be replaced with placeholder badge icon.
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue