diff --git a/file_io.cpp b/file_io.cpp
index ecbcca9..f303f8e 100644
--- a/file_io.cpp
+++ b/file_io.cpp
@@ -102,7 +102,7 @@ static int get_stmode(const char *path)
return (stat64(path, &st) < 0) ? 0 : st.st_mode;
}
-static bool isPathDirectory(char *path)
+static bool isPathDirectory(const char *path)
{
make_fullpath(path);
@@ -630,7 +630,7 @@ static void create_path(const char *base_dir, const char* sub_dir)
mkdir(full_path, S_IRWXU | S_IRWXG | S_IRWXO);
}
-void FileCreatePath(char *dir)
+void FileCreatePath(const char *dir)
{
if (!isPathDirectory(dir)) {
make_fullpath(dir);
@@ -700,7 +700,7 @@ uint32_t getFileType(const char *name)
return st.st_mode;
}
-void prefixGameDir(char *dir, size_t dir_len)
+int findPrefixDir(char *dir, size_t dir_len)
{
// Searches for the core's folder in the following order:
// /media/fat
@@ -713,7 +713,7 @@ void prefixGameDir(char *dir, size_t dir_len)
// it will be created in /media/fat/games/
if (isPathDirectory(dir)) {
printf("Found existing: %s\n", dir);
- return;
+ return 1;
}
static char temp_dir[1024];
@@ -723,14 +723,14 @@ void prefixGameDir(char *dir, size_t dir_len)
if (isPathDirectory(temp_dir)) {
printf("Found USB dir: %s\n", temp_dir);
strncpy(dir, temp_dir, dir_len);
- return;
+ return 1;
}
snprintf(temp_dir, 1024, "%s%d/%s/%s", "../usb", x, GAMES_DIR, dir);
if (isPathDirectory(temp_dir)) {
printf("Found USB dir: %s\n", temp_dir);
strncpy(dir, temp_dir, dir_len);
- return;
+ return 1;
}
}
@@ -738,20 +738,37 @@ void prefixGameDir(char *dir, size_t dir_len)
if (isPathDirectory(temp_dir)) {
printf("Found CIFS dir: %s\n", temp_dir);
strncpy(dir, temp_dir, dir_len);
- return;
+ return 1;
}
snprintf(temp_dir, 1024, "%s/%s/%s", CIFS_DIR, GAMES_DIR, dir);
if (isPathDirectory(temp_dir)) {
printf("Found CIFS dir: %s\n", temp_dir);
strncpy(dir, temp_dir, dir_len);
- return;
+ return 1;
}
- FileCreatePath((char *) 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);
+ if (isPathDirectory(temp_dir)) {
+ printf("Found dir: %s\n", temp_dir);
+ strncpy(dir, temp_dir, dir_len);
+ return 1;
+ }
+
+ return 0;
+}
+
+void prefixGameDir(char *dir, size_t dir_len)
+{
+ if (!findPrefixDir(dir, dir_len))
+ {
+ static char temp_dir[1024];
+
+ 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);
+ }
}
static int device = 0;
diff --git a/file_io.h b/file_io.h
index cdbc022..ce6f156 100644
--- a/file_io.h
+++ b/file_io.h
@@ -72,7 +72,7 @@ int FileReadAdv(fileTYPE *file, void *pBuffer, int length);
int FileReadSec(fileTYPE *file, void *pBuffer);
int FileWriteAdv(fileTYPE *file, void *pBuffer, int length);
int FileWriteSec(fileTYPE *file, void *pBuffer);
-void FileCreatePath(char *dir);
+void FileCreatePath(const char *dir);
int FileExists(const char *name);
int FileCanWrite(const char *name);
@@ -99,6 +99,7 @@ void AdjustDirectory(char *path);
int ScanDirectory(char* path, int mode, const char *extension, int options, const char *prefix = NULL);
void prefixGameDir(char *dir, size_t dir_len);
+int findPrefixDir(char *dir, size_t dir_len);
const char *getStorageDir(int dev);
const char *getRootDir();
diff --git a/support/arcade/romutils.cpp b/support/arcade/romutils.cpp
index 7b0289e..52b861b 100644
--- a/support/arcade/romutils.cpp
+++ b/support/arcade/romutils.cpp
@@ -35,6 +35,7 @@ struct arc_struct {
static char arcade_error_msg[kBigTextSize] = {};
static char arcade_root[kBigTextSize];
+static char mame_root[kBigTextSize];
static void set_arcade_root(const char *path)
{
@@ -46,14 +47,27 @@ static void set_arcade_root(const char *path)
else strcpy(arcade_root, getRootDir());
printf("arcade_root %s\n", arcade_root);
+
+ strcpy(mame_root, "mame");
+ if (findPrefixDir(mame_root, sizeof(mame_root)))
+ {
+ char *p = strrchr(mame_root, '/');
+ if (p) *p = 0;
+ }
+ else
+ {
+ strcpy(mame_root, arcade_root);
+ }
+
+ printf("mame_root %s\n", mame_root);
}
-static const char *get_arcade_root(const char *folder = NULL)
+static const char *get_arcade_root(int rbf)
{
static char path[kBigTextSize];
- if (!folder) strcpy(path, arcade_root);
- else sprintf(path, "%s/%s", arcade_root, folder);
+ if (!rbf) strcpy(path, mame_root);
+ else sprintf(path, "%s/cores", arcade_root);
return path;
}
@@ -417,7 +431,8 @@ static int xml_send_rom(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, cons
if (strlen(arc_info->partname))
{
char *zipname = (strlen(arc_info->partzipname)) ? arc_info->partzipname : arc_info->zipname;
- sprintf(fname, (zipname[0] == '/') ? "%s%s/%s" : "%s/mame/%s/%s", get_arcade_root(), zipname, arc_info->partname);
+ const char *root = get_arcade_root(0);
+ sprintf(fname, (zipname[0] == '/') ? "%s%s/%s" : "%s/mame/%s/%s", root, zipname, arc_info->partname);
printf("file: %s, start=%d, len=%d\n", fname, start, length);
for (int i = 0; i < repeat; i++)
@@ -428,7 +443,7 @@ static int xml_send_rom(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, cons
if (result == 0)
{
printf("%s does not exist\n", fname);
- snprintf(arc_info->error_msg, kBigTextSize, "%s\nFile Not Found", fname + strlen(get_arcade_root()));
+ snprintf(arc_info->error_msg, kBigTextSize, "%s\nFile Not Found", fname + strlen(root));
}
}
}
@@ -562,7 +577,7 @@ static const char *get_rbf(const char *xml)
struct dirent *entry;
DIR *dir;
- const char *dirname = get_arcade_root("cores");
+ const char *dirname = get_arcade_root(1);
if (!(dir = opendir(dirname)))
{
printf("%s directory not found\n", dirname);
@@ -605,15 +620,18 @@ static const char *get_rbf(const char *xml)
int arcade_load(const char *xml)
{
MenuHide();
+ static char path[kBigTextSize];
- set_arcade_root(xml);
- printf("arcade_load [%s]\n", xml);
- const char *rbf = get_rbf(xml);
+ strcpy(path, xml);
+
+ set_arcade_root(path);
+ printf("arcade_load [%s]\n", path);
+ const char *rbf = get_rbf(path);
if (rbf)
{
- printf("MRA: %s, RBF: %s\n", xml, rbf);
- fpga_load_rbf(rbf, NULL, xml);
+ printf("MRA: %s, RBF: %s\n", path, rbf);
+ fpga_load_rbf(rbf, NULL, path);
}
else
{