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
|
|
|
|
///////////////////////////////////////////
|
|
|
|
|
|
|
|
CDirectoryDevice::CDirectoryDevice(const char* sName, const char* sPreference)
|
|
|
|
{
|
2017-12-21 18:21:44 -05:00
|
|
|
m_sName = sName;
|
|
|
|
m_sPreference = sPreference;
|
|
|
|
m_sValue = CAppConfig::GetInstance().GetPreferenceString(m_sPreference);
|
2016-09-06 00:03:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* CDirectoryDevice::GetDeviceName()
|
|
|
|
{
|
2017-12-21 18:21:44 -05:00
|
|
|
return m_sName;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
const char* CDirectoryDevice::GetBinding()
|
|
|
|
{
|
2017-12-21 18:21:44 -05:00
|
|
|
return m_sValue.c_str();
|
2016-09-06 00:03:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDirectoryDevice::Save()
|
|
|
|
{
|
2017-12-21 18:21:44 -05:00
|
|
|
CAppConfig::GetInstance().SetPreferenceString(m_sPreference, m_sValue.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();
|
|
|
|
m_sValue = fileName.toStdString();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-06 00:03:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////
|
|
|
|
//CCdrom0Device Implementation
|
|
|
|
///////////////////////////////////////////
|
|
|
|
|
|
|
|
CCdrom0Device::CCdrom0Device()
|
|
|
|
{
|
2017-12-21 18:21:44 -05:00
|
|
|
const char* sPath = CAppConfig::GetInstance().GetPreferenceString(PS2VM_CDROM0PATH);
|
|
|
|
|
|
|
|
//Detect the binding type from the path format
|
|
|
|
QString m_sPath(sPath);
|
|
|
|
if(m_sPath.startsWith("\\\\.\\", Qt::CaseInsensitive) || m_sPath.startsWith("/dev/", Qt::CaseInsensitive))
|
|
|
|
{
|
|
|
|
m_nBindingType = CCdrom0Device::BINDING_PHYSICAL;
|
|
|
|
m_sImagePath = sPath;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_nBindingType = CCdrom0Device::BINDING_IMAGE;
|
|
|
|
if(!strcmp(sPath, ""))
|
|
|
|
{
|
|
|
|
m_sImagePath = "";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_sImagePath = sPath;
|
|
|
|
}
|
|
|
|
}
|
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()
|
|
|
|
{
|
2017-12-21 18:21:44 -05:00
|
|
|
if(m_nBindingType == CCdrom0Device::BINDING_PHYSICAL)
|
|
|
|
{
|
|
|
|
return "Physical Device";
|
|
|
|
}
|
|
|
|
if(m_nBindingType == CCdrom0Device::BINDING_IMAGE)
|
|
|
|
{
|
|
|
|
return "Disk Image";
|
|
|
|
}
|
|
|
|
return "";
|
2016-09-06 00:03:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* CCdrom0Device::GetBinding()
|
|
|
|
{
|
2017-12-21 18:21:44 -05:00
|
|
|
if(m_sImagePath.length() == 0)
|
|
|
|
{
|
|
|
|
return "(None)";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return m_sImagePath.c_str();
|
|
|
|
}
|
2016-09-06 00:03:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCdrom0Device::Save()
|
|
|
|
{
|
2017-12-21 18:21:44 -05:00
|
|
|
CAppConfig::GetInstance().SetPreferenceString(PS2VM_CDROM0PATH, m_sImagePath.c_str());
|
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
|
|
|
{
|
2017-12-21 18:21:44 -05:00
|
|
|
bool res = false;
|
|
|
|
auto vfsds = new VFSDiscSelectorDialog(m_sImagePath, m_nBindingType, parent);
|
|
|
|
VFSDiscSelectorDialog::connect(vfsds, &VFSDiscSelectorDialog::onFinish, [=](QString res, BINDINGTYPE type) {
|
|
|
|
m_nBindingType = type;
|
|
|
|
m_sImagePath = res.toStdString();
|
|
|
|
});
|
|
|
|
res = QDialog::Accepted == vfsds->exec();
|
|
|
|
delete vfsds;
|
|
|
|
return res;
|
2016-09-06 00:03:02 +01:00
|
|
|
}
|