Move code into Movie::SignalDiscChange

DVDInterface shouldn't need to know anything about
the DTM format's 40-character limitation.

Also replacing "filename" in variable names with "path"
to make it clearer which variables contain the whole path
and which ones only contain the filename.
This commit is contained in:
JosJuice 2016-08-21 12:51:14 +02:00
parent 0015d2e86b
commit 9f6000bb27
4 changed files with 32 additions and 28 deletions

View file

@ -460,48 +460,40 @@ static void EjectDiscCallback(u64 userdata, s64 cyclesLate)
static void InsertDiscCallback(u64 userdata, s64 cyclesLate)
{
std::string& SavedFileName = SConfig::GetInstance().m_strFilename;
std::string* _FileName = (std::string*)userdata;
const std::string& old_path = SConfig::GetInstance().m_strFilename;
std::string* new_path = reinterpret_cast<std::string*>(userdata);
if (!SetVolumeName(*_FileName))
if (!SetVolumeName(*new_path))
{
// Put back the old one
SetVolumeName(SavedFileName);
SetVolumeName(old_path);
PanicAlertT("Invalid file");
}
SetDiscInside(VolumeIsValid());
delete _FileName;
delete new_path;
}
// 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);
// The host thread is now temporarily the CPU thread
ChangeDiscAsCPU(newFileName);
ChangeDiscAsCPU(new_path);
Core::PauseAndLock(false, was_unpaused);
}
// 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(SystemTimers::GetTicksPerSecond(), s_insert_disc, (u64)_FileName);
if (Movie::IsRecordingInput())
{
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));
}
CoreTiming::ScheduleEvent(SystemTimers::GetTicksPerSecond(), s_insert_disc, new_path_pointer);
Movie::SignalDiscChange(new_path);
}
void SetLidOpen(bool open)

View file

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

View file

@ -415,10 +415,22 @@ void SetClearSave(bool 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())
{
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)

View file

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