DVDInterface: Replace SetVolume functions

It's better to just let the calling code provide a volume
object instead of needing one SetVolume for each way of
creating a volume. This simplifies InsertDiscCallback and
is needed for the following commits.
This commit is contained in:
JosJuice 2016-09-24 12:29:13 +02:00
parent 460459fb7d
commit 807e242d05
3 changed files with 25 additions and 39 deletions

View File

@ -37,6 +37,7 @@
#include "DiscIO/Enums.h"
#include "DiscIO/NANDContentLoader.h"
#include "DiscIO/Volume.h"
#include "DiscIO/VolumeCreator.h"
bool CBoot::DVDRead(u64 dvd_offset, u32 output_address, u32 length, bool decrypt)
{
@ -277,7 +278,7 @@ bool CBoot::BootUp()
{
case SConfig::BOOT_ISO:
{
DVDInterface::SetVolumeName(_StartupPara.m_strFilename);
DVDInterface::SetDisc(DiscIO::CreateVolumeFromFilename(_StartupPara.m_strFilename));
if (!DVDInterface::IsDiscInside())
return false;
@ -333,13 +334,14 @@ bool CBoot::BootUp()
if (!_StartupPara.m_strDVDRoot.empty())
{
NOTICE_LOG(BOOT, "Setting DVDRoot %s", _StartupPara.m_strDVDRoot.c_str());
DVDInterface::SetVolumeDirectory(_StartupPara.m_strDVDRoot, dolWii,
_StartupPara.m_strApploader, _StartupPara.m_strFilename);
DVDInterface::SetDisc(DiscIO::CreateVolumeFromDirectory(_StartupPara.m_strDVDRoot, dolWii,
_StartupPara.m_strApploader,
_StartupPara.m_strFilename));
}
else if (!_StartupPara.m_strDefaultISO.empty())
{
NOTICE_LOG(BOOT, "Loading default ISO %s", _StartupPara.m_strDefaultISO.c_str());
DVDInterface::SetVolumeName(_StartupPara.m_strDefaultISO);
DVDInterface::SetDisc(DiscIO::CreateVolumeFromFilename(_StartupPara.m_strDefaultISO));
}
if (!EmulatedBS2(dolWii))
@ -369,12 +371,13 @@ bool CBoot::BootUp()
if (!_StartupPara.m_strDVDRoot.empty())
{
NOTICE_LOG(BOOT, "Setting DVDRoot %s", _StartupPara.m_strDVDRoot.c_str());
DVDInterface::SetVolumeDirectory(_StartupPara.m_strDVDRoot, _StartupPara.bWii);
DVDInterface::SetDisc(
DiscIO::CreateVolumeFromDirectory(_StartupPara.m_strDVDRoot, _StartupPara.bWii));
}
else if (!_StartupPara.m_strDefaultISO.empty())
{
NOTICE_LOG(BOOT, "Loading default ISO %s", _StartupPara.m_strDefaultISO.c_str());
DVDInterface::SetVolumeName(_StartupPara.m_strDefaultISO);
DVDInterface::SetDisc(DiscIO::CreateVolumeFromFilename(_StartupPara.m_strDefaultISO));
}
// Poor man's bootup
@ -409,9 +412,9 @@ bool CBoot::BootUp()
// load default image or create virtual drive from directory
if (!_StartupPara.m_strDVDRoot.empty())
DVDInterface::SetVolumeDirectory(_StartupPara.m_strDVDRoot, true);
DVDInterface::SetDisc(DiscIO::CreateVolumeFromDirectory(_StartupPara.m_strDVDRoot, true));
else if (!_StartupPara.m_strDefaultISO.empty())
DVDInterface::SetVolumeName(_StartupPara.m_strDefaultISO);
DVDInterface::SetDisc(DiscIO::CreateVolumeFromFilename(_StartupPara.m_strDefaultISO));
break;

View File

@ -456,32 +456,20 @@ void Shutdown()
FileMonitor::SetFileSystem(nullptr);
}
void SetDisc(std::unique_ptr<DiscIO::IVolume> disc)
{
DVDThread::WaitUntilIdle();
s_inserted_volume = std::move(disc);
FileMonitor::SetFileSystem(s_inserted_volume.get());
SetLidOpen();
}
const DiscIO::IVolume& GetVolume()
{
_assert_(IsDiscInside());
return *s_inserted_volume;
}
bool SetVolumeName(const std::string& disc_path)
{
DVDThread::WaitUntilIdle();
s_inserted_volume = DiscIO::CreateVolumeFromFilename(disc_path);
FileMonitor::SetFileSystem(s_inserted_volume.get());
SetLidOpen();
return IsDiscInside();
}
bool SetVolumeDirectory(const std::string& full_path, bool is_wii,
const std::string& apploader_path, const std::string& DOL_path)
{
DVDThread::WaitUntilIdle();
s_inserted_volume =
DiscIO::CreateVolumeFromDirectory(full_path, is_wii, apploader_path, DOL_path);
FileMonitor::SetFileSystem(s_inserted_volume.get());
SetLidOpen();
return IsDiscInside();
}
bool IsDiscInside()
{
return s_inserted_volume != nullptr;
@ -501,16 +489,13 @@ static void EjectDiscCallback(u64 userdata, s64 cyclesLate)
static void InsertDiscCallback(u64 userdata, s64 cyclesLate)
{
const std::string& old_path = SConfig::GetInstance().m_strFilename;
std::unique_ptr<DiscIO::IVolume> new_volume =
DiscIO::CreateVolumeFromFilename(s_disc_path_to_insert);
if (!SetVolumeName(s_disc_path_to_insert))
{
// Put back the old one
SetVolumeName(old_path);
if (new_volume)
SetDisc(std::move(new_volume));
else
PanicAlertT("The disc that was about to be inserted couldn't be found.");
}
s_disc_path_to_insert.clear();
}
// Can only be called by the host thread

View File

@ -109,10 +109,8 @@ void DoState(PointerWrap& p);
void RegisterMMIO(MMIO::Mapping* mmio, u32 base);
// Disc access (don't call GetVolume unless you know that IsDiscInside() == true)
void SetDisc(std::unique_ptr<DiscIO::IVolume> disc);
const DiscIO::IVolume& GetVolume();
bool SetVolumeName(const std::string& disc_path);
bool SetVolumeDirectory(const std::string& disc_path, bool is_wii,
const std::string& apploader_path = "", const std::string& DOL_path = "");
bool IsDiscInside();
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