mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-26 23:55:40 +00:00
Qt: Add option to create non-existant memory cards on edit
This commit is contained in:
parent
84fe9aae0e
commit
b2e8aa2d30
|
@ -1505,6 +1505,22 @@ void MainWindow::onCheckForUpdatesActionTriggered()
|
|||
|
||||
void MainWindow::openMemoryCardEditor(const QString& card_a_path, const QString& card_b_path)
|
||||
{
|
||||
for (const QString& card_path : {card_a_path, card_b_path})
|
||||
{
|
||||
if (!card_path.isEmpty() && !QFile::exists(card_path))
|
||||
{
|
||||
if (QMessageBox::question(
|
||||
this, tr("Memory Card Not Found"),
|
||||
tr("Memory card '%1' does not exist. Do you want to create an empty memory card?").arg(card_path),
|
||||
QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
|
||||
{
|
||||
if (!MemoryCardEditorDialog::createMemoryCard(card_path))
|
||||
QMessageBox::critical(this, tr("Memory Card Not Found"),
|
||||
tr("Failed to create memory card '%1'").arg(card_path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_memory_card_editor_dialog)
|
||||
{
|
||||
m_memory_card_editor_dialog = new MemoryCardEditorDialog(this);
|
||||
|
|
|
@ -44,9 +44,17 @@ MemoryCardEditorDialog::~MemoryCardEditorDialog() = default;
|
|||
|
||||
bool MemoryCardEditorDialog::setCardA(const QString& path)
|
||||
{
|
||||
const int index = m_ui.cardAPath->findData(QVariant(QDir::toNativeSeparators(path)));
|
||||
int index = m_ui.cardAPath->findData(QVariant(QDir::toNativeSeparators(path)));
|
||||
if (index < 0)
|
||||
return false;
|
||||
{
|
||||
QFileInfo file(path);
|
||||
if (!file.exists())
|
||||
return false;
|
||||
|
||||
QSignalBlocker sb(m_card_a.path_cb);
|
||||
m_card_a.path_cb->addItem(file.baseName(), QVariant(path));
|
||||
index = m_card_a.path_cb->count() - 1;
|
||||
}
|
||||
|
||||
m_ui.cardAPath->setCurrentIndex(index);
|
||||
return true;
|
||||
|
@ -54,14 +62,30 @@ bool MemoryCardEditorDialog::setCardA(const QString& path)
|
|||
|
||||
bool MemoryCardEditorDialog::setCardB(const QString& path)
|
||||
{
|
||||
const int index = m_ui.cardBPath->findData(QVariant(QDir::toNativeSeparators(path)));
|
||||
int index = m_ui.cardBPath->findData(QVariant(QDir::toNativeSeparators(path)));
|
||||
if (index < 0)
|
||||
return false;
|
||||
{
|
||||
QFileInfo file(path);
|
||||
if (!file.exists())
|
||||
return false;
|
||||
|
||||
QSignalBlocker sb(m_card_b.path_cb);
|
||||
m_card_b.path_cb->addItem(file.baseName(), QVariant(path));
|
||||
index = m_card_b.path_cb->count() - 1;
|
||||
}
|
||||
|
||||
m_ui.cardBPath->setCurrentIndex(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MemoryCardEditorDialog::createMemoryCard(const QString& path)
|
||||
{
|
||||
MemoryCardImage::DataArray data;
|
||||
MemoryCardImage::Format(&data);
|
||||
|
||||
return MemoryCardImage::SaveToFile(data, path.toUtf8().constData());
|
||||
}
|
||||
|
||||
void MemoryCardEditorDialog::resizeEvent(QResizeEvent* ev)
|
||||
{
|
||||
QtUtils::ResizeColumnsForTableView(m_card_a.table, {32, -1, 155, 45});
|
||||
|
|
|
@ -18,6 +18,8 @@ public:
|
|||
bool setCardA(const QString& path);
|
||||
bool setCardB(const QString& path);
|
||||
|
||||
static bool createMemoryCard(const QString& path);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent* ev);
|
||||
void closeEvent(QCloseEvent* ev);
|
||||
|
|
Loading…
Reference in a new issue