Start using filestream directly where possible

This commit is contained in:
twinaphex 2017-12-19 01:42:59 +01:00
parent 456862089a
commit 78836b5d1c
4 changed files with 64 additions and 26 deletions

View File

@ -1568,12 +1568,17 @@ static void InitCommon(std::vector<CDIF *> *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;

View File

@ -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)

View File

@ -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)

View File

@ -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();
}
}