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>
|
2018-09-24 13:01:30 -04:00
|
|
|
#include "QStringUtils.h"
|
2016-09-06 00:03:02 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////
|
|
|
|
//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;
|
2018-09-24 13:01:30 -04:00
|
|
|
m_value = CAppConfig::GetInstance().GetPreferencePath(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-09-24 13:01:30 -04:00
|
|
|
QString CDirectoryDevice::GetBinding()
|
2016-09-06 00:03:02 +01:00
|
|
|
{
|
2018-09-24 13:01:30 -04:00
|
|
|
return PathToQString(m_value);
|
2016-09-06 00:03:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDirectoryDevice::Save()
|
|
|
|
{
|
2018-01-15 16:57:42 -05:00
|
|
|
CAppConfig::GetInstance().SetPreferencePath(m_preference, m_value);
|
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);
|
2017-12-21 18:21:44 -05:00
|
|
|
//Detect the binding type from the path format
|
|
|
|
{
|
2018-09-24 13:01:30 -04:00
|
|
|
auto pathString = PathToQString(path);
|
|
|
|
if(
|
2018-09-25 14:21:39 -04:00
|
|
|
pathString.startsWith("\\\\.\\", Qt::CaseInsensitive) ||
|
2019-10-03 13:26:13 +01:00
|
|
|
pathString.startsWith("\\\\?\\", Qt::CaseInsensitive) ||
|
2018-09-25 14:21:39 -04:00
|
|
|
pathString.startsWith("/dev/", Qt::CaseInsensitive))
|
2018-09-24 13:01:30 -04:00
|
|
|
{
|
|
|
|
m_bindingType = CCdrom0Device::BINDING_PHYSICAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_bindingType = CCdrom0Device::BINDING_IMAGE;
|
|
|
|
}
|
2017-12-21 18:21:44 -05:00
|
|
|
}
|
2018-09-24 13:01:30 -04:00
|
|
|
m_imagePath = path;
|
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-09-24 13:01:30 -04:00
|
|
|
QString 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-09-24 13:01:30 -04:00
|
|
|
return PathToQString(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
|
|
|
}
|