Skip to content

Commit

Permalink
recording: Throw errors on fread/fwrite errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
xTVaser committed Jan 19, 2019
1 parent 5a2160f commit 7955b42
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions pcsx2/Recording/InputRecordingFile.cpp
Expand Up @@ -183,9 +183,19 @@ bool InputRecordingFile::DeletePadData(unsigned long frame)

u8 buf[2][18];
fseek(recordingFile, seek1, SEEK_SET);
int rsize = fread(buf, 1, RecordingBlockDataSize, recordingFile);
int rSize = fread(buf, 1, RecordingBlockDataSize, recordingFile);
if (rSize != RecordingBlockDataSize)
{
recordingConLog(wxString::Format("[REC]: Error encountered when reading from file: Expected %d bytes, read %d instead.\n", RecordingBlockDataSize, rSize));
return false;
}
fseek(recordingFile, seek2, SEEK_SET);
fwrite(buf,1, RecordingBlockDataSize, recordingFile);
rSize = fwrite(buf, 1, RecordingBlockDataSize, recordingFile);
if (rSize != RecordingBlockDataSize)
{
recordingConLog(wxString::Format("[REC]: Error encountered when writing to file: Expected %d bytes, read %d instead.\n", RecordingBlockDataSize, rSize));
return false;
}
}
MaxFrame--;
WriteMaxFrame();
Expand All @@ -209,13 +219,28 @@ bool InputRecordingFile::InsertPadData(unsigned long frame, const PadData& key)

u8 buf[2][18];
fseek(recordingFile, seek1, SEEK_SET);
int rsize = fread(buf, 1, RecordingBlockDataSize, recordingFile);
int rSize = fread(buf, 1, RecordingBlockDataSize, recordingFile);
if (rSize != RecordingBlockDataSize)
{
recordingConLog(wxString::Format("[REC]: Error encountered when reading from file: Expected %d bytes, read %d instead.\n", RecordingBlockDataSize, rSize));
return false;
}
fseek(recordingFile, seek2, SEEK_SET);
fwrite(buf, 1, RecordingBlockDataSize, recordingFile);
rSize = fwrite(buf, 1, RecordingBlockDataSize, recordingFile);
if (rSize != RecordingBlockDataSize)
{
recordingConLog(wxString::Format("[REC]: Error encountered when writing to file: Expected %d bytes, wrote %d instead.\n", RecordingBlockDataSize, rSize));
return false;
}
}
long seek = GetBlockSeekPoint(frame) + RecordingBlockHeaderSize;
fseek(recordingFile, seek, SEEK_SET);
fwrite(key.buf, 1, RecordingBlockDataSize, recordingFile);
int rSize = fwrite(key.buf, 1, RecordingBlockDataSize, recordingFile);
if (rSize != RecordingBlockDataSize)
{
recordingConLog(wxString::Format("[REC]: Error encountered when writing to file: Expected %d bytes, wrote %d instead.\n", RecordingBlockDataSize, rSize));
return false;
}
MaxFrame++;
WriteMaxFrame();
fflush(recordingFile);
Expand All @@ -226,14 +251,20 @@ bool InputRecordingFile::InsertPadData(unsigned long frame, const PadData& key)
bool InputRecordingFile::UpdatePadData(unsigned long frame, const PadData& key)
{
if (recordingFile == NULL)
{
return false;
}
if (!key.fExistKey)
{
return false;
}

long seek = GetBlockSeekPoint(frame) + RecordingBlockHeaderSize;
fseek(recordingFile, seek, SEEK_SET);
if (fwrite(key.buf, 1, RecordingBlockDataSize, recordingFile) == 0)
{
return false;
}

fflush(recordingFile);
return true;
Expand Down

0 comments on commit 7955b42

Please sign in to comment.