DEV9: Do not save hdd size

This commit is contained in:
TheLastRar 2023-09-03 20:58:50 +01:00 committed by refractionpcsx2
parent 60154b7c26
commit 98eb006cdd
8 changed files with 80 additions and 110 deletions

View File

@ -259,7 +259,6 @@ DEV9SettingsWidget::DEV9SettingsWidget(SettingsDialog* dialog, QWidget* parent)
connect(m_ui.hddEnabled, QOverload<int>::of(&QCheckBox::stateChanged), this, &DEV9SettingsWidget::onHddEnabledChanged);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.hddEnabled, "DEV9/Hdd", "HddEnable", false);
connect(m_ui.hddFile, &QLineEdit::editingFinished, this, &DEV9SettingsWidget::onHddFileEdit);
if (m_dialog->isPerGameSettings())
{
m_ui.hddFile->setText(QString::fromUtf8(m_dialog->getStringValue("DEV9/Hdd", "HddFile", "").value().c_str()));
@ -267,32 +266,13 @@ DEV9SettingsWidget::DEV9SettingsWidget(SettingsDialog* dialog, QWidget* parent)
}
else
m_ui.hddFile->setText(QString::fromUtf8(m_dialog->getStringValue("DEV9/Hdd", "HddFile", "DEV9hdd.raw").value().c_str()));
UpdateHddSizeUIValues();
connect(m_ui.hddFile, &QLineEdit::textChanged, this, &DEV9SettingsWidget::onHddFileTextChange);
connect(m_ui.hddFile, &QLineEdit::editingFinished, this, &DEV9SettingsWidget::onHddFileEdit);
connect(m_ui.hddBrowseFile, &QPushButton::clicked, this, &DEV9SettingsWidget::onHddBrowseFileClicked);
//TODO: need a getUintValue for if 48bit support occurs
const int size = (u64)m_dialog->getIntValue("DEV9/Hdd", "HddSizeSectors", 0).value() * 512 / (1024 * 1024 * 1024);
if (m_dialog->isPerGameSettings())
{
std::optional<int> sizeOpt = std::nullopt;
if (size > 0)
sizeOpt = size;
const int sizeGlobal = (u64)Host::GetBaseIntSettingValue("DEV9/Hdd", "HddSizeSectors", 0) * 512 / (1024 * 1024 * 1024);
SettingWidgetBinder::SettingAccessor<QSpinBox>::makeNullableInt(m_ui.hddSizeSpinBox, sizeGlobal);
SettingWidgetBinder::SettingAccessor<QSpinBox>::setNullableIntValue(m_ui.hddSizeSpinBox, sizeOpt);
m_ui.hddSizeSlider->setValue(sizeOpt.value_or(sizeGlobal));
m_ui.hddSizeSlider->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_ui.hddSizeSlider, &QSlider::customContextMenuRequested, this, &DEV9SettingsWidget::onHddSizeSliderContext);
}
else
{
m_ui.hddSizeSlider->setValue(size);
SettingWidgetBinder::SettingAccessor<QSpinBox>::setIntValue(m_ui.hddSizeSpinBox, size);
}
connect(m_ui.hddSizeSlider, QOverload<int>::of(&QSlider::valueChanged), this, &DEV9SettingsWidget::onHddSizeSlide);
SettingWidgetBinder::SettingAccessor<QSpinBox>::connectValueChanged(m_ui.hddSizeSpinBox, [&]() { onHddSizeAccessorSpin(); });
@ -700,12 +680,9 @@ void DEV9SettingsWidget::onHddEnabledChanged(int state)
m_ui.hddFile->setEnabled(enabled);
m_ui.hddFileLabel->setEnabled(enabled);
m_ui.hddBrowseFile->setEnabled(enabled);
m_ui.hddSizeLabel->setEnabled(enabled);
m_ui.hddSizeSlider->setEnabled(enabled);
m_ui.hddSizeMaxLabel->setEnabled(enabled);
m_ui.hddSizeMinLabel->setEnabled(enabled);
m_ui.hddSizeSpinBox->setEnabled(enabled);
m_ui.hddCreate->setEnabled(enabled);
UpdateHddSizeUIEnabled();
}
void DEV9SettingsWidget::onHddBrowseFileClicked()
@ -722,85 +699,39 @@ void DEV9SettingsWidget::onHddBrowseFileClicked()
m_ui.hddFile->editingFinished();
}
void DEV9SettingsWidget::onHddFileTextChange()
{
UpdateHddSizeUIEnabled();
// Force update so user doesn't have to exit text box
std::string hddPath(m_ui.hddFile->text().toStdString());
if (hddPath.empty())
UpdateHddSizeUIValues();
}
void DEV9SettingsWidget::onHddFileEdit()
{
// Check if file exists, if so set HddSize to correct value.
// Also save the hddPath setting
std::string hddPath(m_ui.hddFile->text().toStdString());
if (hddPath.empty())
{
m_dialog->setStringSettingValue("DEV9/Hdd", "HddFile", std::nullopt);
return;
}
else
m_dialog->setStringSettingValue("DEV9/Hdd", "HddFile", hddPath.c_str());
if (!Path::IsAbsolute(hddPath))
hddPath = Path::Combine(EmuFolders::Settings, hddPath);
if (!FileSystem::FileExists(hddPath.c_str()))
return;
const s64 size = FileSystem::GetPathFileSize(hddPath.c_str());
if (size < 0)
return;
const u32 sizeSectors = static_cast<u32>(size / 512);
const int sizeGB = size / 1024 / 1024 / 1024;
QSignalBlocker sb1(m_ui.hddSizeSpinBox);
QSignalBlocker sb2(m_ui.hddSizeSlider);
m_ui.hddSizeSpinBox->setValue(sizeGB);
m_ui.hddSizeSlider->setValue(sizeGB);
m_dialog->setIntSettingValue("DEV9/Hdd", "HddSizeSectors", (int)sizeSectors);
UpdateHddSizeUIValues();
}
void DEV9SettingsWidget::onHddSizeSlide(int i)
{
// We have to call onHddSizeAccessorSpin() ourself, as the value could still be considered null when the valueChanged signal is fired
QSignalBlocker sb(m_ui.hddSizeSpinBox);
SettingWidgetBinder::SettingAccessor<QSpinBox>::setNullableIntValue(m_ui.hddSizeSpinBox, i);
onHddSizeAccessorSpin();
}
void DEV9SettingsWidget::onHddSizeSliderContext(const QPoint& pt)
{
QMenu menu(m_ui.hddSizeSlider);
connect(menu.addAction(qApp->translate("SettingWidgetBinder", "Reset")), &QAction::triggered, this, &DEV9SettingsWidget::onHddSizeSliderReset);
menu.exec(m_ui.hddSizeSlider->mapToGlobal(pt));
}
void DEV9SettingsWidget::onHddSizeSliderReset([[maybe_unused]] bool checked)
{
// We have to call onHddSizeAccessorSpin() ourself, as the value could still be considered non-null when the valueChanged signal is fired
QSignalBlocker sb(m_ui.hddSizeSpinBox);
SettingWidgetBinder::SettingAccessor<QSpinBox>::setNullableIntValue(m_ui.hddSizeSpinBox, std::nullopt);
onHddSizeAccessorSpin();
m_ui.hddSizeSpinBox->setValue(i);
}
void DEV9SettingsWidget::onHddSizeAccessorSpin()
{
//TODO: need a getUintValue for if 48bit support occurs
QSignalBlocker sb(m_ui.hddSizeSlider);
if (m_dialog->isPerGameSettings())
{
std::optional<int> new_value = SettingWidgetBinder::SettingAccessor<QSpinBox>::getNullableIntValue(m_ui.hddSizeSpinBox);
const int sizeGlobal = (u64)Host::GetBaseIntSettingValue("DEV9/Hdd", "HddSizeSectors", 0) * 512 / (1024 * 1024 * 1024);
m_ui.hddSizeSlider->setValue(new_value.value_or(sizeGlobal));
if (new_value.has_value())
m_dialog->setIntSettingValue("DEV9/Hdd", "HddSizeSectors", new_value.value() * (1024 * 1024 * 1024 / 512));
else
m_dialog->setIntSettingValue("DEV9/Hdd", "HddSizeSectors", std::nullopt);
}
else
{
const int new_value = SettingWidgetBinder::SettingAccessor<QSpinBox>::getIntValue(m_ui.hddSizeSpinBox);
m_ui.hddSizeSlider->setValue(new_value);
m_dialog->setIntSettingValue("DEV9/Hdd", "HddSizeSectors", new_value * (1024 * 1024 * 1024 / 512));
}
m_ui.hddSizeSlider->setValue(m_ui.hddSizeSpinBox->value());
}
void DEV9SettingsWidget::onHddCreateClicked()
@ -808,7 +739,8 @@ void DEV9SettingsWidget::onHddCreateClicked()
//Do the thing
std::string hddPath(m_ui.hddFile->text().toStdString());
u64 sizeBytes = (u64)m_dialog->getEffectiveIntValue("DEV9/Hdd", "HddSizeSectors", 0) * 512;
const u64 sizeBytes = (u64)m_ui.hddSizeSpinBox->value() * (u64)(1024 * 1024 * 1024);
if (sizeBytes == 0 || hddPath.empty())
{
QMessageBox::warning(this, QObject::tr("HDD Creator"),
@ -848,6 +780,49 @@ void DEV9SettingsWidget::onHddCreateClicked()
}
}
void DEV9SettingsWidget::UpdateHddSizeUIEnabled()
{
std::string hddPath(m_ui.hddFile->text().toStdString());
bool enableSizeUI;
if (m_dialog->isPerGameSettings() && hddPath.empty())
enableSizeUI = false;
else
enableSizeUI = m_ui.hddFile->isEnabled();
m_ui.hddSizeLabel->setEnabled(enableSizeUI);
m_ui.hddSizeSlider->setEnabled(enableSizeUI);
m_ui.hddSizeMaxLabel->setEnabled(enableSizeUI);
m_ui.hddSizeMinLabel->setEnabled(enableSizeUI);
m_ui.hddSizeSpinBox->setEnabled(enableSizeUI);
}
void DEV9SettingsWidget::UpdateHddSizeUIValues()
{
std::string hddPath(m_ui.hddFile->text().toStdString());
if (m_dialog->isPerGameSettings() && hddPath.empty())
hddPath = m_ui.hddFile->placeholderText().toStdString();
if (!Path::IsAbsolute(hddPath))
hddPath = Path::Combine(EmuFolders::Settings, hddPath);
if (!FileSystem::FileExists(hddPath.c_str()))
return;
const s64 size = FileSystem::GetPathFileSize(hddPath.c_str());
if (size < 0)
return;
const u32 sizeSectors = static_cast<u32>(size / 512);
const int sizeGB = size / 1024 / 1024 / 1024;
QSignalBlocker sb1(m_ui.hddSizeSpinBox);
QSignalBlocker sb2(m_ui.hddSizeSlider);
m_ui.hddSizeSpinBox->setValue(sizeGB);
m_ui.hddSizeSlider->setValue(sizeGB);
}
void DEV9SettingsWidget::showEvent(QShowEvent* event)
{
QWidget::showEvent(event);

View File

@ -47,12 +47,9 @@ private Q_SLOTS:
void onHddEnabledChanged(int state);
void onHddBrowseFileClicked();
void onHddFileTextChange();
void onHddFileEdit();
void onHddSizeSlide(int i);
// Per game only.
void onHddSizeSliderContext(const QPoint& pt);
void onHddSizeSliderReset(bool checked = false);
//
void onHddSizeAccessorSpin();
void onHddCreateClicked();
@ -73,6 +70,9 @@ private:
void AddNewHostConfig(const HostEntryUi& host);
void DeleteHostConfig(int index);
void UpdateHddSizeUIEnabled();
void UpdateHddSizeUIValues();
SettingsDialog* m_dialog;
Ui::DEV9SettingsWidget m_ui;

View File

@ -980,12 +980,6 @@ struct Pcsx2Config
bool HddEnable{false};
std::string HddFile;
/* The PS2's HDD max size is 2TB
* which is 2^32 * 512 byte sectors
* Note that we don't yet support
* 48bit LBA, so our limit is lower */
uint HddSizeSectors{40 * (1024 * 1024 * 1024 / 512)};
DEV9Options();
void LoadSave(SettingsWrapper& wrap);
@ -1011,8 +1005,7 @@ struct Pcsx2Config
OpEqu(EthHosts) &&
OpEqu(HddEnable) &&
OpEqu(HddFile) &&
OpEqu(HddSizeSectors);
OpEqu(HddFile);
}
bool operator!=(const DEV9Options& right) const

