Merge pull request #913 from lioncash/movie-func

Core: Break movie header validity checking into a function
This commit is contained in:
Pierre Bourdon 2014-08-31 06:55:04 +02:00
commit ea7eee1f58
1 changed files with 10 additions and 5 deletions

View File

@ -103,6 +103,14 @@ static void EnsureTmpInputSize(size_t bound)
tmpInput = newTmpInput; tmpInput = newTmpInput;
} }
static bool IsMovieHeader(u8 magic[4])
{
return magic[0] == 'D' &&
magic[1] == 'T' &&
magic[2] == 'M' &&
magic[3] == 0x1A;
}
std::string GetInputDisplay() std::string GetInputDisplay()
{ {
if (!IsPlayingInput() && !IsRecordingInput()) if (!IsPlayingInput() && !IsRecordingInput())
@ -730,10 +738,7 @@ bool PlayInput(const std::string& filename)
g_recordfd.ReadArray(&tmpHeader, 1); g_recordfd.ReadArray(&tmpHeader, 1);
if (tmpHeader.filetype[0] != 'D' || if (!IsMovieHeader(tmpHeader.filetype))
tmpHeader.filetype[1] != 'T' ||
tmpHeader.filetype[2] != 'M' ||
tmpHeader.filetype[3] != 0x1A)
{ {
PanicAlertT("Invalid recording file"); PanicAlertT("Invalid recording file");
goto cleanup; goto cleanup;
@ -801,7 +806,7 @@ void LoadInput(const std::string& filename)
t_record.ReadArray(&tmpHeader, 1); t_record.ReadArray(&tmpHeader, 1);
if (tmpHeader.filetype[0] != 'D' || tmpHeader.filetype[1] != 'T' || tmpHeader.filetype[2] != 'M' || tmpHeader.filetype[3] != 0x1A) if (!IsMovieHeader(tmpHeader.filetype))
{ {
PanicAlertT("Savestate movie %s is corrupted, movie recording stopping...", filename.c_str()); PanicAlertT("Savestate movie %s is corrupted, movie recording stopping...", filename.c_str());
EndPlayInput(false); EndPlayInput(false);