mirror of https://github.com/PCSX2/pcsx2.git
CDVD: Use wxFFile API to handle MEC file too
again nicer, exception safe, less compilation warning :) v2: * check file is properly opened in write mode * only print an error when result is bad
This commit is contained in:
parent
534e01e2d6
commit
deb7121fde
|
@ -86,37 +86,35 @@ static int mg_BIToffset(u8 *buffer)
|
||||||
return ofs + 0x20;
|
return ofs + 0x20;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *_cdvdOpenMechaVer()
|
static void cdvdGetMechaVer(u8* ver)
|
||||||
{
|
{
|
||||||
// get the name of the bios file
|
|
||||||
|
|
||||||
wxFileName mecfile(EmuConfig.BiosFilename);
|
wxFileName mecfile(EmuConfig.BiosFilename);
|
||||||
mecfile.SetExt( L"mec" );
|
mecfile.SetExt( L"mec" );
|
||||||
const wxString fname( mecfile.GetFullPath() );
|
const wxString fname( mecfile.GetFullPath() );
|
||||||
|
|
||||||
// if file doesnt exist, create empty one
|
// Likely a bad idea to go further
|
||||||
FILE* fd = wxFopen(fname, L"r+b");
|
if (mecfile.IsDir())
|
||||||
if (fd == NULL)
|
|
||||||
{
|
|
||||||
Console.Warning("MEC File Not Found, creating substitute...");
|
|
||||||
fd = wxFopen(fname, L"wb");
|
|
||||||
if (fd == NULL)
|
|
||||||
throw Exception::CannotCreateStream(fname);
|
throw Exception::CannotCreateStream(fname);
|
||||||
|
|
||||||
fputc(0x03, fd);
|
|
||||||
fputc(0x06, fd);
|
if (Path::GetFileSize(fname) < 4) {
|
||||||
fputc(0x02, fd);
|
Console.Warning("MEC File Not Found, creating substitute...");
|
||||||
fputc(0x00, fd);
|
|
||||||
}
|
wxFFile fp(fname, L"wb");
|
||||||
return fd;
|
if (!fp.IsOpened())
|
||||||
|
throw Exception::CannotCreateStream(fname);
|
||||||
|
|
||||||
|
u8 version[4] = {0x3, 0x6, 0x2, 0x0};
|
||||||
|
fp.Write(version, sizeof(version));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cdvdGetMechaVer(u8* ver)
|
wxFFile fp(fname, L"rb");
|
||||||
{
|
if (!fp.IsOpened())
|
||||||
FILE* fd = _cdvdOpenMechaVer();
|
throw Exception::CannotCreateStream(fname);
|
||||||
fseek(fd, 0, SEEK_SET);
|
|
||||||
fread(ver, 1, 4, fd);
|
size_t ret = fp.Read(ver, 4);
|
||||||
fclose(fd);
|
if (ret != 4)
|
||||||
|
Console.Error(L"Failed to read from %s. Did only %zu/4 bytes", WX_STR(fname), ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
NVMLayout* getNvmLayout()
|
NVMLayout* getNvmLayout()
|
||||||
|
|
Loading…
Reference in New Issue