Check core's home dir on every access for plug and play functionality.
This commit is contained in:
50
file_io.cpp
50
file_io.cpp
@@ -104,7 +104,7 @@ static int get_stmode(const char *path)
|
||||
return (stat64(path, &st) < 0) ? 0 : st.st_mode;
|
||||
}
|
||||
|
||||
static bool isPathDirectory(const char *path)
|
||||
static int isPathDirectory(const char *path)
|
||||
{
|
||||
make_fullpath(path);
|
||||
|
||||
@@ -116,13 +116,13 @@ static bool isPathDirectory(const char *path)
|
||||
{
|
||||
printf("isPathDirectory(mz_zip_reader_init_file) Zip:%s, error:%s\n", zip_path,
|
||||
mz_zip_get_error_string(mz_zip_get_last_error(&z)));
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!*file_path)
|
||||
{
|
||||
mz_zip_reader_end(&z);
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Folder names always end with a slash in the zip
|
||||
@@ -135,13 +135,13 @@ static bool isPathDirectory(const char *path)
|
||||
zip_path, file_path,
|
||||
mz_zip_get_error_string(mz_zip_get_last_error(&z)));
|
||||
mz_zip_reader_end(&z);
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (mz_zip_reader_is_file_a_directory(&z, file_index))
|
||||
{
|
||||
mz_zip_reader_end(&z);
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
mz_zip_reader_end(&z);
|
||||
}
|
||||
@@ -150,17 +150,17 @@ static bool isPathDirectory(const char *path)
|
||||
int stmode = get_stmode(full_path);
|
||||
if (!stmode)
|
||||
{
|
||||
printf("isPathDirectory(stat) path:%s, error:%s.\n", full_path, strerror(errno));
|
||||
return false;
|
||||
printf("isPathDirectory(stat) path: %s, error: %s.\n", full_path, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (stmode & S_IFDIR) return true;
|
||||
if (stmode & S_IFDIR) return 1;
|
||||
}
|
||||
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool isPathRegularFile(const char *path)
|
||||
static int isPathRegularFile(const char *path)
|
||||
{
|
||||
make_fullpath(path);
|
||||
|
||||
@@ -172,13 +172,13 @@ static bool isPathRegularFile(const char *path)
|
||||
{
|
||||
//printf("isPathRegularFile(mz_zip_reader_init_file) Zip:%s, error:%s\n", zip_path,
|
||||
// mz_zip_get_error_string(mz_zip_get_last_error(&z)));
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!*file_path)
|
||||
{
|
||||
mz_zip_reader_end(&z);
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const int file_index = mz_zip_reader_locate_file(&z, file_path, NULL, 0);
|
||||
@@ -188,13 +188,13 @@ static bool isPathRegularFile(const char *path)
|
||||
// zip_path, file_path,
|
||||
// mz_zip_get_error_string(mz_zip_get_last_error(&z)));
|
||||
mz_zip_reader_end(&z);
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!mz_zip_reader_is_file_a_directory(&z, file_index) && mz_zip_reader_is_file_supported(&z, file_index))
|
||||
{
|
||||
mz_zip_reader_end(&z);
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
mz_zip_reader_end(&z);
|
||||
}
|
||||
@@ -203,7 +203,7 @@ static bool isPathRegularFile(const char *path)
|
||||
if (get_stmode(full_path) & S_IFREG) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FileClose(fileTYPE *file)
|
||||
@@ -892,7 +892,7 @@ void prefixGameDir(char *dir, size_t dir_len)
|
||||
{
|
||||
static char temp_dir[1024];
|
||||
|
||||
FileCreatePath(GAMES_DIR);
|
||||
//FileCreatePath(GAMES_DIR);
|
||||
snprintf(temp_dir, 1024, "%s/%s", GAMES_DIR, dir);
|
||||
strncpy(dir, temp_dir, dir_len);
|
||||
printf("Prefixed dir to %s\n", temp_dir);
|
||||
@@ -1105,7 +1105,7 @@ struct DirentComp
|
||||
|
||||
void AdjustDirectory(char *path)
|
||||
{
|
||||
if (isPathDirectory(path)) return;
|
||||
if (!FileExists(path)) return;
|
||||
|
||||
char *p = strrchr(path, '/');
|
||||
if (p)
|
||||
@@ -1238,8 +1238,12 @@ int ScanDirectory(char* path, int mode, const char *extension, int options, cons
|
||||
|
||||
if (mode == SCANF_INIT)
|
||||
{
|
||||
iFirstEntry = 0;
|
||||
iSelectedEntry = 0;
|
||||
DirItem.clear();
|
||||
|
||||
file_name[0] = 0;
|
||||
if ((options & SCANO_NOENTER) || !isPathDirectory(path))
|
||||
if ((options & SCANO_NOENTER) || isPathRegularFile(path))
|
||||
{
|
||||
char *p = strrchr(path, '/');
|
||||
if (p)
|
||||
@@ -1254,11 +1258,7 @@ int ScanDirectory(char* path, int mode, const char *extension, int options, cons
|
||||
}
|
||||
}
|
||||
|
||||
if (!isPathDirectory(path))
|
||||
{
|
||||
path[0] = 0;
|
||||
file_name[0] = 0;
|
||||
}
|
||||
if (!isPathDirectory(path)) return 0;
|
||||
|
||||
if (options & SCANO_NEOGEO) neogeo_scan_xml(path);
|
||||
|
||||
@@ -1278,10 +1278,6 @@ int ScanDirectory(char* path, int mode, const char *extension, int options, cons
|
||||
char *zip_path, *file_path_in_zip = (char*)"";
|
||||
FileIsZipped(full_path, &zip_path, &file_path_in_zip);
|
||||
|
||||
iFirstEntry = 0;
|
||||
iSelectedEntry = 0;
|
||||
DirItem.clear();
|
||||
|
||||
DIR *d = nullptr;
|
||||
mz_zip_archive *z = nullptr;
|
||||
if (is_zipped)
|
||||
|
||||
40
menu.cpp
40
menu.cpp
@@ -310,11 +310,12 @@ static int changeDir(char *dir)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char *home_dir = NULL;
|
||||
|
||||
// this function displays file selection menu
|
||||
static void SelectFile(const char* path, const char* pFileExt, unsigned char Options, unsigned char MenuSelect, unsigned char MenuCancel)
|
||||
{
|
||||
printf("pFileExt = %s\n", pFileExt);
|
||||
const char *suffix = NULL;
|
||||
|
||||
strncpy(selPath, path, sizeof(selPath) - 1);
|
||||
selPath[sizeof(selPath) - 1] = 0;
|
||||
@@ -328,31 +329,27 @@ static void SelectFile(const char* path, const char* pFileExt, unsigned char Opt
|
||||
strcat(selPath, get_rbf_name());
|
||||
}
|
||||
pFileExt = "RBFMRA";
|
||||
home_dir = NULL;
|
||||
}
|
||||
else if (Options & SCANO_TXT)
|
||||
{
|
||||
if(pFileExt == 0)
|
||||
pFileExt = "TXT";
|
||||
if(pFileExt == 0) pFileExt = "TXT";
|
||||
home_dir = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_pce() && !strncasecmp(pFileExt, "CUE", 3)) suffix = "CD";
|
||||
if (strncasecmp(HomeDir(suffix), selPath, strlen(HomeDir(suffix))) || !strcasecmp(HomeDir(suffix), selPath))
|
||||
const char *home = HomeDir((is_pce() && !strncasecmp(pFileExt, "CUE", 3)) ? PCECD_DIR : NULL);
|
||||
home_dir = strrchr(home, '/');
|
||||
if (home_dir) home_dir++;
|
||||
|
||||
if (strncasecmp(home, selPath, strlen(home)) || !strcasecmp(home, selPath))
|
||||
{
|
||||
Options &= ~SCANO_NOENTER;
|
||||
strcpy(selPath, HomeDir(suffix));
|
||||
strcpy(selPath, home);
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcasecmp(HomeDir(suffix), selPath)) FileCreatePath(selPath);
|
||||
|
||||
ScanDirectory(selPath, SCANF_INIT, pFileExt, Options);
|
||||
if (!flist_nDirEntries())
|
||||
{
|
||||
selPath[0] = 0;
|
||||
ScanDirectory(selPath, SCANF_INIT, pFileExt, Options);
|
||||
}
|
||||
|
||||
AdjustDirectory(selPath);
|
||||
|
||||
strcpy(fs_pFileExt, pFileExt);
|
||||
@@ -5250,10 +5247,19 @@ void PrintDirectory(int expand)
|
||||
if (!i && k) leftchar = 17;
|
||||
if (i && k < flist_nDirEntries() - 1) leftchar = 16;
|
||||
}
|
||||
else
|
||||
else if(!flist_nDirEntries()) // selected directory is empty
|
||||
{
|
||||
if (i == 0 && flist_nDirEntries() == 0) // selected directory is empty
|
||||
strcpy(s, " No files!");
|
||||
if (!i) strcpy(s, " No files!");
|
||||
if (home_dir)
|
||||
{
|
||||
if (i == 6) strcpy(s, " Missing directory:");
|
||||
if (i == 8)
|
||||
{
|
||||
len = strlen(home_dir);
|
||||
if (len > 27) len = 27;
|
||||
strncpy(s + 1 + ((27 - len) / 2), home_dir, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int sel = (i == (flist_iSelectedEntry() - flist_iFirstEntry()));
|
||||
|
||||
@@ -1121,6 +1121,8 @@ int neogeo_romset_tx(char* name)
|
||||
crom_sz = 0;
|
||||
set_config(0, -1);
|
||||
|
||||
const char* home = HomeDir();
|
||||
|
||||
// Look for the romset's file list in romsets.xml
|
||||
if (!(system_type & 2))
|
||||
{
|
||||
@@ -1140,7 +1142,7 @@ int neogeo_romset_tx(char* name)
|
||||
char *p = strrchr(full_path, '/');
|
||||
if (p) *p = 0;
|
||||
strcat(full_path, "/romsets.xml");
|
||||
if (!FileExists(full_path)) sprintf(full_path, "%s/%s/romsets.xml", getRootDir(), HomeDir());
|
||||
if (!FileExists(full_path)) sprintf(full_path, "%s/%s/romsets.xml", getRootDir(), home);
|
||||
}
|
||||
printf("xml for %s: %s\n", name, full_path);
|
||||
|
||||
@@ -1162,31 +1164,31 @@ int neogeo_romset_tx(char* name)
|
||||
if (strcmp(romset, "debug")) {
|
||||
// Not loading the special 'debug' romset
|
||||
if (!(system_type & 2)) {
|
||||
sprintf(full_path, "%s/uni-bios.rom", HomeDir());
|
||||
sprintf(full_path, "%s/uni-bios.rom", home);
|
||||
if (!(mask & 0x8000) && FileExists(full_path)) {
|
||||
// Autoload Unibios for cart systems if present
|
||||
neogeo_tx(HomeDir(), "uni-bios.rom", NEO_FILE_RAW, 0, 0, 0x20000);
|
||||
neogeo_tx(home, "uni-bios.rom", NEO_FILE_RAW, 0, 0, 0x20000);
|
||||
} else {
|
||||
// Otherwise load normal system roms
|
||||
if (system_type == 0)
|
||||
neogeo_tx(HomeDir(), "neo-epo.sp1", NEO_FILE_RAW, 0, 0, 0x20000);
|
||||
neogeo_tx(home, "neo-epo.sp1", NEO_FILE_RAW, 0, 0, 0x20000);
|
||||
else
|
||||
neogeo_tx(HomeDir(), "sp-s2.sp1", NEO_FILE_RAW, 0, 0, 0x20000);
|
||||
neogeo_tx(home, "sp-s2.sp1", NEO_FILE_RAW, 0, 0, 0x20000);
|
||||
}
|
||||
} else if (system_type == 2) {
|
||||
// NeoGeo CD
|
||||
neogeo_tx(HomeDir(), "top-sp1.bin", NEO_FILE_RAW, 0, 0, 0x80000);
|
||||
neogeo_tx(home, "top-sp1.bin", NEO_FILE_RAW, 0, 0, 0x80000);
|
||||
} else {
|
||||
// NeoGeo CDZ
|
||||
neogeo_tx(HomeDir(), "neocd.bin", NEO_FILE_RAW, 0, 0, 0x80000);
|
||||
neogeo_tx(home, "neocd.bin", NEO_FILE_RAW, 0, 0, 0x80000);
|
||||
}
|
||||
}
|
||||
|
||||
//flush CROM if any.
|
||||
neogeo_tx(NULL, NULL, 0, -1, 0, 0);
|
||||
|
||||
if (!(system_type & 2)) neogeo_tx(HomeDir(), "sfix.sfix", NEO_FILE_FIX, 2, 0, 0);
|
||||
neogeo_file_tx(HomeDir(), "000-lo.lo", NEO_FILE_8BIT, 1, 0, 0x10000);
|
||||
if (!(system_type & 2)) neogeo_tx(home, "sfix.sfix", NEO_FILE_FIX, 2, 0, 0);
|
||||
neogeo_file_tx(home, "000-lo.lo", NEO_FILE_8BIT, 1, 0, 0x10000);
|
||||
|
||||
if (crom_start < 0x300000) crom_start = 0x300000;
|
||||
uint32_t crom_max = crom_start + crom_sz_max;
|
||||
|
||||
@@ -226,7 +226,7 @@ void pcecd_set_image(int num, const char *filename)
|
||||
|
||||
if (!loaded)
|
||||
{
|
||||
sprintf(buf, "%sCD/cd_bios.rom", user_io_get_core_path());
|
||||
sprintf(buf, "%s/cd_bios.rom", HomeDir(PCECD_DIR));
|
||||
loaded = load_bios(buf, filename);
|
||||
}
|
||||
|
||||
|
||||
@@ -130,4 +130,6 @@ int pcecd_send_data(uint8_t* buf, int len, uint8_t index);
|
||||
void pcecd_reset();
|
||||
int pcecd_using_cd();
|
||||
|
||||
#define PCECD_DIR "TGFX16-CD"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -500,8 +500,10 @@ void x86_init()
|
||||
{
|
||||
user_io_8bit_set_status(UIO_STATUS_RESET, UIO_STATUS_RESET);
|
||||
|
||||
load_bios(user_io_make_filepath(HomeDir(), "boot0.rom"), 0);
|
||||
load_bios(user_io_make_filepath(HomeDir(), "boot1.rom"), 1);
|
||||
const char *home = HomeDir();
|
||||
|
||||
load_bios(user_io_make_filepath(home, "boot0.rom"), 0);
|
||||
load_bios(user_io_make_filepath(home, "boot1.rom"), 1);
|
||||
|
||||
IOWR(PC_BUS_BASE, 0, 0x00FFF0EA);
|
||||
IOWR(PC_BUS_BASE, 1, 0x000000F0);
|
||||
|
||||
29
user_io.cpp
29
user_io.cpp
@@ -129,9 +129,7 @@ char* user_io_create_config_name()
|
||||
return str;
|
||||
}
|
||||
|
||||
static char core_name[16 + 1]; // max 16 bytes for core name
|
||||
static char core_dir[1024];
|
||||
|
||||
static char core_name[32] = {};
|
||||
static char filepath_store[1024];
|
||||
|
||||
char *user_io_make_filepath(const char *path, const char *filename)
|
||||
@@ -141,7 +139,7 @@ char *user_io_make_filepath(const char *path, const char *filename)
|
||||
return filepath_store;
|
||||
}
|
||||
|
||||
static char ovr_name[16 + 1] = {};
|
||||
static char ovr_name[32] = {};
|
||||
void user_io_name_override(const char* name)
|
||||
{
|
||||
snprintf(ovr_name, sizeof(ovr_name), "%s", name);
|
||||
@@ -149,10 +147,7 @@ void user_io_name_override(const char* name)
|
||||
|
||||
void user_io_set_core_name(const char *name)
|
||||
{
|
||||
strncpy(core_name, name, 17);
|
||||
strncpy(core_dir, name, 1024);
|
||||
prefixGameDir(core_dir, 1024);
|
||||
|
||||
snprintf(core_name, sizeof(core_name), name);
|
||||
printf("Core name set to \"%s\"\n", core_name);
|
||||
}
|
||||
|
||||
@@ -164,13 +159,12 @@ char *user_io_get_core_name()
|
||||
char *user_io_get_core_path(const char *suffix)
|
||||
{
|
||||
static char tmp[1024];
|
||||
if (suffix)
|
||||
{
|
||||
strcpy(tmp, core_dir);
|
||||
strcat(tmp, suffix);
|
||||
return tmp;
|
||||
}
|
||||
return core_dir;
|
||||
|
||||
if (suffix) strcpy(tmp, suffix);
|
||||
else strcpy(tmp, !strcasecmp(core_name, "minimig") ? "Amiga" : core_name);
|
||||
|
||||
prefixGameDir(tmp, sizeof(tmp));
|
||||
return tmp;
|
||||
}
|
||||
|
||||
const char *user_io_get_core_name_ex()
|
||||
@@ -323,9 +317,6 @@ static void user_io_read_core_name()
|
||||
if (p && p[0]) strcpy(core_name, p);
|
||||
}
|
||||
|
||||
strcpy(core_dir, !strcasecmp(core_name, "minimig") ? "Amiga" : core_name);
|
||||
prefixGameDir(core_dir, sizeof(core_dir));
|
||||
|
||||
printf("Core name is \"%s\"\n", core_name);
|
||||
}
|
||||
|
||||
@@ -787,7 +778,6 @@ void user_io_init(const char *path, const char *xml)
|
||||
send_rtc(1);
|
||||
user_io_set_core_name("Archie");
|
||||
archie_init();
|
||||
user_io_read_core_name();
|
||||
parse_config();
|
||||
parse_buttons();
|
||||
break;
|
||||
@@ -796,7 +786,6 @@ void user_io_init(const char *path, const char *xml)
|
||||
puts("Identified Sharp MZ Series core");
|
||||
user_io_set_core_name("sharpmz");
|
||||
sharpmz_init();
|
||||
user_io_read_core_name();
|
||||
parse_config();
|
||||
parse_buttons();
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user