GCMemcardManager: Rewrite file copying logic to provide a better user experience.

This commit is contained in:
Admiral H. Curtiss
2020-08-01 01:05:48 +02:00
parent 08dccb8727
commit 6e96f95432

View File

@ -573,31 +573,27 @@ void GCMemcardManager::ImportFile()
void GCMemcardManager::CopyFiles() void GCMemcardManager::CopyFiles()
{ {
auto selection = m_slot_table[m_active_slot]->selectedItems(); const auto& source_card = m_slot_memcard[m_active_slot];
auto& memcard = m_slot_memcard[m_active_slot]; if (!source_card)
return;
auto count = selection.count() / m_slot_table[m_active_slot]->columnCount(); auto& target_card = m_slot_memcard[!m_active_slot];
if (!target_card)
return;
for (int i = 0; i < count; i++) const auto selected_indices = GetSelectedFileIndices();
if (selected_indices.empty())
return;
const auto savefiles = Memcard::GetSavefiles(*source_card, selected_indices);
if (savefiles.empty())
{ {
auto sel = selection[i * m_slot_table[m_active_slot]->columnCount()]; ModalMessageBox::warning(this, tr("Copy Failed"),
int file_index = memcard->GetFileIndex(m_slot_table[m_active_slot]->row(sel)); tr("Failed to read selected savefile(s) from memory card."));
return;
const auto result = m_slot_memcard[!m_active_slot]->CopyFrom(*memcard, file_index);
if (result != Memcard::GCMemcardImportFileRetVal::SUCCESS)
{
ModalMessageBox::warning(this, tr("Copy failed"), tr("Failed to copy file"));
}
} }
for (int i = 0; i < SLOT_COUNT; i++) ImportFiles(!m_active_slot, savefiles);
{
if (!m_slot_memcard[i]->Save())
PanicAlertFmtT("File write failed");
UpdateSlotTable(i);
}
} }
void GCMemcardManager::DeleteFiles() void GCMemcardManager::DeleteFiles()