Merge pull request #4138 from JosJuice/40-limit-out-of-di

Move code into Movie::SignalDiscChange
This commit is contained in:
Mat M
2016-09-18 22:54:48 -04:00
committed by GitHub
4 changed files with 32 additions and 28 deletions

View File

@ -457,48 +457,40 @@ static void EjectDiscCallback(u64 userdata, s64 cyclesLate)
static void InsertDiscCallback(u64 userdata, s64 cyclesLate) static void InsertDiscCallback(u64 userdata, s64 cyclesLate)
{ {
std::string& SavedFileName = SConfig::GetInstance().m_strFilename; const std::string& old_path = SConfig::GetInstance().m_strFilename;
std::string* _FileName = (std::string*)userdata; std::string* new_path = reinterpret_cast<std::string*>(userdata);
if (!SetVolumeName(*_FileName)) if (!SetVolumeName(*new_path))
{ {
// Put back the old one // Put back the old one
SetVolumeName(SavedFileName); SetVolumeName(old_path);
PanicAlertT("Invalid file"); PanicAlertT("Invalid file");
} }
SetDiscInside(VolumeIsValid()); SetDiscInside(VolumeIsValid());
delete _FileName; delete new_path;
} }
// Can only be called by the host thread // Can only be called by the host thread
void ChangeDiscAsHost(const std::string& newFileName) void ChangeDiscAsHost(const std::string& new_path)
{ {
bool was_unpaused = Core::PauseAndLock(true); bool was_unpaused = Core::PauseAndLock(true);
// The host thread is now temporarily the CPU thread // The host thread is now temporarily the CPU thread
ChangeDiscAsCPU(newFileName); ChangeDiscAsCPU(new_path);
Core::PauseAndLock(false, was_unpaused); Core::PauseAndLock(false, was_unpaused);
} }
// Can only be called by the CPU thread // Can only be called by the CPU thread
void ChangeDiscAsCPU(const std::string& newFileName) void ChangeDiscAsCPU(const std::string& new_path)
{ {
std::string* _FileName = new std::string(newFileName); // TODO: This is bad. Pointers in CoreTiming userdata require
// manual memory management and aren't savestate-safe.
u64 new_path_pointer = reinterpret_cast<u64>(new std::string(new_path));
CoreTiming::ScheduleEvent(0, s_eject_disc); CoreTiming::ScheduleEvent(0, s_eject_disc);
CoreTiming::ScheduleEvent(SystemTimers::GetTicksPerSecond(), s_insert_disc, (u64)_FileName); CoreTiming::ScheduleEvent(SystemTimers::GetTicksPerSecond(), s_insert_disc, new_path_pointer);
if (Movie::IsRecordingInput())
{ Movie::SignalDiscChange(new_path);
std::string fileName = newFileName;
auto sizeofpath = fileName.find_last_of("/\\") + 1;
if (fileName.substr(sizeofpath).length() > 40)
{
PanicAlertT("The disc change to \"%s\" could not be saved in the .dtm file.\n"
"The filename of the disc image must not be longer than 40 characters.",
newFileName.c_str());
}
Movie::SignalDiscChange(fileName.substr(sizeofpath));
}
} }
void SetLidOpen(bool open) void SetLidOpen(bool open)

View File

@ -108,8 +108,8 @@ bool VolumeIsValid();
// Disc detection and swapping // Disc detection and swapping
void SetDiscInside(bool _DiscInside); void SetDiscInside(bool _DiscInside);
bool IsDiscInside(); bool IsDiscInside();
void ChangeDiscAsHost(const std::string& path); // Can only be called by the host thread void ChangeDiscAsHost(const std::string& new_path); // Can only be called by the host thread
void ChangeDiscAsCPU(const std::string& path); // Can only be called by the CPU thread void ChangeDiscAsCPU(const std::string& new_path); // Can only be called by the CPU thread
// DVD Access Functions // DVD Access Functions
bool ChangePartition(u64 offset); bool ChangePartition(u64 offset);

View File

@ -415,10 +415,22 @@ void SetClearSave(bool enabled)
s_bClearSave = enabled; s_bClearSave = enabled;
} }
void SignalDiscChange(const std::string& new_disc_filename) void SignalDiscChange(const std::string& new_path)
{ {
s_discChange = new_disc_filename; if (Movie::IsRecordingInput())
s_bDiscChange = true; {
size_t size_of_path_without_filename = new_path.find_last_of("/\\") + 1;
std::string filename = new_path.substr(size_of_path_without_filename);
constexpr size_t maximum_length = sizeof(DTMHeader::discChange);
if (filename.length() > maximum_length)
{
PanicAlertT("The disc change to \"%s\" could not be saved in the .dtm file.\n"
"The filename of the disc image must not be longer than 40 characters.",
filename.c_str());
}
s_discChange = filename;
s_bDiscChange = true;
}
} }
void SetReset(bool reset) void SetReset(bool reset)

View File

@ -129,7 +129,7 @@ u64 GetCurrentLagCount();
u64 GetTotalLagCount(); u64 GetTotalLagCount();
void SetClearSave(bool enabled); void SetClearSave(bool enabled);
void SignalDiscChange(const std::string& new_disc_filename); void SignalDiscChange(const std::string& new_path);
void SetReset(bool reset); void SetReset(bool reset);
void SetTitleId(u64 title_id); void SetTitleId(u64 title_id);