diff --git a/libretro.cpp b/libretro.cpp index 19a7b684..6d45c678 100644 --- a/libretro.cpp +++ b/libretro.cpp @@ -1568,12 +1568,17 @@ static void InitCommon(std::vector *CDInterfaces, const bool EmulateMemc abort(); { + const char *biospath = MDFN_MakeFName(MDFNMKF_FIRMWARE, + 0, MDFN_GetSettingS(biospath_sname).c_str()); + RFILE *BIOSFile = filestream_open(biospath, + RETRO_VFS_FILE_ACCESS_READ, + RETRO_VFS_FILE_ACCESS_HINT_NONE); - const char *biospath = MDFN_MakeFName(MDFNMKF_FIRMWARE, 0, MDFN_GetSettingS(biospath_sname).c_str()); - - FileStream BIOSFile(biospath, MODE_READ); - - BIOSFile.read(BIOSROM->data8, 512 * 1024); + if (BIOSFile) + { + filestream_read(BIOSFile, BIOSROM->data8, 512 * 1024); + filestream_close(BIOSFile); + } } i = 0; diff --git a/mednafen/cdrom/CDAccess_Image.cpp b/mednafen/cdrom/CDAccess_Image.cpp index 7174e974..c1ebea62 100644 --- a/mednafen/cdrom/CDAccess_Image.cpp +++ b/mednafen/cdrom/CDAccess_Image.cpp @@ -320,22 +320,27 @@ int CDAccess_Image::LoadSBI(const char* sbi_path) uint8 header[4]; uint8 ed[4 + 10]; uint8 tmpq[12]; - FileStream sbis(sbi_path, MODE_READ); + RFILE *sbis = filestream_open(sbi_path, + RETRO_VFS_FILE_ACCESS_READ, + RETRO_VFS_FILE_ACCESS_HINT_NONE); - sbis.read(header, 4); - - if(memcmp(header, "SBI\0", 4)) + if (!sbis) return -1; - while(sbis.read(ed, sizeof(ed), false) == sizeof(ed)) + filestream_read(sbis, header, 4); + + if(memcmp(header, "SBI\0", 4)) + goto error; + + while(filestream_read(sbis, ed, sizeof(ed)) == sizeof(ed)) { /* Bad BCD MSF offset in SBI file. */ if(!BCD_is_valid(ed[0]) || !BCD_is_valid(ed[1]) || !BCD_is_valid(ed[2])) - return -1; + goto error; /* Unrecognized boogly oogly in SBI file */ if(ed[3] != 0x01) - return -1; + goto error; memcpy(tmpq, &ed[4], 10); @@ -350,7 +355,13 @@ int CDAccess_Image::LoadSBI(const char* sbi_path) //MDFN_printf(_("Loaded Q subchannel replacements for %zu sectors.\n"), SubQReplaceMap.size()); log_cb(RETRO_LOG_INFO, "[Image] Loaded SBI file %s\n", sbi_path); + filestream_close(sbis); return 0; + +error: + if (sbis) + filestream_close(sbis); + return -1; } bool CDAccess_Image::ImageOpen(const char *path, bool image_memcache) diff --git a/mednafen/cdrom/CDAccess_PBP.cpp b/mednafen/cdrom/CDAccess_PBP.cpp index b5458e8c..17ff28ad 100644 --- a/mednafen/cdrom/CDAccess_PBP.cpp +++ b/mednafen/cdrom/CDAccess_PBP.cpp @@ -684,22 +684,27 @@ int CDAccess_PBP::LoadSBI(const char* sbi_path) uint8 header[4]; uint8 ed[4 + 10]; uint8 tmpq[12]; - FileStream sbis(sbi_path, MODE_READ); + RFILE *sbis = filestream_open(sbi_path, + RETRO_VFS_FILE_ACCESS_READ, + RETRO_VFS_FILE_ACCESS_HINT_NONE); - sbis.read(header, 4); - - if(memcmp(header, "SBI\0", 4)) + if (!sbis) return -1; - while(sbis.read(ed, sizeof(ed), false) == sizeof(ed)) + filestream_read(sbis, header, 4); + + if(memcmp(header, "SBI\0", 4)) + goto error; + + while(filestream_read(sbis, ed, sizeof(ed)) == sizeof(ed)) { /* Bad BCD MSF offset in SBI file. */ if(!BCD_is_valid(ed[0]) || !BCD_is_valid(ed[1]) || !BCD_is_valid(ed[2])) - return -1; + goto error; /* Unrecognized boogly oogly in SBI file */ if(ed[3] != 0x01) - return -1; + goto error; memcpy(tmpq, &ed[4], 10); @@ -716,7 +721,13 @@ int CDAccess_PBP::LoadSBI(const char* sbi_path) MDFN_printf(_("Loaded Q subchannel replacements for %zu sectors.\n"), SubQReplaceMap.size()); #endif log_cb(RETRO_LOG_INFO, "[PBP] Loaded SBI file %s\n", sbi_path); + filestream_close(sbis); return 0; + +error: + if (sbis) + filestream_close(sbis); + return -1; } void CDAccess_PBP::Eject(bool eject_status) diff --git a/mednafen/psx/frontio.cpp b/mednafen/psx/frontio.cpp index 0a4896d0..fefd7772 100644 --- a/mednafen/psx/frontio.cpp +++ b/mednafen/psx/frontio.cpp @@ -945,12 +945,18 @@ void FrontIO::LoadMemcard(unsigned int which, const char *path) if(DevicesMC[which]->GetNVSize()) { - FileStream mf(path, MODE_READ); + RFILE *mf = filestream_open(path, RETRO_VFS_FILE_ACCESS_READ, + RETRO_VFS_FILE_ACCESS_HINT_NONE); - mf.read(DevicesMC[which]->GetNVData(), (1 << 17)); + if (!mf) + return; + + filestream_read(mf, DevicesMC[which]->GetNVData(), (1 << 17)); DevicesMC[which]->WriteNV(DevicesMC[which]->GetNVData(), 0, (1 << 17)); DevicesMC[which]->ResetNVDirtyCount(); // There's no need to rewrite the file if it's the same data. + + filestream_close(mf); } } @@ -971,14 +977,19 @@ void FrontIO::SaveMemcard(unsigned int which, const char *path) if(DevicesMC[which]->GetNVSize() && DevicesMC[which]->GetNVDirtyCount()) { - FileStream mf(path, MODE_WRITE); // TODO: MODE_WRITE_ATOMIC_OVERWRITE + RFILE *mf = filestream_open(path, + RETRO_VFS_FILE_ACCESS_WRITE, + RETRO_VFS_FILE_ACCESS_HINT_NONE); - DevicesMC[which]->ReadNV(DevicesMC[which]->GetNVData(), 0, (1 << 17)); - mf.write(DevicesMC[which]->GetNVData(), (1 << 17)); + if (!mf) + return; - mf.close(); // Call before resetting the NV dirty count! + DevicesMC[which]->ReadNV(DevicesMC[which]->GetNVData(), 0, (1 << 17)); + filestream_write(mf, DevicesMC[which]->GetNVData(), (1 << 17)); - DevicesMC[which]->ResetNVDirtyCount(); + filestream_close(mf); // Call before resetting the NV dirty count! + + DevicesMC[which]->ResetNVDirtyCount(); } }