2016-09-06 00:03:02 +01:00
|
|
|
#include "VfsDevice.h"
|
|
|
|
#include "AppConfig.h"
|
|
|
|
#include "PS2VM_Preferences.h"
|
|
|
|
#include "vfsdiscselectordialog.h"
|
|
|
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QStorageInfo>
|
|
|
|
|
|
|
|
///////////////////////////////////////////
|
|
|
|
//CDirectoryDevice Implementation
|
|
|
|
///////////////////////////////////////////
|
|
|
|
|
2018-01-09 11:42:02 -05:00
|
|
|
CDirectoryDevice::CDirectoryDevice(const char* name, const char* preference)
|
2016-09-06 00:03:02 +01:00
|
|
|
{
|
2018-01-09 11:42:02 -05:00
|
|
|
m_name = name;
|
|
|
|
m_preference = preference;
|
|
|
|
m_value = CAppConfig::GetInstance().GetPreferenceString(preference);
|
2016-09-06 00:03:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* CDirectoryDevice::GetDeviceName()
|
|
|
|
{
|
2018-01-09 11:42:02 -05:00
|
|
|
return m_name;
|
2016-09-06 00:03:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* CDirectoryDevice::GetBindingType()
|
|
|
|
{
|
2017-12-21 18:21:44 -05:00
|
|
|
return "Directory";
|
2016-09-06 00:03:02 +01:00
|
|
|
}
|
|
|
|
|
2018-01-09 11:49:01 -05:00
|
|
|
std::string CDirectoryDevice::GetBinding()
|
2016-09-06 00:03:02 +01:00
|
|
|
{
|
2018-01-09 11:49:01 -05:00
|
|
|
return m_value;
|
2016-09-06 00:03:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDirectoryDevice::Save()
|
|
|
|
{
|
2018-01-09 11:42:02 -05:00
|
|
|
CAppConfig::GetInstance().SetPreferenceString(m_preference, m_value.c_str());
|
2016-09-06 00:03:02 +01:00
|
|
|
}
|
|
|
|
|
2017-12-21 18:21:44 -05:00
|
|
|
bool CDirectoryDevice::RequestModification(QWidget* parent)
|
2016-09-06 00:03:02 +01:00
|
|
|
{
|
2017-12-21 18:21:44 -05:00
|
|
|
QFileDialog dialog(parent);
|
|
|
|
dialog.setFileMode(QFileDialog::Directory);
|
|
|
|
dialog.setOption(QFileDialog::ShowDirsOnly);
|
|
|
|
dialog.setOption(QFileDialog::DontResolveSymlinks);
|
|
|
|
if(dialog.exec())
|
|
|
|
{
|
|
|
|
QString fileName = dialog.selectedFiles().first();
|
2018-01-09 11:42:02 -05:00
|
|
|
m_value = fileName.toStdString();
|
2017-12-21 18:21:44 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-06 00:03:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////
|
|
|
|
//CCdrom0Device Implementation
|
|
|
|
///////////////////////////////////////////
|
|
|
|
|
|
|
|
CCdrom0Device::CCdrom0Device()
|
|
|
|
{
|
2018-01-15 14:14:59 -05:00
|
|
|
auto path = CAppConfig::GetInstance().GetPreferencePath(PREF_PS2_CDROM0_PATH);
|
2018-01-09 14:24:20 -05:00
|
|
|
auto pathString = QString(path.native().c_str());
|
2017-12-21 18:21:44 -05:00
|
|
|
//Detect the binding type from the path format
|
2018-01-09 11:48:27 -05:00
|
|
|
if(
|
2018-01-09 14:24:20 -05:00
|
|
|
pathString.startsWith("\\\\.\\", Qt::CaseInsensitive) ||
|
|
|
|
pathString.startsWith("/dev/", Qt::CaseInsensitive))
|
2017-12-21 18:21:44 -05:00
|
|
|
{
|
2018-01-09 11:42:02 -05:00
|
|
|
m_bindingType = CCdrom0Device::BINDING_PHYSICAL;
|
2017-12-21 18:21:44 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-09 11:42:02 -05:00
|
|
|
m_bindingType = CCdrom0Device::BINDING_IMAGE;
|
2017-12-21 18:21:44 -05:00
|
|
|
}
|
2018-01-09 14:24:20 -05:00
|
|
|
m_imagePath = path.native();
|
2016-09-06 00:03:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* CCdrom0Device::GetDeviceName()
|
|
|
|
{
|
2017-12-21 18:21:44 -05:00
|
|
|
return "cdrom0";
|
2016-09-06 00:03:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* CCdrom0Device::GetBindingType()
|
|
|
|
{
|
2018-01-09 11:42:02 -05:00
|
|
|
if(m_bindingType == CCdrom0Device::BINDING_PHYSICAL)
|
2017-12-21 18:21:44 -05:00
|
|
|
{
|
|
|
|
return "Physical Device";
|
|
|
|
}
|
2018-01-09 11:42:02 -05:00
|
|
|
if(m_bindingType == CCdrom0Device::BINDING_IMAGE)
|
2017-12-21 18:21:44 -05:00
|
|
|
{
|
|
|
|
return "Disk Image";
|
|
|
|
}
|
|
|
|
return "";
|
2016-09-06 00:03:02 +01:00
|
|
|
}
|
|
|
|
|
2018-01-09 11:49:01 -05:00
|
|
|
std::string CCdrom0Device::GetBinding()
|
2016-09-06 00:03:02 +01:00
|
|
|
{
|
2018-01-09 11:42:02 -05:00
|
|
|
if(m_imagePath.empty())
|
2017-12-21 18:21:44 -05:00
|
|
|
{
|
|
|
|
return "(None)";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-09 11:49:01 -05:00
|
|
|
return m_imagePath;
|
2017-12-21 18:21:44 -05:00
|
|
|
}
|
2016-09-06 00:03:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCdrom0Device::Save()
|
|
|
|
{
|
2018-01-15 14:14:59 -05:00
|
|
|
CAppConfig::GetInstance().SetPreferencePath(PREF_PS2_CDROM0_PATH, m_imagePath);
|
2016-09-06 00:03:02 +01:00
|
|
|
}
|
|
|
|
|
2017-12-21 18:21:44 -05:00
|
|
|
bool CCdrom0Device::RequestModification(QWidget* parent)
|
2016-09-06 00:03:02 +01:00
|
|
|
{
|
2018-01-09 11:42:02 -05:00
|
|
|
auto vfsds = new VFSDiscSelectorDialog(m_imagePath, m_bindingType, parent);
|
2017-12-21 18:21:44 -05:00
|
|
|
VFSDiscSelectorDialog::connect(vfsds, &VFSDiscSelectorDialog::onFinish, [=](QString res, BINDINGTYPE type) {
|
2018-01-09 11:42:02 -05:00
|
|
|
m_bindingType = type;
|
|
|
|
m_imagePath = res.toStdString();
|
2017-12-21 18:21:44 -05:00
|
|
|
});
|
2018-01-09 11:42:02 -05:00
|
|
|
bool res = QDialog::Accepted == vfsds->exec();
|
2017-12-21 18:21:44 -05:00
|
|
|
delete vfsds;
|
|
|
|
return res;
|
2016-09-06 00:03:02 +01:00
|
|
|
}
|