From 7f4159a21eb276af4f7483bdfc2cf35d9d1e38c8 Mon Sep 17 00:00:00 2001 From: sorgelig Date: Sun, 29 Dec 2019 06:37:17 +0800 Subject: [PATCH] recents: simpification of data, option to clear the list. --- menu.cpp | 11 +++++++++++ recent.cpp | 48 ++++++++++++++++++++++++------------------------ recent.h | 1 + 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/menu.cpp b/menu.cpp index 25a1e49..4d1e294 100644 --- a/menu.cpp +++ b/menu.cpp @@ -3523,6 +3523,17 @@ void HandleUI(void) menustate = MENU_RECENT1; } + if (c == KEY_BACKSPACE) + { + for (int i = 0; i < OsdGetSize(); i++) OsdWrite(i, "", 0, 0); + OsdWrite(OsdGetSize() / 2, " Clearing the recents", 0, 0); + OsdUpdate(); + sleep(1); + recent_clear((fs_Options & SCANO_UMOUNT) ? ioctl_index + 500 : ioctl_index); + menustate = fs_MenuCancel; + break; + } + if (down) // scroll down one entry { recent_scan(SCANF_NEXT); diff --git a/recent.cpp b/recent.cpp index 979779d..b229b06 100644 --- a/recent.cpp +++ b/recent.cpp @@ -5,15 +5,9 @@ #include #include #include -#include -#include -#include -#include "hardware.h" #include "file_io.h" #include "user_io.h" -#include "fpga_io.h" -#include "miniz_zip.h" #include "osd.h" #include "recent.h" #include "support.h" @@ -31,10 +25,8 @@ struct display_name_t char name[256]; }; -typedef std::vector RecentVector; -static RecentVector recents(RECENT_MAX); -typedef std::vector RecentDisplayNameVector; -static RecentDisplayNameVector displaynames(RECENT_MAX); +static recent_rec_t recents[RECENT_MAX]; +static display_name_t displaynames[RECENT_MAX]; static int numlast = 0; @@ -56,17 +48,18 @@ static char* recent_create_config_name(int idx) static void recent_load(int idx) { // initialize recent to empty strings - memset(recents.data(), 0, recents.size() * sizeof(recent_rec_t)); + memset(recents, 0, sizeof(recents)); // load the config file into memory - FileLoadConfig(recent_create_config_name(idx), recents.data(), recents.size() * sizeof(recent_rec_t)); + FileLoadConfig(recent_create_config_name(idx), recents, sizeof(recents)); - for (numlast = 0; numlast < (int)recents.size() && strlen(recents[numlast].name); numlast++) {} + for (numlast = 0; numlast < (int)(sizeof(recents)/sizeof(recents[0])) && strlen(recents[numlast].name); numlast++) {} // init display names to file names for (int i = 0; i < recent_available(); i++) memcpy(displaynames[i].name, recents[i].name, sizeof(displaynames[i].name)); - if (is_neogeo_core()) { + if (is_neogeo_core()) + { for (int i = 0; i < recent_available(); i++) { // update display names for neogeo neo files char* altname = neogeo_get_altname(recents[i].dir, recents[i].name, recents[i].name); @@ -156,11 +149,9 @@ void recent_scan(int mode) static const char* recent_path(char* dir, char* name) { - static std::string fullname; - fullname = dir; - fullname += '/'; - fullname += name; - return fullname.c_str(); + static char path[1024]; + snprintf(path, sizeof(path), "%s/%s", dir, name); + return path; } void recent_scroll_name() @@ -269,11 +260,11 @@ void recent_update(char* dir, char* path, int idx) // update the selection int indexToErase = RECENT_MAX - 1; - recent_rec_t rec; + recent_rec_t rec = {}; strcpy(rec.dir, dir); strcpy(rec.name, name); - for (unsigned i = 0; i < recents.size(); i++) + for (unsigned i = 0; i < sizeof(recents)/sizeof(recents[0]); i++) { if (!strcmp(recents[i].dir, dir) && !strcmp(recents[i].name, name)) { @@ -281,9 +272,18 @@ void recent_update(char* dir, char* path, int idx) break; } } - recents.erase(recents.begin() + indexToErase); - recents.insert(recents.begin(), rec); + + if(indexToErase) memmove(recents + 1, recents, sizeof(recents[0])*indexToErase); + memcpy(recents, &rec, sizeof(recents[0])); // store the config file to storage - FileSaveConfig(recent_create_config_name(idx), recents.data(), recents.size() * sizeof(recent_rec_t)); + FileSaveConfig(recent_create_config_name(idx), recents, sizeof(recents)); +} + +void recent_clear(int idx) +{ + memset(recents, 0, sizeof(recents)); + + // store the config file to storage + FileSaveConfig(recent_create_config_name(idx), recents, sizeof(recents)); } diff --git a/recent.h b/recent.h index 4e46a76..4d2641b 100644 --- a/recent.h +++ b/recent.h @@ -7,5 +7,6 @@ void recent_scroll_name(); void recent_print(); int recent_select(char* dir, char* path); void recent_update(char* dir, char* path, int idx); +void recent_clear(int idx); #endif