Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ endif

# Libretro
SOURCES_C += $(LIBRETRO_DIR)/libretro.c \
$(LIBRETRO_DIR)/libretro_vfs.c \
$(LIBRETRO_COMM_DIR)/memmap/memalign.c \
$(ROOT_DIR)/custom/mupen64plus-core/plugin/emulate_game_controller_via_libretro.c \
$(LIBRETRO_COMM_DIR)/audio/resampler/drivers/sinc_resampler.c \
Expand Down
21 changes: 12 additions & 9 deletions libretro/libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "device/rcp/pi/pi_controller.h"
#include "device/pif/pif.h"
#include "libretro_memory.h"
#include "libretro_vfs.h"

#include "audio_plugin.h"

Expand Down Expand Up @@ -646,6 +647,13 @@ void retro_set_environment(retro_environment_t cb)
environ_cb(RETRO_ENVIRONMENT_SET_SUBSYSTEM_INFO, (void*)subsystems);
environ_cb(RETRO_ENVIRONMENT_GET_CLEAR_ALL_THREAD_WAITS_CB, &environ_clear_thread_waits_cb);

struct retro_vfs_interface_info vfs_iface_info;
vfs_iface_info.required_interface_version = 3;
vfs_iface_info.iface = NULL;

if (environ_cb(RETRO_ENVIRONMENT_GET_VFS_INTERFACE, &vfs_iface_info))
vfs_interface = vfs_iface_info.iface;

setup_variables();
}

Expand Down Expand Up @@ -1891,12 +1899,11 @@ bool retro_load_game(const struct retro_game_info *game)
newPath = (char*)calloc(1, strlen(gamePath)+5);
strcpy(newPath, gamePath);
strcat(newPath, ".ndd");
FILE* fileTest = fopen(newPath, "r");
if(!fileTest)

if (!vfs_file_exists(newPath))
{
free(newPath);
} else {
fclose(fileTest);
// Free'd later in Mupen Core
retro_dd_path_img = newPath;
}
Expand All @@ -1908,14 +1915,12 @@ bool retro_load_game(const struct retro_game_info *game)
newPath = (char *)calloc(1, strlen(gamePath) + 4);
strcpy(newPath, gamePath);
strcat(newPath, ".gb");
FILE *fileTest = fopen(newPath, "r");
if (!fileTest)
if (!vfs_file_exists(newPath))
{
free(newPath);
}
else
{
fclose(fileTest);
// Free'd later in Mupen Core
retro_transferpak_rom_path = newPath;

Expand All @@ -1926,14 +1931,12 @@ bool retro_load_game(const struct retro_game_info *game)
newPath = (char *)calloc(1, strlen(gamePath) + 5);
strcpy(newPath, gamePath);
strcat(newPath, ".sav");
FILE *fileTest = fopen(newPath, "r");
if (!fileTest)
if (!vfs_file_exists(newPath))
{
free(newPath);
}
else
{
fclose(fileTest);
// Free'd later in Mupen Core
retro_transferpak_ram_path = newPath;
}
Expand Down
39 changes: 39 additions & 0 deletions libretro/libretro_vfs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "libretro_vfs.h"

#include <stdio.h>
#include <stdlib.h>

struct retro_vfs_interface *vfs_interface = NULL;

void *vfs_fopen(const char *path, bool write)
{
if (vfs_interface)
{
unsigned access = write ? RETRO_VFS_FILE_ACCESS_WRITE
: RETRO_VFS_FILE_ACCESS_READ;
return (void*)vfs_interface->open(path, access, RETRO_VFS_FILE_ACCESS_HINT_NONE);
}

return (void*)fopen(path, write ? "wb" : "rb");
}

bool vfs_file_exists(const char *path)
{
void *fp = vfs_fopen(path, false);
if (!fp)
return false;

vfs_fclose(fp);
return true;
}

void vfs_fclose(void *fp)
{
if (!fp)
return;

if (vfs_interface)
vfs_interface->close((struct retro_vfs_file_handle*)fp);
else
fclose((FILE*)fp);
}
14 changes: 14 additions & 0 deletions libretro/libretro_vfs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef _LIBRETRO_VFS_H_
#define _LIBRETRO_VFS_H_

#include <stdbool.h>

#include "libretro.h"

extern struct retro_vfs_interface *vfs_interface;

void *vfs_fopen(const char *path, bool write);
bool vfs_file_exists(const char *path);
void vfs_fclose(void *fp);

#endif