View File

@ -46,6 +46,11 @@ void ATA::WritePaddedString(u8* data, int* index, const std::string& value, u32
void ATA::CreateHDDinfo(u64 sizeSectors)
{
//PS2 is limited to 32bit size HDD (2TB), however,
//we don't yet support 48bit, so limit to 24bit size
constexpr u32 maxSize = 1 << 24;
sizeSectors = std::min<u32>(sizeSectors, maxSize);
constexpr u16 sectorSize = 512;
DevCon.WriteLn("DEV9: HddSize : %i", sizeSectors * sectorSize / (1024 * 1024));
const u64 nbSectors = sizeSectors;

View File

@ -54,8 +54,6 @@ int ATA::Open(const std::string& hddPath)
readBufferLen = 256 * 512;
readBuffer = new u8[readBufferLen];
CreateHDDinfo(EmuConfig.DEV9.HddSizeSectors);
//Open File
if (!FileSystem::FileExists(hddPath.c_str()))
return -1;
@ -68,8 +66,9 @@ int ATA::Open(const std::string& hddPath)
return -1;
}
//Store HddImage size for later check
//Store HddImage size for later use
hddImageSize = static_cast<u64>(size);
CreateHDDinfo(hddImageSize / 512);
InitSparseSupport(hddPath);
@ -560,7 +559,7 @@ bool ATA::HDD_CanSeek()
bool ATA::HDD_CanAccess(int* sectors)
{
s64 maxLBA = std::min<s64>(EmuConfig.DEV9.HddSizeSectors, hddImageSize / 512) - 1;
s64 maxLBA = hddImageSize / 512 - 1;
if ((regSelect & 0x40) == 0) //CHS mode
maxLBA = std::min<s64>(maxLBA, curCylinders * curHeads * curSectors);

View File

@ -73,7 +73,7 @@ void ATA::HDD_IdentifyDevice()
DevCon.WriteLn("DEV9: HddidentifyDevice");
//IDE transfer start
CreateHDDinfo(EmuConfig.DEV9.HddSizeSectors);
CreateHDDinfo(hddImageSize / 512);
pioDRQEndTransferFunc = nullptr;
DRQCmdPIODataToHost(identifyData, 256 * 2, 0, 256 * 2, true);

View File

@ -1054,8 +1054,7 @@ void DEV9CheckChanges(const Pcsx2Config& old_config)
{
//ATA::Open/Close dosn't set any regs
//So we can close/open to apply settings
if (EmuConfig.DEV9.HddFile != old_config.DEV9.HddFile ||
EmuConfig.DEV9.HddSizeSectors != old_config.DEV9.HddSizeSectors)
if (EmuConfig.DEV9.HddFile != old_config.DEV9.HddFile)
{
dev9.ata->Close();
if (dev9.ata->Open(hddPath) != 0)

View File

@ -1089,7 +1089,6 @@ void Pcsx2Config::DEV9Options::LoadSave(SettingsWrapper& wrap)
SettingsWrapSection("DEV9/Hdd");
SettingsWrapEntry(HddEnable);
SettingsWrapEntry(HddFile);
SettingsWrapEntry(HddSizeSectors);
}
}