summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorMat M <mathew1800@gmail.com>2016-09-18 22:54:48 -0400
committerGitHub <noreply@github.com>2016-09-18 22:54:48 -0400
commit04e6aaf419feb18e7b2f2be19aabd4b34660ce31 (patch)
treedbacfaba9a160a69f6f56fb62d6db668f8f36452 /Source
parent9e1cfbee0e78338109d44349f9afce56ad29a941 (diff)
parent9f6000bb2728f7078210f30f9d7645cf5f086a35 (diff)
Merge pull request #4138 from JosJuice/40-limit-out-of-di
Move code into Movie::SignalDiscChange
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/Core/HW/DVDInterface.cpp36
-rw-r--r--Source/Core/Core/HW/DVDInterface.h4
-rw-r--r--Source/Core/Core/Movie.cpp18
-rw-r--r--Source/Core/Core/Movie.h2
4 files changed, 32 insertions, 28 deletions
diff --git a/Source/Core/Core/HW/DVDInterface.cpp b/Source/Core/Core/HW/DVDInterface.cpp
index ad3236d1b0..3599634e8e 100644
--- a/Source/Core/Core/HW/DVDInterface.cpp
+++ b/Source/Core/Core/HW/DVDInterface.cpp
@@ -457,48 +457,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)
diff --git a/Source/Core/Core/HW/DVDInterface.h b/Source/Core/Core/HW/DVDInterface.h
index 640afe1d84..e67e30ea9a 100644
--- a/Source/Core/Core/HW/DVDInterface.h
+++ b/Source/Core/Core/HW/DVDInterface.h
@@ -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);
diff --git a/Source/Core/Core/Movie.cpp b/Source/Core/Core/Movie.cpp
index c32ead6fa6..72642f8a51 100644
--- a/Source/Core/Core/Movie.cpp
+++ b/Source/Core/Core/Movie.cpp
@@ -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;
- s_bDiscChange = true;
+ 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)
diff --git a/Source/Core/Core/Movie.h b/Source/Core/Core/Movie.h
index 8bb31461e3..f21745464e 100644
--- a/Source/Core/Core/Movie.h
+++ b/Source/Core/Core/Movie.h
@@ -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);