Skip to content

Commit

Permalink
Using file name as link/mount point name in order to support Save Gam…
Browse files Browse the repository at this point in the history
…e Files
  • Loading branch information
pocomane committed Jul 31, 2021
1 parent dcf0eec commit 211260b
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions mbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,13 +670,13 @@ static void get_base_path(system_t* sys, char* out, int size) {
}
}

static void get_link_path(system_t* sys, char* out, int size) {
static void get_link_path(system_t* sys, const char* filename, char* out, int size) {
if (NULL != sys->sublink) {
snprintf(out, size-1, "%s", sys->sublink);
} else {
get_base_path(sys, out, size);
int dl = strlen(out);
snprintf(out+dl, size-dl-1, "/%s/%s.%s", ROMSUBLINK, MBC_LINK_NAM, sys->romext);
snprintf(out+dl, size-dl-1, "/%s/%s.%s", ROMSUBLINK, filename?filename:MBC_LINK_NAM, sys->romext);
}
}

Expand Down Expand Up @@ -737,8 +737,14 @@ static int rom_link(system_t* sys, char* path) {
// Here we use the system 2)
//

char filename[strlen(path)];
filename[0] = '\0';
strcpy(filename, after_string(path, '/'));
char* ext = after_string(filename,'.');
if (ext > filename+1) *(ext-1) = '\0';

char linkpath[PATH_MAX] = {0};
get_link_path(sys, linkpath, sizeof(linkpath));
get_link_path(sys, filename, linkpath, sizeof(linkpath));

if (create_file(linkpath)) {
PRINTERR("Can not create rom link file or folder %s\n", linkpath);
Expand Down Expand Up @@ -766,11 +772,28 @@ static int rom_unlink(system_t* sys) {
int result;
char aux_path[PATH_MAX] = {0};

get_link_path(sys, aux_path, sizeof(aux_path));
if (!filesystem_unbind(aux_path) && is_empty_file(aux_path))
remove(aux_path);

get_link_path(sys, NULL, aux_path, sizeof(aux_path));
path_parentize(aux_path);

struct dirent* ep = NULL;
DIR* dp = opendir(aux_path);
if (dp != NULL) {
while (0 != (ep = readdir (dp))){
if (!strcmp(".",ep->d_name) || !strcmp("..",ep->d_name))
continue;
char p[PATH_MAX] = {0};
snprintf(p, sizeof(p), "%s/%s", aux_path, ep->d_name);
if (!filesystem_unbind(p) && is_empty_file(p))
remove(p);
}
}

result = filesystem_unbind(aux_path);
if (result) {
PRINTERR("Can not unbind %s\n", aux_path);
return result;
}

rmdir(aux_path); // No issue if error

return result;
Expand Down

0 comments on commit 211260b

Please sign in to comment.