Skip to content

Commit

Permalink
input-rec: remove private InputRecordingFile::open()
Browse files Browse the repository at this point in the history
The code that gets ran by each branch differs enough that just moving them into openNew() & openExisting() is more beneficial. Removes the unnecessary runtime boolean check.
  • Loading branch information
sonicfind authored and refractionpcsx2 committed Nov 27, 2022
1 parent 7bab2d1 commit b862416
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 deletions.
50 changes: 22 additions & 28 deletions pcsx2/Recording/InputRecordingFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,45 +314,39 @@ void InputRecordingFile::IncrementUndoCount()
fwrite(&m_undoCount, 4, 1, m_recordingFile);
}

bool InputRecordingFile::open(const std::string_view& path, bool newRecording)
bool InputRecordingFile::OpenNew(const std::string& path, bool fromSavestate)
{
if (newRecording)
{
if ((m_recordingFile = FileSystem::OpenCFile(path.data(), "wb+")) != nullptr)
{
m_filename = path;
m_totalFrames = 0;
m_undoCount = 0;
m_header.Init();
return true;
}
}
else if ((m_recordingFile = FileSystem::OpenCFile(path.data(), "rb+")) != nullptr)
if ((m_recordingFile = FileSystem::OpenCFile(path.data(), "wb+")) == nullptr)
{
if (verifyRecordingFileHeader())
{
m_filename = path;
return true;
}
Close();
InputRec::consoleLog("Input recording file m_header is invalid");
InputRec::consoleLog(fmt::format("Input recording file opening failed. Error - {}", strerror(errno)));
return false;
}
InputRec::consoleLog(fmt::format("Input recording file opening failed. Error - {}", strerror(errno)));
return false;
}

bool InputRecordingFile::OpenNew(const std::string& path, bool fromSavestate)
{
if (!open(path, true))
return false;
m_filename = path;
m_totalFrames = 0;
m_undoCount = 0;
m_header.Init();
m_savestate.fromSavestate = fromSavestate;
return true;
}

bool InputRecordingFile::OpenExisting(const std::string& path)
{
return open(path, false);
if ((m_recordingFile = FileSystem::OpenCFile(path.data(), "rb+")) == nullptr)
{
InputRec::consoleLog(fmt::format("Input recording file opening failed. Error - {}", strerror(errno)));
return false;
}

if (!verifyRecordingFileHeader())
{
Close();
InputRec::consoleLog("Input recording file header is invalid");
return false;
}

m_filename = path;
return true;
}

bool InputRecordingFile::ReadKeyBuffer(u8& result, const uint frame, const uint port, const uint bufIndex)
Expand Down
1 change: 0 additions & 1 deletion pcsx2/Recording/InputRecordingFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ class InputRecordingFile

// Calculates the position of the current frame in the input recording
size_t getRecordingBlockSeekPoint(const long frame) const noexcept;
bool open(const std::string_view& path, bool newRecording);
bool verifyRecordingFileHeader();
};

Expand Down

0 comments on commit b862416

Please sign in to comment.