recents: store altname.

This commit is contained in:
sorgelig
2019-12-29 08:12:29 +08:00
parent 3c119f76e9
commit 8a8645c530
5 changed files with 42 additions and 50 deletions

View File

@@ -600,6 +600,11 @@ int FileExists(const char *name)
return isPathRegularFile(name);
}
int PathIsDir(const char *name)
{
return isPathDirectory(name);
}
int FileCanWrite(const char *name)
{
sprintf(full_path, "%s/%s", getRootDir(), name);

View File

@@ -76,6 +76,7 @@ void FileCreatePath(const char *dir);
int FileExists(const char *name);
int FileCanWrite(const char *name);
int PathIsDir(const char *name);
#define SAVE_DIR "saves"
void FileGenerateSavePath(const char *name, char* out_name);

View File

@@ -256,6 +256,7 @@ static char* GetExt(char *ext)
static char SelectedRBF[1024] = { 0 };
static char SelectedDir[1024] = { 0 };
static char SelectedPath[1024] = { 0 };
static char SelectedLabel[1024] = { 0 };
static int changeDir(char *dir)
{
@@ -1258,7 +1259,7 @@ void HandleUI(void)
case MENU_ARCHIE_MAIN_FILE_SELECTED:
if (menusub <= 1)
{
recent_update(SelectedDir, SelectedPath, 500);
recent_update(SelectedDir, SelectedPath, SelectedLabel, 500);
user_io_file_mount(SelectedPath, menusub);
}
if (menusub == 2) archie_set_rom(SelectedPath);
@@ -1667,7 +1668,7 @@ void HandleUI(void)
menustate = MENU_NONE1;
}
recent_update(SelectedDir, SelectedPath, ioctl_index);
recent_update(SelectedDir, SelectedPath, SelectedLabel, ioctl_index);
break;
case MENU_8BIT_MAIN_IMAGE_SELECTED:
@@ -1709,7 +1710,7 @@ void HandleUI(void)
menustate = SelectedPath[0] ? MENU_NONE1 : MENU_8BIT_MAIN1;
recent_update(SelectedDir, SelectedPath, ioctl_index + 500);
recent_update(SelectedDir, SelectedPath, SelectedLabel, ioctl_index + 500);
break;
case MENU_8BIT_SYSTEM1:
@@ -3192,7 +3193,7 @@ void HandleUI(void)
break;
case MENU_FILE_SELECTED:
recent_update(SelectedDir, SelectedPath, 0);
recent_update(SelectedDir, SelectedPath, SelectedLabel, 0);
InsertFloppy(&df[menusub], SelectedPath);
if (menusub < drives) menusub++;
menustate = MENU_MAIN1;
@@ -3400,7 +3401,7 @@ void HandleUI(void)
strcpy(SelectedDir, SelectedPath);
strcat(SelectedPath, "/");
}
strcpy(SelectedLabel, flist_SelectedItem()->altname);
strcat(SelectedPath, name);
menustate = fs_MenuSelect;
}
@@ -3548,7 +3549,7 @@ void HandleUI(void)
if (select)
{
menustate = recent_select(SelectedDir, SelectedPath) ? (enum MENU)fs_MenuSelect : MENU_RECENT1;
menustate = recent_select(SelectedDir, SelectedPath, SelectedLabel) ? (enum MENU)fs_MenuSelect : MENU_RECENT1;
}
break;
@@ -4025,7 +4026,7 @@ void HandleUI(void)
/******************************************************************/
case MENU_HARDFILE_SELECTED:
{
recent_update(SelectedDir, SelectedPath, 500);
recent_update(SelectedDir, SelectedPath, SelectedLabel, 500);
int num = (menusub - 2) / 2;
uint len = strlen(SelectedPath);
if (len > sizeof(minimig_config.hardfile[num].filename) - 1) len = sizeof(minimig_config.hardfile[num].filename) - 1;

View File

@@ -10,7 +10,6 @@
#include "user_io.h"
#include "osd.h"
#include "cfg.h"
#include "support.h"
#include "recent.h"
#define RECENT_MAX 16
@@ -19,15 +18,11 @@ struct recent_rec_t
{
char dir[1024];
char name[256];
};
struct display_name_t
{
char name[256];
char label[256];
};
static recent_rec_t recents[RECENT_MAX];
static display_name_t displaynames[RECENT_MAX];
static char ena[RECENT_MAX];
static int numlast = 0;
@@ -46,6 +41,13 @@ static char* recent_create_config_name(int idx)
return str;
}
static const char* recent_path(char* dir, char* name)
{
static char path[1024];
snprintf(path, sizeof(path), "%s/%s", dir, name);
return path;
}
static void recent_load(int idx)
{
// initialize recent to empty strings
@@ -56,16 +58,11 @@ static void recent_load(int idx)
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())
// check the items
for (int i = 0; i < recent_available(); i++)
{
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);
if (altname) strcpy(displaynames[i].name, altname);
}
ena[i] = FileExists(recent_path(recents[i].dir, recents[i].name));
if (is_neogeo_core() && !ena[i]) ena[i] = PathIsDir(recent_path(recents[i].dir, recents[i].name));
}
}
@@ -150,13 +147,6 @@ void recent_scan(int mode)
}
}
static const char* recent_path(char* dir, char* name)
{
static char path[1024];
snprintf(path, sizeof(path), "%s/%s", dir, name);
return path;
}
void recent_scroll_name()
{
// this function is called periodically when file selection window is displayed
@@ -166,10 +156,10 @@ void recent_scroll_name()
static char name[256 + 4];
// don't scroll if the file doesn't exist
if (!FileExists(recent_path(recents[iSelectedEntry].dir, recents[iSelectedEntry].name))) return;
if (!ena[iSelectedEntry]) return;
name[0] = 32;
strcpy(name + 1, displaynames[iSelectedEntry].name);
strcpy(name + 1, recents[iSelectedEntry].label);
len = strlen(name); // get name length
@@ -195,7 +185,7 @@ void recent_print()
k = iFirstEntry + i;
s[0] = 32;
char* name = displaynames[k].name;
char* name = recents[k].label;
strcpy(s + 1, name);
len = strlen(s); // get name length
@@ -213,8 +203,7 @@ void recent_print()
if (!i && k) leftchar = 17;
if ((i == OsdGetSize() - 1) && (k < recent_available() - 1)) leftchar = 16;
// check if file exists
d = FileExists(recent_path(recents[k].dir, recents[k].name)) ? 0 : 1;
d = ena[k] ? 0 : 1;
}
else
{
@@ -225,35 +214,30 @@ void recent_print()
}
}
int recent_select(char *dir, char *path)
int recent_select(char *dir, char *path, char *label)
{
// copy directory and file name over
dir[0] = 0;
path[0] = 0;
if (!recent_available()) return 0;
if (strlen(recents[iSelectedEntry].name))
{
strcpy(dir, recents[iSelectedEntry].dir);
strcpy(path, dir);
strcat(path, "/");
strcat(path, recents[iSelectedEntry].name);
strcpy(label, recents[iSelectedEntry].label);
}
if (!FileExists(path)) return 0;
else return recent_available();
return ena[iSelectedEntry];
}
void recent_update(char* dir, char* path, int idx)
void recent_update(char* dir, char* path, char* label, int idx)
{
if (!cfg.recents || !strlen(path)) return;
if (is_neogeo_core())
{
// only support neo files for now to simplify name parsing and locating files in recent files menu
char* ext = strrchr(path, '.');
if (!ext || strcmp(ext, ".neo")) return;
}
// separate the path into directory and filename
char* name = strrchr(path, '/');
if (name) name++; else name = path;
@@ -264,8 +248,9 @@ void recent_update(char* dir, char* path, int idx)
// update the selection
int indexToErase = RECENT_MAX - 1;
recent_rec_t rec = {};
strcpy(rec.dir, dir);
strcpy(rec.name, name);
strncpy(rec.dir, dir, sizeof(rec.dir));
strncpy(rec.name, name, sizeof(rec.name));
strncpy(rec.label, label ? label : name, sizeof(rec.label));
for (unsigned i = 0; i < sizeof(recents)/sizeof(recents[0]); i++)
{

View File

@@ -5,8 +5,8 @@ int recent_init(int idx);
void recent_scan(int mode);
void recent_scroll_name();
void recent_print();
int recent_select(char* dir, char* path);
void recent_update(char* dir, char* path, int idx);
int recent_select(char *dir, char *path, char *label);
void recent_update(char* dir, char* path, char* label, int idx);
void recent_clear(int idx);
#endif