From 84e80e47df768fc4d8c393d2fec467bce29e39e3 Mon Sep 17 00:00:00 2001 From: GameDragon2k Date: Fri, 20 Oct 2017 20:26:13 -0400 Subject: [PATCH 01/16] Initial test for badge icon --- cheevos/cheevos.c | 12 ++++++++++-- menu/drivers/xmb.c | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index 9ad63a365c..0ed68488ae 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -2157,14 +2157,14 @@ void cheevos_populate_menu(void *data, bool hardcore) { menu_entries_append_enum(info->list, cheevo->title, cheevo->description, MENU_ENUM_LABEL_CHEEVOS_UNLOCKED_ENTRY, - MENU_SETTINGS_CHEEVOS_START + i, 0, 0); + MENU_SETTINGS_CHEEVOS_START + i, 0, atoi(cheevo->badge)); items_found++; } else { menu_entries_append_enum(info->list, cheevo->title, cheevo->description, MENU_ENUM_LABEL_CHEEVOS_LOCKED_ENTRY, - MENU_SETTINGS_CHEEVOS_START + i, 0, 0); + MENU_SETTINGS_CHEEVOS_START + i, 0, atoi(cheevo->badge)); items_found++; } } @@ -3337,8 +3337,12 @@ 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"); @@ -3366,8 +3370,12 @@ 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"); diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index c1d5dac42e..49df1ce1c8 100755 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -252,6 +252,15 @@ typedef struct xmb_handle menu_texture_item list[XMB_TEXTURE_LAST]; } textures; +#ifdef HAVE_CHEEVOS + struct + { + size_t current_badge; + menu_texture_item test; + menu_texture_item list[XMB_TEXTURE_LAST]; + } badges; +#endif + xmb_node_t main_menu_node; #ifdef HAVE_IMAGEVIEWER xmb_node_t images_tab_node; @@ -2239,6 +2248,20 @@ static uintptr_t xmb_icon_get_id(xmb_handle_t *xmb, #endif } +#ifdef HAVE_CHEEVOS + if ((type >= MENU_SETTINGS_CHEEVOS_START) && + (type < MENU_SETTINGS_NETPLAY_ROOMS_START)) + { + unsigned new_id = type - MENU_SETTINGS_CHEEVOS_START; + int bufferSize = 16; + char new_str[bufferSize]; + snprintf(new_str, bufferSize, "%05d", (int)xmb->badges.current_badge); + strcat(new_str, ".png"); + menu_display_reset_textures_list(new_str, "badges", &xmb->badges.list[new_id], TEXTURE_FILTER_MIPMAP_LINEAR); + return xmb->badges.list[new_id]; + } +#endif + return xmb->textures.list[XMB_TEXTURE_SUBSETTING]; } @@ -2466,6 +2489,10 @@ static int xmb_draw_item( if (color[3] != 0) { +#ifdef HAVE_CHEEVOS + xmb->badges.current_badge = entry->entry_idx; +#endif + math_matrix_4x4 mymat_tmp; menu_display_ctx_rotate_draw_t rotate_draw; uintptr_t texture = xmb_icon_get_id(xmb, core_node, node, From ec2808685d848199b01bffa9d58ff460dec159b8 Mon Sep 17 00:00:00 2001 From: GameDragon2k Date: Sat, 21 Oct 2017 17:46:13 -0400 Subject: [PATCH 02/16] Add files to handle all cheevos badges. --- Makefile.common | 4 ++++ cheevos/badges.c | 31 +++++++++++++++++++++++++++++++ cheevos/badges.h | 27 +++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 cheevos/badges.c create mode 100644 cheevos/badges.h diff --git a/Makefile.common b/Makefile.common index 95012320df..737820a16c 100644 --- a/Makefile.common +++ b/Makefile.common @@ -1474,8 +1474,12 @@ ifeq ($(HAVE_NETWORKING), 1) ifeq ($(HAVE_CHEEVOS), 1) DEFINES += -DHAVE_CHEEVOS OBJ += cheevos/cheevos.o \ +<<<<<<< HEAD cheevos/var.o \ cheevos/cond.o \ +======= + cheevos/badges.o \ +>>>>>>> Add files to handle all cheevos badges. $(LIBRETRO_COMM_DIR)/utils/md5.o endif diff --git a/cheevos/badges.c b/cheevos/badges.c new file mode 100644 index 0000000000..4dca01fef6 --- /dev/null +++ b/cheevos/badges.c @@ -0,0 +1,31 @@ +#include "badges.h" +#include "../menu/menu_driver.h" +#include "../verbosity.h" + +badges_ctx_t badges_ctx; + +void set_badge_menu_texture(badges_ctx_t * badges, int i) +{ + const char * locked_suffix = (badges->badge_locked[i] == true) ? "_lock.png" : ".png"; + + unsigned int bufferSize = 16; + char badge_file[bufferSize]; + + snprintf(badge_file, bufferSize, "%s", badges->badge_id_list[i]); + strcat(badge_file, locked_suffix); + + // Badge directory should probably use a definition + menu_display_reset_textures_list(badge_file, "badges", &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) +{ + badge_struct->badge_id_list[id] = badge_id; + badge_struct->badge_locked[id] = active; + set_badge_menu_texture(badge_struct, id); +} + +menu_texture_item get_badge_texture (int id) +{ + return badges_ctx.menu_texture_list[id]; +} diff --git a/cheevos/badges.h b/cheevos/badges.h new file mode 100644 index 0000000000..b5b9011122 --- /dev/null +++ b/cheevos/badges.h @@ -0,0 +1,27 @@ +#ifndef __RARCH_BADGE_H +#define __RARCH_BADGE_H + +#include "../menu/menu_driver.h" + +#include + +RETRO_BEGIN_DECLS + +#define CHEEVOS_BADGE_LIMIT 256 + +typedef struct +{ + bool badge_locked[CHEEVOS_BADGE_LIMIT]; + const char * badge_id_list[CHEEVOS_BADGE_LIMIT]; + menu_texture_item menu_texture_list[CHEEVOS_BADGE_LIMIT]; +} badges_ctx_t; + +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 badges_ctx_t badges_ctx; + +RETRO_END_DECLS + +#endif From 8b9ad28ecbe5f7bf0105123ec14013b1813f0c81 Mon Sep 17 00:00:00 2001 From: GameDragon2k Date: Sat, 21 Oct 2017 17:48:26 -0400 Subject: [PATCH 03/16] channges to populate and apply badges. --- cheevos/cheevos.c | 7 +++++-- menu/drivers/xmb.c | 25 +++++-------------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index 0ed68488ae..bce5770895 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -35,6 +35,7 @@ #include "../menu/menu_entries.h" #endif +#include "badges.h" #include "cheevos.h" #include "var.h" #include "cond.h" @@ -2157,16 +2158,17 @@ void cheevos_populate_menu(void *data, bool hardcore) { menu_entries_append_enum(info->list, cheevo->title, cheevo->description, MENU_ENUM_LABEL_CHEEVOS_UNLOCKED_ENTRY, - MENU_SETTINGS_CHEEVOS_START + i, 0, atoi(cheevo->badge)); + MENU_SETTINGS_CHEEVOS_START + i, 0, 0); items_found++; } else { menu_entries_append_enum(info->list, cheevo->title, cheevo->description, MENU_ENUM_LABEL_CHEEVOS_LOCKED_ENTRY, - MENU_SETTINGS_CHEEVOS_START + i, 0, atoi(cheevo->badge)); + MENU_SETTINGS_CHEEVOS_START + i, 0, 0); items_found++; } + set_badge_info(&badges_ctx, i, cheevo->badge, (cheevo->active & CHEEVOS_ACTIVE_SOFTCORE)); } else { @@ -2184,6 +2186,7 @@ void cheevos_populate_menu(void *data, bool hardcore) MENU_SETTINGS_CHEEVOS_START + i, 0, 0); items_found++; } + set_badge_info(&badges_ctx, i, cheevo->badge, (cheevo->active & CHEEVOS_ACTIVE_HARDCORE)); } } diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 49df1ce1c8..c5bc6a2c47 100755 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -61,6 +61,8 @@ #include "../../tasks/tasks_internal.h" +#include "../../cheevos/badges.h" + #define XMB_RIBBON_ROWS 64 #define XMB_RIBBON_COLS 64 #define XMB_RIBBON_VERTICES 2*XMB_RIBBON_COLS*XMB_RIBBON_ROWS-2*XMB_RIBBON_COLS @@ -252,15 +254,6 @@ typedef struct xmb_handle menu_texture_item list[XMB_TEXTURE_LAST]; } textures; -#ifdef HAVE_CHEEVOS - struct - { - size_t current_badge; - menu_texture_item test; - menu_texture_item list[XMB_TEXTURE_LAST]; - } badges; -#endif - xmb_node_t main_menu_node; #ifdef HAVE_IMAGEVIEWER xmb_node_t images_tab_node; @@ -2252,13 +2245,9 @@ static uintptr_t xmb_icon_get_id(xmb_handle_t *xmb, if ((type >= MENU_SETTINGS_CHEEVOS_START) && (type < MENU_SETTINGS_NETPLAY_ROOMS_START)) { - unsigned new_id = type - MENU_SETTINGS_CHEEVOS_START; - int bufferSize = 16; - char new_str[bufferSize]; - snprintf(new_str, bufferSize, "%05d", (int)xmb->badges.current_badge); - strcat(new_str, ".png"); - menu_display_reset_textures_list(new_str, "badges", &xmb->badges.list[new_id], TEXTURE_FILTER_MIPMAP_LINEAR); - return xmb->badges.list[new_id]; + //return badges_ctx.menu_texture_list[type - MENU_SETTINGS_CHEEVOS_START]; + int new_id = type - MENU_SETTINGS_CHEEVOS_START; + return get_badge_texture( new_id ); } #endif @@ -2489,10 +2478,6 @@ static int xmb_draw_item( if (color[3] != 0) { -#ifdef HAVE_CHEEVOS - xmb->badges.current_badge = entry->entry_idx; -#endif - math_matrix_4x4 mymat_tmp; menu_display_ctx_rotate_draw_t rotate_draw; uintptr_t texture = xmb_icon_get_id(xmb, core_node, node, From 63090ae2e485ba8b5e4b2217c043dbc04df661fb Mon Sep 17 00:00:00 2001 From: GameDragon2k Date: Sun, 22 Oct 2017 13:02:16 -0400 Subject: [PATCH 04/16] Simple http request function to download badges. --- cheevos/badges.c | 53 +++++++++++++++++++++++++++++++++++++++++++++-- cheevos/badges.h | 1 + cheevos/cheevos.c | 47 +++++++++++++++++++++++++++++------------ 3 files changed, 86 insertions(+), 15 deletions(-) diff --git a/cheevos/badges.c b/cheevos/badges.c index 4dca01fef6..d143084660 100644 --- a/cheevos/badges.c +++ b/cheevos/badges.c @@ -1,9 +1,58 @@ -#include "badges.h" -#include "../menu/menu_driver.h" +#include +#include + #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"; diff --git a/cheevos/badges.h b/cheevos/badges.h index b5b9011122..da0e4d6787 100644 --- a/cheevos/badges.h +++ b/cheevos/badges.h @@ -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; diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index bce5770895..4edf5e87f7 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -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"); From cfe59bcf2a6787d1e951eab79e32b4e39a39a02c Mon Sep 17 00:00:00 2001 From: GameDragon2k Date: Thu, 23 Nov 2017 06:58:19 -0500 Subject: [PATCH 05/16] Cheevos badges --- cheevos/badges.c | 52 ++++++++--------------------------------- cheevos/badges.h | 2 +- cheevos/cheevos.c | 56 +++++++++++++++++++++++++++++++++++++-------- file_path_special.c | 49 +++++++++++++++++++++++++++++---------- file_path_special.h | 5 ++-- menu/drivers/xmb.c | 6 +++-- 6 files changed, 102 insertions(+), 68 deletions(-) diff --git a/cheevos/badges.c b/cheevos/badges.c index d143084660..922a1de22e 100644 --- a/cheevos/badges.c +++ b/cheevos/badges.c @@ -1,6 +1,7 @@ #include #include +#include "../file_path_special.h" #include "../verbosity.h" #include "../network/net_http_special.h" @@ -8,49 +9,12 @@ badges_ctx_t badges_ctx; -bool download_badge(const char* filename) +bool badge_exists(const char* filepath) { - char fullpath[PATH_MAX_LENGTH]; - - strcpy(fullpath, "badges/"); - strcat(fullpath, filename); - - if(path_file_exists(fullpath)) - { + if(path_file_exists(filepath)) 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; - } - } + return false; } 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]); strcat(badge_file, locked_suffix); - // Badge directory should probably use a definition - menu_display_reset_textures_list(badge_file, "badges", &badges->menu_texture_list[i],TEXTURE_FILTER_MIPMAP_LINEAR); + char fullpath[PATH_MAX_LENGTH]; + 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) diff --git a/cheevos/badges.h b/cheevos/badges.h index da0e4d6787..863aa34e1a 100644 --- a/cheevos/badges.h +++ b/cheevos/badges.h @@ -16,10 +16,10 @@ typedef struct menu_texture_item menu_texture_list[CHEEVOS_BADGE_LIMIT]; } badges_ctx_t; +bool badge_exists(const char* filepath); 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; diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index 4edf5e87f7..1c5f57058d 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -40,6 +41,7 @@ #include "var.h" #include "cond.h" +#include "../file_path_special.h" #include "../command.h" #include "../dynamic.h" #include "../configuration.h" @@ -77,6 +79,9 @@ * THE USER'S PASSWORD, TAKE CARE! */ #undef CHEEVOS_LOG_PASSWORD +/* Define this macro to log downloaded badge images. */ +#undef CHEEVOS_LOG_BADGES + /* C89 wants only int values in enums. */ #define CHEEVOS_JSON_KEY_GAMEID 0xb4960eecU #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); } + CORO_GOSUB(GET_BADGES); + CORO_STOP(); /************************************************************************** @@ -3163,24 +3170,54 @@ static int cheevos_iterate(coro_t* coro) CORO_SUB(GET_BADGES) char badge_filename[16]; + char fullpath[PATH_MAX_LENGTH]; + FILE* file; 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; + for (unsigned j = 0; j < 2; j++) + { + strcpy(badge_filename, cheevo->badge); + if (j == 0) strcat(badge_filename, ".png"); + else strcat(badge_filename, "_lock.png"); - strcpy(badge_filename, cheevo->badge); - strcat(badge_filename, "_lock.png"); - if (!download_badge(badge_filename)) - break; + fill_pathname_application_special(fullpath, + PATH_MAX_LENGTH * sizeof(char), + APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_CHEEVOS_BADGES); + + 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 @@ -3323,6 +3360,7 @@ static int cheevos_iterate(coro_t* coro) CHEEVOS_VAR_JSON[length] = 0; } + CHEEVOS_VAR_K = length; net_http_delete(CHEEVOS_VAR_HTTP); net_http_connection_free(CHEEVOS_VAR_CONN); CORO_RET(); diff --git a/file_path_special.c b/file_path_special.c index 3d5231a63f..b6ac69470e 100644 --- a/file_path_special.c +++ b/file_path_special.c @@ -1,6 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2011-2017 - Daniel De Matteis - * + * * 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- * 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 * 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 */ candidates[0] = application_dir; candidates[1] = home; @@ -129,23 +129,23 @@ void fill_pathname_abbreviate_special(char *out_path, notations [1] = "~"; notations [2] = NULL; - fill_pathname_application_path(application_dir, + fill_pathname_application_path(application_dir, PATH_MAX_LENGTH * sizeof(char)); path_basedir_wrapper(application_dir); - + 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) { size_t src_size = strlcpy(out_path, notations[i], size); retro_assert(src_size < size); - + out_path += src_size; size -= src_size; in_path += strlen(candidates[i]); - + if (!path_char_is_slash(*in_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); CFRelease(bundle_path); CFRelease(bundle_url); - + retro_assert(strlcat(s, "nobin", len) < len); return; } @@ -269,7 +269,7 @@ void fill_pathname_application_path(char *s, size_t len) char link_path[255]; link_path[0] = *s = '\0'; - pid = getpid(); + pid = getpid(); /* Linux, BSD and Solaris paths. Not standardized. */ 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"); #endif } @@ -335,7 +335,7 @@ void fill_pathname_application_special(char *s, char *s1 = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); s1[0] = '\0'; - fill_pathname_application_special(s1, + fill_pathname_application_special(s1, PATH_MAX_LENGTH * sizeof(char), APPLICATION_SPECIAL_DIRECTORY_ASSETS_ZARCH); fill_pathname_join(s, @@ -349,7 +349,7 @@ void fill_pathname_application_special(char *s, #ifdef HAVE_ZARCH { settings_t *settings = config_get_ptr(); - fill_pathname_join(s, + fill_pathname_join(s, settings->paths.directory_assets, "zarch", len); @@ -501,6 +501,31 @@ void fill_pathname_application_special(char *s, } #endif 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: default: break; diff --git a/file_path_special.h b/file_path_special.h index e763f78a7f..4d959e1899 100644 --- a/file_path_special.h +++ b/file_path_special.h @@ -1,7 +1,7 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen * Copyright (C) 2011-2016 - Daniel De Matteis - * + * * 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- * 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_ZARCH, APPLICATION_SPECIAL_DIRECTORY_ASSETS_ZARCH_FONT, - APPLICATION_SPECIAL_DIRECTORY_ASSETS_ZARCH_ICONS + APPLICATION_SPECIAL_DIRECTORY_ASSETS_ZARCH_ICONS, + APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_CHEEVOS_BADGES }; /** diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index c5bc6a2c47..7dc700b29e 100755 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -2245,9 +2245,11 @@ static uintptr_t xmb_icon_get_id(xmb_handle_t *xmb, if ((type >= MENU_SETTINGS_CHEEVOS_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; - 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 From 4f9119d42e3940e9a5420d95acccf6108f236e0c Mon Sep 17 00:00:00 2001 From: GameDragon2k Date: Thu, 23 Nov 2017 08:06:33 -0500 Subject: [PATCH 06/16] Fix conflict --- Makefile.common | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Makefile.common b/Makefile.common index 737820a16c..7aeea49c68 100644 --- a/Makefile.common +++ b/Makefile.common @@ -1474,12 +1474,9 @@ ifeq ($(HAVE_NETWORKING), 1) ifeq ($(HAVE_CHEEVOS), 1) DEFINES += -DHAVE_CHEEVOS OBJ += cheevos/cheevos.o \ -<<<<<<< HEAD cheevos/var.o \ cheevos/cond.o \ -======= - cheevos/badges.o \ ->>>>>>> Add files to handle all cheevos badges. + cheevos/badges.o \ $(LIBRETRO_COMM_DIR)/utils/md5.o endif From 2b9636d782f383008b7959fe7ec4c9848abeb291 Mon Sep 17 00:00:00 2001 From: GameDragon2k Date: Thu, 23 Nov 2017 11:55:53 -0500 Subject: [PATCH 07/16] Add xmb menu items --- cheevos/badges.c | 6 ++++++ cheevos/badges.h | 1 + cheevos/cheevos.c | 9 ++++++++- configuration.c | 5 ++++- configuration.h | 1 + intl/msg_hash_lbl.h | 2 ++ intl/msg_hash_us.h | 6 ++++++ menu/cbs/menu_cbs_sublabel.c | 4 ++++ menu/menu_displaylist.c | 18 ++++++++++++------ menu/menu_setting.c | 20 ++++++++++++++++++-- msg_hash.h | 1 + 11 files changed, 63 insertions(+), 10 deletions(-) diff --git a/cheevos/badges.c b/cheevos/badges.c index 922a1de22e..961fbc600e 100644 --- a/cheevos/badges.c +++ b/cheevos/badges.c @@ -1,7 +1,9 @@ #include +#include #include #include "../file_path_special.h" +#include "../configuration.h" #include "../verbosity.h" #include "../network/net_http_special.h" @@ -44,5 +46,9 @@ void set_badge_info (badges_ctx_t *badge_struct, int id, const char *badge_id, b menu_texture_item get_badge_texture (int id) { + settings_t *settings = config_get_ptr(); + if (!settings->bools.cheevos_badges_enable) + return (menu_texture_item)NULL; + return badges_ctx.menu_texture_list[id]; } diff --git a/cheevos/badges.h b/cheevos/badges.h index 863aa34e1a..57a8de6ed2 100644 --- a/cheevos/badges.h +++ b/cheevos/badges.h @@ -22,6 +22,7 @@ extern void set_badge_info (badges_ctx_t *badge_struct, int id, const char *badg extern menu_texture_item get_badge_texture(int id); extern badges_ctx_t badges_ctx; +static badges_ctx_t new_badges_ctx; RETRO_END_DECLS diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index 1c5f57058d..914309a705 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -3169,6 +3170,12 @@ static int cheevos_iterate(coro_t* coro) *************************************************************************/ CORO_SUB(GET_BADGES) + badges_ctx = new_badges_ctx; + + settings_t *settings = config_get_ptr(); + if (!string_is_equal_fast(settings->arrays.menu_driver, "xmb", 3) || !settings->bools.cheevos_badges_enable) + CORO_RET(); + char badge_filename[16]; char fullpath[PATH_MAX_LENGTH]; FILE* file; @@ -3176,7 +3183,7 @@ static int cheevos_iterate(coro_t* coro) const cheevo_t *end = cheevos_locals.core.cheevos + cheevos_locals.core.count; - for (unsigned i = 0; cheevo < end ; cheevo++) + for (; cheevo < end ; cheevo++) { for (unsigned j = 0; j < 2; j++) { diff --git a/configuration.c b/configuration.c index 21ce17f95d..513d9a6f0c 100644 --- a/configuration.c +++ b/configuration.c @@ -1255,6 +1255,9 @@ static struct config_bool_setting *populate_settings_bool(settings_t *settings, SETTING_BOOL("cheevos_test_unofficial", &settings->bools.cheevos_test_unofficial, true, false, false); SETTING_BOOL("cheevos_hardcore_mode_enable", &settings->bools.cheevos_hardcore_mode_enable, true, false, false); SETTING_BOOL("cheevos_leaderboards_enable", &settings->bools.cheevos_leaderboards_enable, true, false, false); +#ifdef HAVE_XMB + SETTING_BOOL("cheevos_badges_enable", &settings->bools.cheevos_badges_enable, true, false, false); +#endif SETTING_BOOL("cheevos_verbose_enable", &settings->bools.cheevos_verbose_enable, true, false, false); #endif #ifdef HAVE_OVERLAY @@ -1864,7 +1867,7 @@ static void config_set_defaults(void) temp_str[0] = '\0'; fill_pathname_expand_special(temp_str, - g_defaults.path.config, + g_defaults.path.config, PATH_MAX_LENGTH * sizeof(char)); path_set(RARCH_PATH_CONFIG, temp_str); free(temp_str); diff --git a/configuration.h b/configuration.h index ee2d29d5f7..7dd74b9282 100644 --- a/configuration.h +++ b/configuration.h @@ -184,6 +184,7 @@ typedef struct settings bool cheevos_test_unofficial; bool cheevos_hardcore_mode_enable; bool cheevos_leaderboards_enable; + bool cheevos_badges_enable; bool cheevos_verbose_enable; /* Camera */ diff --git a/intl/msg_hash_lbl.h b/intl/msg_hash_lbl.h index fbf28f4ca6..6cc3ee5313 100644 --- a/intl/msg_hash_lbl.h +++ b/intl/msg_hash_lbl.h @@ -136,6 +136,8 @@ MSG_HASH(MENU_ENUM_LABEL_CHEEVOS_HARDCORE_MODE_ENABLE, "cheevos_hardcore_mode_enable") MSG_HASH(MENU_ENUM_LABEL_CHEEVOS_LEADERBOARDS_ENABLE, "cheevos_leaderboards_enable") +MSG_HASH(MENU_ENUM_LABEL_CHEEVOS_BADGES_ENABLE, + "cheevos_badges_enable") MSG_HASH(MENU_ENUM_LABEL_CHEEVOS_LOCKED_ACHIEVEMENTS, "cheevos_locked_achievements") MSG_HASH(MENU_ENUM_LABEL_CHEEVOS_LOCKED_ENTRY, diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index a7f516c586..dbe83d50ba 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -434,6 +434,10 @@ MSG_HASH( MENU_ENUM_LABEL_VALUE_CHEEVOS_LEADERBOARDS_ENABLE, "Leaderboards" ) +MSG_HASH( + MENU_ENUM_LABEL_VALUE_CHEEVOS_BADGES_ENABLE, + "Achievement Badges" + ) MSG_HASH( MENU_ENUM_LABEL_VALUE_CHEEVOS_LOCKED_ACHIEVEMENTS, "Locked Achievements:" @@ -1791,6 +1795,8 @@ MSG_HASH(MENU_ENUM_SUBLABEL_CHEEVOS_HARDCORE_MODE_ENABLE, "Enable or disable savestates, cheats, rewind, fast-forward, pause, and slow-motion for all games.") MSG_HASH(MENU_ENUM_SUBLABEL_CHEEVOS_LEADERBOARDS_ENABLE, "Enable or disable in-game leaderboards. Has no effect if Hardcore Mode is disabled.") +MSG_HASH(MENU_ENUM_SUBLABEL_CHEEVOS_BADGES_ENABLE, + "Enable or disable badge display in Achievement List.") MSG_HASH(MENU_ENUM_SUBLABEL_CHEEVOS_VERBOSE_ENABLE, "Enable or disable OSD verbosity for achievements.") MSG_HASH(MENU_ENUM_SUBLABEL_DRIVER_SETTINGS, diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index 9b1013905a..db388d9def 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -63,6 +63,7 @@ default_sublabel_macro(action_bind_sublabel_cheevos_enable, MENU_ default_sublabel_macro(action_bind_sublabel_cheevos_test_unofficial, MENU_ENUM_SUBLABEL_CHEEVOS_TEST_UNOFFICIAL) default_sublabel_macro(action_bind_sublabel_cheevos_hardcore_mode_enable, MENU_ENUM_SUBLABEL_CHEEVOS_HARDCORE_MODE_ENABLE) default_sublabel_macro(action_bind_sublabel_cheevos_leaderboards_enable, MENU_ENUM_SUBLABEL_CHEEVOS_LEADERBOARDS_ENABLE) +default_sublabel_macro(action_bind_sublabel_cheevos_badges_enable, MENU_ENUM_SUBLABEL_CHEEVOS_BADGES_ENABLE) default_sublabel_macro(action_bind_sublabel_cheevos_verbose_enable, MENU_ENUM_SUBLABEL_CHEEVOS_VERBOSE_ENABLE) default_sublabel_macro(action_bind_sublabel_menu_views_settings_list, MENU_ENUM_SUBLABEL_MENU_VIEWS_SETTINGS) default_sublabel_macro(action_bind_sublabel_quick_menu_views_settings_list, MENU_ENUM_SUBLABEL_QUICK_MENU_VIEWS_SETTINGS) @@ -1266,6 +1267,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs, case MENU_ENUM_LABEL_CHEEVOS_LEADERBOARDS_ENABLE: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_cheevos_leaderboards_enable); break; + case MENU_ENUM_LABEL_CHEEVOS_BADGES_ENABLE: + BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_cheevos_badges_enable); + break; case MENU_ENUM_LABEL_CHEEVOS_VERBOSE_ENABLE: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_cheevos_verbose_enable); break; diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index e4dd8450d1..03290e1d8b 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -1572,7 +1572,7 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info, free(tmp); } } - + free(path_short); } @@ -3495,7 +3495,7 @@ static int menu_displaylist_parse_options_remappings( } #ifdef HAVE_KEYMAPPER if (system) - { + { settings_t *settings = config_get_ptr(); unsigned device = settings->uints.input_libretro_device[settings->uints.keymapper_port]; @@ -3514,13 +3514,13 @@ static int menu_displaylist_parse_options_remappings( keybind = &input_config_binds[settings->uints.keymapper_port][retro_id]; auto_bind = (const struct retro_keybind*) input_config_get_bind_auto(settings->uints.keymapper_port, retro_id); - + input_config_get_bind_string(descriptor, keybind, auto_bind, sizeof(descriptor)); if(!strstr(descriptor, "Auto")) { - const struct retro_keybind *keyptr = + const struct retro_keybind *keyptr = &input_config_binds[settings->uints.keymapper_port][retro_id]; strlcpy(descriptor, msg_hash_to_str(keyptr->enum_idx), sizeof(descriptor)); @@ -3860,7 +3860,7 @@ static int menu_displaylist_parse_cores( malloc(PATH_MAX_LENGTH * sizeof(char)); char *display_name = (char*) malloc(PATH_MAX_LENGTH * sizeof(char)); - core_path[0] = + core_path[0] = display_name[0] = '\0'; fill_pathname_join(core_path, dir, path, @@ -4180,7 +4180,7 @@ static void menu_displaylist_parse_playlist_generic( { playlist_t *playlist = NULL; char *path_playlist = NULL; - + menu_displaylist_set_new_playlist(menu, playlist_path); menu_driver_ctl(RARCH_MENU_CTL_PLAYLIST_GET, &playlist); @@ -5615,6 +5615,12 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data) menu_displaylist_parse_settings_enum(menu, info, MENU_ENUM_LABEL_CHEEVOS_LEADERBOARDS_ENABLE, PARSE_ONLY_BOOL, false); + if (string_is_equal_fast(settings->arrays.menu_driver, "xmb", 3)) + { + menu_displaylist_parse_settings_enum(menu, info, + MENU_ENUM_LABEL_CHEEVOS_BADGES_ENABLE, + PARSE_ONLY_BOOL, false); + } menu_displaylist_parse_settings_enum(menu, info, MENU_ENUM_LABEL_CHEEVOS_TEST_UNOFFICIAL, PARSE_ONLY_BOOL, false); diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 168dd8bc5f..bb39557308 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -917,7 +917,7 @@ int menu_setting_set(unsigned type, const char *label, int ret = 0; file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0); size_t selection = menu_navigation_get_selection(); - menu_file_list_cbs_t *cbs = selection_buf ? + menu_file_list_cbs_t *cbs = selection_buf ? (menu_file_list_cbs_t*)file_list_get_actiondata_at_offset(selection_buf, selection) : NULL; if (!cbs) @@ -1446,7 +1446,7 @@ static int setting_action_ok_bind_defaults(void *data, bool wraparound) return 0; } -static void +static void setting_get_string_representation_st_float_video_refresh_rate_auto( void *data, char *s, size_t len) { @@ -6461,6 +6461,22 @@ static bool setting_append_list( SD_FLAG_NONE ); + CONFIG_BOOL( + list, list_info, + &settings->bools.cheevos_badges_enable, + MENU_ENUM_LABEL_CHEEVOS_BADGES_ENABLE, + MENU_ENUM_LABEL_VALUE_CHEEVOS_BADGES_ENABLE, + false, + MENU_ENUM_LABEL_VALUE_OFF, + MENU_ENUM_LABEL_VALUE_ON, + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + general_read_handler, + SD_FLAG_NONE + ); + CONFIG_BOOL( list, list_info, &settings->bools.cheevos_verbose_enable, diff --git a/msg_hash.h b/msg_hash.h index 25f83229b8..b6a63286f0 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -853,6 +853,7 @@ enum msg_hash_enums MENU_LABEL(ACCOUNTS_CHEEVOS_USERNAME), MENU_LABEL(CHEEVOS_HARDCORE_MODE_ENABLE), MENU_LABEL(CHEEVOS_LEADERBOARDS_ENABLE), + MENU_LABEL(CHEEVOS_BADGES_ENABLE), MENU_LABEL(CHEEVOS_TEST_UNOFFICIAL), MENU_LABEL(CHEEVOS_VERBOSE_ENABLE), MENU_LABEL(CHEEVOS_ENABLE), From 1c0e692070f87fffd697dc7a325a7a499568e956 Mon Sep 17 00:00:00 2001 From: radius Date: Thu, 23 Nov 2017 17:07:22 -0500 Subject: [PATCH 08/16] rewrite so the variables are not allocated on stack --- cheevos/cheevos.c | 121 +++++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 60 deletions(-) diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index 525061f1c5..4fe6910247 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -2528,7 +2528,12 @@ typedef struct char url[256]; \ struct http_connection_t *conn; \ struct http_t *http; \ - retro_time_t t0; + retro_time_t t0; \ + char badge_basepath[PATH_MAX_LENGTH]; \ + char badge_fullpath[PATH_MAX_LENGTH]; \ + char badge_name[16]; \ + cheevo_t *cheevo; \ + const cheevo_t *cheevo_end; #include "coro.h" @@ -2557,8 +2562,13 @@ typedef struct #define CHEEVOS_VAR_SIZE CORO_VAR(size) #define CHEEVOS_VAR_URL CORO_VAR(url) #define CHEEVOS_VAR_CONN CORO_VAR(conn) -#define CHEEVOS_VAR_HTTP CORO_VAR(http) -#define CHEEVOS_VAR_T0 CORO_VAR(t0) +#define CHEEVOS_VAR_HTTP CORO_VAR(http) +#define CHEEVOS_VAR_T0 CORO_VAR(t0) +#define CHEEVOS_VAR_BADGE_PATH CORO_VAR(badge_fullpath) +#define CHEEVOS_VAR_BADGE_BASE_PATH CORO_VAR(badge_fullpath) +#define CHEEVOS_VAR_BADGE_NAME CORO_VAR(badge_name) +#define CHEEVOS_VAR_CHEEVO_CURR CORO_VAR(cheevo) +#define CHEEVOS_VAR_CHEEVO_END CORO_VAR(cheevo_end) static int cheevos_iterate(coro_t* coro) { @@ -2786,7 +2796,7 @@ static int cheevos_iterate(coro_t* coro) FILE* file; size_t size; - file = fopen(CHEEVOS_JSON_OVERRIDE, "rb"); + file = filestream_open(CHEEVOS_JSON_OVERRIDE, RFILE_MODE_READ_WRITE, -1); fseek(file, 0, SEEK_END); size = ftell(file); fseek(file, 0, SEEK_SET); @@ -3143,14 +3153,12 @@ static int cheevos_iterate(coro_t* coro) *************************************************************************/ CORO_SUB(GET_CHEEVOS) - CORO_GOSUB(LOGIN); + CORO_GOSUB(LOGIN); - snprintf( - CHEEVOS_VAR_URL, sizeof(CHEEVOS_VAR_URL), - "http://retroachievements.org/dorequest.php?r=patch&u=%s&g=%u&f=3&l=1&t=%s", - CHEEVOS_VAR_SETTINGS->arrays.cheevos_username, - CHEEVOS_VAR_GAMEID, cheevos_locals.token - ); + snprintf(CHEEVOS_VAR_URL, sizeof(CHEEVOS_VAR_URL), + "http://retroachievements.org/dorequest.php?r=patch&u=%s&g=%u&f=3&l=1&t=%s", + CHEEVOS_VAR_SETTINGS->arrays.cheevos_username, + CHEEVOS_VAR_GAMEID, cheevos_locals.token); CHEEVOS_VAR_URL[sizeof(CHEEVOS_VAR_URL) - 1] = 0; @@ -3169,66 +3177,59 @@ 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) + /************************************************************************** + * Info Gets the achievements from Retro Achievements + * Inputs CHEEVOS_VAR_GAMEID + * Outputs CHEEVOS_VAR_JSON + *************************************************************************/ + CORO_SUB(GET_BADGES) - badges_ctx = new_badges_ctx; + badges_ctx = new_badges_ctx; - settings_t *settings = config_get_ptr(); - if (!string_is_equal_fast(settings->arrays.menu_driver, "xmb", 3) || !settings->bools.cheevos_badges_enable) + settings_t *settings = config_get_ptr(); + if (!string_is_equal(settings->arrays.menu_driver, "xmb") || + !settings->bools.cheevos_badges_enable) CORO_RET(); - char badge_filename[16]; - char fullpath[PATH_MAX_LENGTH]; - FILE* file; - cheevo_t *cheevo = cheevos_locals.core.cheevos; - const cheevo_t *end = cheevos_locals.core.cheevos + - cheevos_locals.core.count; + FILE* file; + CHEEVOS_VAR_CHEEVO_CURR = cheevos_locals.core.cheevos; + CHEEVOS_VAR_CHEEVO_END = cheevos_locals.core.cheevos + cheevos_locals.core.count; - for (; cheevo < end ; cheevo++) - { - for (unsigned j = 0; j < 2; j++) + for (; CHEEVOS_VAR_CHEEVO_CURR < CHEEVOS_VAR_CHEEVO_END ; CHEEVOS_VAR_CHEEVO_CURR++) + { + for (CHEEVOS_VAR_J = 0 ; CHEEVOS_VAR_J < 2; CHEEVOS_VAR_J++) { - strcpy(badge_filename, cheevo->badge); - if (j == 0) strcat(badge_filename, ".png"); - else strcat(badge_filename, "_lock.png"); + CHEEVOS_VAR_BADGE_PATH[0] = '\0'; + fill_pathname_application_special(CHEEVOS_VAR_BADGE_BASE_PATH, sizeof(CHEEVOS_VAR_BADGE_BASE_PATH), + APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_CHEEVOS_BADGES); - fill_pathname_application_special(fullpath, - PATH_MAX_LENGTH * sizeof(char), - APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_CHEEVOS_BADGES); + if (!path_is_directory(CHEEVOS_VAR_BADGE_BASE_PATH)) + path_mkdir(CHEEVOS_VAR_BADGE_BASE_PATH); + CORO_YIELD(); + if (CHEEVOS_VAR_J == 0) + snprintf(CHEEVOS_VAR_BADGE_NAME, sizeof(CHEEVOS_VAR_BADGE_NAME), "%s.png", CHEEVOS_VAR_CHEEVO_CURR->badge); + else + snprintf(CHEEVOS_VAR_BADGE_NAME, sizeof(CHEEVOS_VAR_BADGE_NAME), "%s_lock.png", CHEEVOS_VAR_CHEEVO_CURR->badge); - if (!path_is_directory(fullpath)) - path_mkdir(fullpath); + fill_pathname_join(CHEEVOS_VAR_BADGE_PATH, CHEEVOS_VAR_BADGE_BASE_PATH, CHEEVOS_VAR_BADGE_NAME, sizeof(CHEEVOS_VAR_BADGE_PATH)); - 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 - } - } + if (!badge_exists(CHEEVOS_VAR_BADGE_PATH)) + { + snprintf(CHEEVOS_VAR_URL, sizeof(CHEEVOS_VAR_URL), "http://i.retroachievements.org/Badge/%s", CHEEVOS_VAR_BADGE_NAME); + CORO_GOSUB(HTTP_GET); + if (CHEEVOS_VAR_JSON != NULL) + { + file = fopen (CHEEVOS_VAR_BADGE_PATH, "wb"); + fwrite(CHEEVOS_VAR_JSON, 1, CHEEVOS_VAR_K, file); + fclose(file); +#ifdef CHEEVOS_LOG_BADGES + RARCH_LOG("[CHEEVOS]: downloaded badge %s\n", CHEEVOS_VAR_BADGE_PATH); +#endif + } + } } - } + } CORO_RET(); From a80fc4a762917a90ce767acd3da41067faf111e3 Mon Sep 17 00:00:00 2001 From: radius Date: Thu, 23 Nov 2017 17:33:26 -0500 Subject: [PATCH 09/16] revert this for now --- cheevos/cheevos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index 4fe6910247..c37ac68694 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -2796,7 +2796,7 @@ static int cheevos_iterate(coro_t* coro) FILE* file; size_t size; - file = filestream_open(CHEEVOS_JSON_OVERRIDE, RFILE_MODE_READ_WRITE, -1); + file = fopen(CHEEVOS_JSON_OVERRIDE, "rb"); fseek(file, 0, SEEK_END); size = ftell(file); fseek(file, 0, SEEK_SET); From 459b669798c7291e99947d43441482bcdaf72d20 Mon Sep 17 00:00:00 2001 From: radius Date: Thu, 23 Nov 2017 17:47:50 -0500 Subject: [PATCH 10/16] use filestream --- cheevos/cheevos.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index c37ac68694..8674154611 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -2576,6 +2576,7 @@ static int cheevos_iterate(coro_t* coro) size_t to_read = 4096; uint8_t *buffer = NULL; const char *end = NULL; + RFILE* file; enum { @@ -3191,7 +3192,6 @@ static int cheevos_iterate(coro_t* coro) !settings->bools.cheevos_badges_enable) CORO_RET(); - FILE* file; CHEEVOS_VAR_CHEEVO_CURR = cheevos_locals.core.cheevos; CHEEVOS_VAR_CHEEVO_END = cheevos_locals.core.cheevos + cheevos_locals.core.count; @@ -3220,9 +3220,9 @@ static int cheevos_iterate(coro_t* coro) CORO_GOSUB(HTTP_GET); if (CHEEVOS_VAR_JSON != NULL) { - file = fopen (CHEEVOS_VAR_BADGE_PATH, "wb"); - fwrite(CHEEVOS_VAR_JSON, 1, CHEEVOS_VAR_K, file); - fclose(file); + file = filestream_open(CHEEVOS_VAR_BADGE_PATH, RFILE_MODE_WRITE, -1); + filestream_write(file, CHEEVOS_VAR_JSON, CHEEVOS_VAR_K); + filestream_close(file); #ifdef CHEEVOS_LOG_BADGES RARCH_LOG("[CHEEVOS]: downloaded badge %s\n", CHEEVOS_VAR_BADGE_PATH); #endif From a865720d258c519b0098578009cf054a02d4f15f Mon Sep 17 00:00:00 2001 From: radius Date: Thu, 23 Nov 2017 17:49:55 -0500 Subject: [PATCH 11/16] indentation --- cheevos/cheevos.c | 62 +++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index 8674154611..7a1432535f 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -2537,38 +2537,38 @@ typedef struct #include "coro.h" -#define CHEEVOS_VAR_INFO CORO_VAR(info) -#define CHEEVOS_VAR_DATA CORO_VAR(data) -#define CHEEVOS_VAR_LEN CORO_VAR(len) -#define CHEEVOS_VAR_PATH CORO_VAR(path) -#define CHEEVOS_VAR_SETTINGS CORO_VAR(settings) -#define CHEEVOS_VAR_SYSINFO CORO_VAR(sysinfo) -#define CHEEVOS_VAR_I CORO_VAR(i) -#define CHEEVOS_VAR_J CORO_VAR(j) -#define CHEEVOS_VAR_K CORO_VAR(k) -#define CHEEVOS_VAR_EXT CORO_VAR(ext) -#define CHEEVOS_VAR_MD5 CORO_VAR(md5) -#define CHEEVOS_VAR_HASH CORO_VAR(hash) -#define CHEEVOS_VAR_GAMEID CORO_VAR(gameid) -#define CHEEVOS_VAR_JSON CORO_VAR(json) -#define CHEEVOS_VAR_COUNT CORO_VAR(count) -#define CHEEVOS_VAR_OFFSET CORO_VAR(offset) -#define CHEEVOS_VAR_HEADER CORO_VAR(header) -#define CHEEVOS_VAR_ROMSIZE CORO_VAR(romsize) -#define CHEEVOS_VAR_BYTES CORO_VAR(bytes) -#define CHEEVOS_VAR_MAPPER CORO_VAR(mapper) -#define CHEEVOS_VAR_ROUND CORO_VAR(round) -#define CHEEVOS_VAR_STREAM CORO_VAR(stream) -#define CHEEVOS_VAR_SIZE CORO_VAR(size) -#define CHEEVOS_VAR_URL CORO_VAR(url) -#define CHEEVOS_VAR_CONN CORO_VAR(conn) -#define CHEEVOS_VAR_HTTP CORO_VAR(http) -#define CHEEVOS_VAR_T0 CORO_VAR(t0) -#define CHEEVOS_VAR_BADGE_PATH CORO_VAR(badge_fullpath) +#define CHEEVOS_VAR_INFO CORO_VAR(info) +#define CHEEVOS_VAR_DATA CORO_VAR(data) +#define CHEEVOS_VAR_LEN CORO_VAR(len) +#define CHEEVOS_VAR_PATH CORO_VAR(path) +#define CHEEVOS_VAR_SETTINGS CORO_VAR(settings) +#define CHEEVOS_VAR_SYSINFO CORO_VAR(sysinfo) +#define CHEEVOS_VAR_I CORO_VAR(i) +#define CHEEVOS_VAR_J CORO_VAR(j) +#define CHEEVOS_VAR_K CORO_VAR(k) +#define CHEEVOS_VAR_EXT CORO_VAR(ext) +#define CHEEVOS_VAR_MD5 CORO_VAR(md5) +#define CHEEVOS_VAR_HASH CORO_VAR(hash) +#define CHEEVOS_VAR_GAMEID CORO_VAR(gameid) +#define CHEEVOS_VAR_JSON CORO_VAR(json) +#define CHEEVOS_VAR_COUNT CORO_VAR(count) +#define CHEEVOS_VAR_OFFSET CORO_VAR(offset) +#define CHEEVOS_VAR_HEADER CORO_VAR(header) +#define CHEEVOS_VAR_ROMSIZE CORO_VAR(romsize) +#define CHEEVOS_VAR_BYTES CORO_VAR(bytes) +#define CHEEVOS_VAR_MAPPER CORO_VAR(mapper) +#define CHEEVOS_VAR_ROUND CORO_VAR(round) +#define CHEEVOS_VAR_STREAM CORO_VAR(stream) +#define CHEEVOS_VAR_SIZE CORO_VAR(size) +#define CHEEVOS_VAR_URL CORO_VAR(url) +#define CHEEVOS_VAR_CONN CORO_VAR(conn) +#define CHEEVOS_VAR_HTTP CORO_VAR(http) +#define CHEEVOS_VAR_T0 CORO_VAR(t0) +#define CHEEVOS_VAR_BADGE_PATH CORO_VAR(badge_fullpath) #define CHEEVOS_VAR_BADGE_BASE_PATH CORO_VAR(badge_fullpath) -#define CHEEVOS_VAR_BADGE_NAME CORO_VAR(badge_name) -#define CHEEVOS_VAR_CHEEVO_CURR CORO_VAR(cheevo) -#define CHEEVOS_VAR_CHEEVO_END CORO_VAR(cheevo_end) +#define CHEEVOS_VAR_BADGE_NAME CORO_VAR(badge_name) +#define CHEEVOS_VAR_CHEEVO_CURR CORO_VAR(cheevo) +#define CHEEVOS_VAR_CHEEVO_END CORO_VAR(cheevo_end) static int cheevos_iterate(coro_t* coro) { From faef304755cd564e2c67816099b31e738696007f Mon Sep 17 00:00:00 2001 From: radius Date: Thu, 23 Nov 2017 17:53:28 -0500 Subject: [PATCH 12/16] use filestream_write_file instead --- cheevos/cheevos.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index 7a1432535f..76dca89de7 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -2576,7 +2576,6 @@ static int cheevos_iterate(coro_t* coro) size_t to_read = 4096; uint8_t *buffer = NULL; const char *end = NULL; - RFILE* file; enum { @@ -3220,9 +3219,8 @@ static int cheevos_iterate(coro_t* coro) CORO_GOSUB(HTTP_GET); if (CHEEVOS_VAR_JSON != NULL) { - file = filestream_open(CHEEVOS_VAR_BADGE_PATH, RFILE_MODE_WRITE, -1); - filestream_write(file, CHEEVOS_VAR_JSON, CHEEVOS_VAR_K); - filestream_close(file); + if (filestream_write_file(CHEEVOS_VAR_BADGE_PATH, CHEEVOS_VAR_JSON, CHEEVOS_VAR_K)) + RARCH_ERR("[CHEEVOS]: error writing badge %s\n", CHEEVOS_VAR_BADGE_PATH); #ifdef CHEEVOS_LOG_BADGES RARCH_LOG("[CHEEVOS]: downloaded badge %s\n", CHEEVOS_VAR_BADGE_PATH); #endif From 556eba5e58876ac28ccf25851a923b45f292115c Mon Sep 17 00:00:00 2001 From: radius Date: Thu, 23 Nov 2017 18:26:46 -0500 Subject: [PATCH 13/16] update CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index c825908cf1..17bb6ec41b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,5 @@ # 1.7.0 (future) +- CHEEVOS: Add badges # 1.6.9 - COMMON: Small memory leak. From f6419797698a7a65e6c9b9d4907a6e014dc66096 Mon Sep 17 00:00:00 2001 From: radius Date: Thu, 23 Nov 2017 19:37:47 -0500 Subject: [PATCH 14/16] add badges.c to griffin --- griffin/griffin.c | 1 + 1 file changed, 1 insertion(+) diff --git a/griffin/griffin.c b/griffin/griffin.c index 9b4a08f305..b65934f365 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -151,6 +151,7 @@ ACHIEVEMENTS #include "../libretro-common/formats/json/jsonsax.c" #include "../network/net_http_special.c" #include "../cheevos/cheevos.c" +#include "../cheevos/badges.c" #include "../cheevos/var.c" #include "../cheevos/cond.c" #endif From 36b9bd967527a5e7afe2d0367547a2d5f9ebdc5b Mon Sep 17 00:00:00 2001 From: radius Date: Thu, 23 Nov 2017 21:33:41 -0500 Subject: [PATCH 15/16] free CHEEVOS_VAR_JSON --- cheevos/cheevos.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index 76dca89de7..27e0b042ab 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -81,7 +81,7 @@ #undef CHEEVOS_LOG_PASSWORD /* Define this macro to log downloaded badge images. */ -#undef CHEEVOS_LOG_BADGES +#define CHEEVOS_LOG_BADGES /* C89 wants only int values in enums. */ #define CHEEVOS_JSON_KEY_GAMEID 0xb4960eecU @@ -3214,16 +3214,18 @@ static int cheevos_iterate(coro_t* coro) if (!badge_exists(CHEEVOS_VAR_BADGE_PATH)) { +#ifdef CHEEVOS_LOG_BADGES + RARCH_LOG("[CHEEVOS]: downloading badge %s\n", CHEEVOS_VAR_BADGE_PATH); +#endif snprintf(CHEEVOS_VAR_URL, sizeof(CHEEVOS_VAR_URL), "http://i.retroachievements.org/Badge/%s", CHEEVOS_VAR_BADGE_NAME); CORO_GOSUB(HTTP_GET); if (CHEEVOS_VAR_JSON != NULL) { - if (filestream_write_file(CHEEVOS_VAR_BADGE_PATH, CHEEVOS_VAR_JSON, CHEEVOS_VAR_K)) + if (!filestream_write_file(CHEEVOS_VAR_BADGE_PATH, CHEEVOS_VAR_JSON, CHEEVOS_VAR_K)) RARCH_ERR("[CHEEVOS]: error writing badge %s\n", CHEEVOS_VAR_BADGE_PATH); -#ifdef CHEEVOS_LOG_BADGES - RARCH_LOG("[CHEEVOS]: downloaded badge %s\n", CHEEVOS_VAR_BADGE_PATH); -#endif + else + free(CHEEVOS_VAR_JSON); } } } From ca2d2e4ba5a825557841b1f6ee758b6fa2ea6a25 Mon Sep 17 00:00:00 2001 From: radius Date: Thu, 23 Nov 2017 21:43:08 -0500 Subject: [PATCH 16/16] undefine this --- cheevos/cheevos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index 27e0b042ab..167e5239f0 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -81,7 +81,7 @@ #undef CHEEVOS_LOG_PASSWORD /* Define this macro to log downloaded badge images. */ -#define CHEEVOS_LOG_BADGES +#undef CHEEVOS_LOG_BADGES /* C89 wants only int values in enums. */ #define CHEEVOS_JSON_KEY_GAMEID 0xb4960eecU