Qt/GCMemcardManager: Properly perform actions and do error checking

This commit is contained in:
spycrab 2018-05-12 21:05:47 +02:00
parent 8b3358e208
commit 229c92d0bf
1 changed files with 20 additions and 8 deletions

View File

@ -321,7 +321,13 @@ void GCMemcardManager::ImportFile()
if (path.isEmpty()) if (path.isEmpty())
return; return;
m_slot_memcard[m_active_slot]->ImportGci(path.toStdString(), ""); const auto result = m_slot_memcard[m_active_slot]->ImportGci(path.toStdString(), "");
if (result != SUCCESS)
{
QMessageBox::critical(this, tr("Import failed"), tr("Failed to import \"%1\".").arg(path));
return;
}
if (!m_slot_memcard[m_active_slot]->Save()) if (!m_slot_memcard[m_active_slot]->Save())
PanicAlertT("File write failed"); PanicAlertT("File write failed");
@ -341,14 +347,19 @@ void GCMemcardManager::CopyFiles()
auto sel = selection[i * m_slot_table[m_active_slot]->columnCount()]; auto sel = selection[i * m_slot_table[m_active_slot]->columnCount()];
int file_index = memcard->GetFileIndex(m_slot_table[m_active_slot]->row(sel)); int file_index = memcard->GetFileIndex(m_slot_table[m_active_slot]->row(sel));
m_slot_memcard[!m_active_slot]->CopyFrom(*memcard, file_index); const auto result = m_slot_memcard[!m_active_slot]->CopyFrom(*memcard, file_index);
if (result != SUCCESS)
QMessageBox::warning(this, tr("Copy failed"), tr("Failed to copy file"));
} }
if (!m_slot_memcard[!m_active_slot]->Save()) for (int i = 0; i < SLOT_COUNT; i++)
{
if (!m_slot_memcard[i]->Save())
PanicAlertT("File write failed"); PanicAlertT("File write failed");
for (int i = 0; i < SLOT_COUNT; i++)
UpdateSlotTable(i); UpdateSlotTable(i);
}
} }
void GCMemcardManager::DeleteFiles() void GCMemcardManager::DeleteFiles()
@ -374,13 +385,14 @@ void GCMemcardManager::DeleteFiles()
{ {
auto sel = selection[i * m_slot_table[m_active_slot]->columnCount()]; auto sel = selection[i * m_slot_table[m_active_slot]->columnCount()];
int file_index = memcard->GetFileIndex(m_slot_table[m_active_slot]->row(sel)); int file_index = memcard->GetFileIndex(m_slot_table[m_active_slot]->row(sel));
memcard->RemoveFile(file_index); if (memcard->RemoveFile(file_index) != SUCCESS)
QMessageBox::warning(this, tr("Remove failed"), tr("Failed to remove file"));
} }
QMessageBox::information(this, tr("Success"), tr("Successfully deleted files."));
if (!memcard->Save()) if (!memcard->Save())
PanicAlertT("File write failed"); PanicAlertT("File write failed");
else
QMessageBox::information(this, tr("Success"), tr("Successfully deleted files."));
UpdateSlotTable(m_active_slot); UpdateSlotTable(m_active_slot);
UpdateActions(); UpdateActions();