Merge pull request #13278 from JoshuaVandaele/saves-import

Implement importing multiple saves from an export folder
This commit is contained in:
JosJuice
2025-05-02 15:40:27 +02:00
committed by GitHub
4 changed files with 115 additions and 14 deletions

View File

@ -9,6 +9,7 @@
#include <QAction>
#include <QActionGroup>
#include <QDesktopServices>
#include <QDirIterator>
#include <QFileDialog>
#include <QFontDialog>
#include <QInputDialog>
@ -345,6 +346,8 @@ void MenuBar::AddToolsMenu()
m_import_wii_save =
tools_menu->addAction(tr("Import Wii Save..."), this, &MenuBar::ImportWiiSave);
m_import_wii_saves =
tools_menu->addAction(tr("Import Wii Saves..."), this, &MenuBar::ImportWiiSaves);
m_export_wii_saves =
tools_menu->addAction(tr("Export All Wii Saves"), this, &MenuBar::ExportWiiSaves);
@ -1098,6 +1101,7 @@ void MenuBar::UpdateToolsMenu(const Core::State state)
m_import_backup->setEnabled(is_uninitialized);
m_check_nand->setEnabled(is_uninitialized);
m_import_wii_save->setEnabled(is_uninitialized);
m_import_wii_saves->setEnabled(is_uninitialized);
m_export_wii_saves->setEnabled(is_uninitialized);
if (is_uninitialized)
@ -1201,7 +1205,8 @@ void MenuBar::ImportWiiSave()
return ModalMessageBox::question(
this, tr("Save Import"),
tr("Save data for this title already exists in the NAND. Consider backing up "
"the current data before overwriting.\nOverwrite now?")) == QMessageBox::Yes;
"the current data before overwriting.\n\nOverwrite existing save data?")) ==
QMessageBox::Yes;
};
const auto result = WiiSave::Import(file.toStdString(), can_overwrite);
@ -1232,6 +1237,95 @@ void MenuBar::ImportWiiSave()
}
}
void MenuBar::ImportWiiSaves()
{
QString folder =
DolphinFileDialog::getExistingDirectory(this, tr("Select Save Folder"), QDir::currentPath());
if (folder.isEmpty())
return;
QDirIterator it(folder, QStringList(QStringLiteral("*.bin")), QDir::Files,
QDirIterator::Subdirectories);
QStringList failure_details;
size_t success_count = 0;
size_t fail_count = 0;
bool yes_all = false;
bool no_all = false;
while (it.hasNext())
{
const QString file = it.next();
auto can_overwrite = [&] {
if (yes_all)
return true;
if (no_all)
return false;
auto response = ModalMessageBox::question(
this, tr("Save Import"),
tr("%1: Save data for this title already exists in the NAND. Consider backing up "
"the current data before overwriting.\n\nOverwrite existing save data?")
.arg(file),
QMessageBox::StandardButton::YesAll | QMessageBox::StandardButton::Yes |
QMessageBox::StandardButton::No | QMessageBox::StandardButton::NoAll);
if (response == QMessageBox::YesAll)
{
yes_all = true;
return true;
}
else if (response == QMessageBox::NoAll)
{
no_all = true;
return false;
}
return response == QMessageBox::Yes;
};
const auto result = WiiSave::Import(file.toStdString(), can_overwrite);
switch (result)
{
case WiiSave::CopyResult::Success:
success_count++;
break;
case WiiSave::CopyResult::CorruptedSource:
fail_count++;
failure_details.append(tr("%1: Failed to import save file. The given file appears to be "
"corrupted or is not a valid Wii save.")
.arg(file));
break;
case WiiSave::CopyResult::TitleMissing:
fail_count++;
failure_details.append(
tr("%1: Failed to import save file. Please launch the game once, then try again.")
.arg(file));
break;
case WiiSave::CopyResult::Cancelled:
break;
default:
fail_count++;
failure_details.append(
tr("%1: Failed to import save file. Your NAND may be corrupt, or something is preventing "
"access to files within it. Try repairing your NAND (Tools -> Manage NAND -> Check "
"NAND...), then import the save again.")
.arg(file));
break;
}
}
if (success_count == 0 && fail_count == 0)
return;
ModalMessageBox::information(this, tr("Save Import"),
tr("Successfully imported %1 save file(s) with %2 failure(s)")
.arg(success_count)
.arg(fail_count),
QMessageBox::Ok, QMessageBox::NoButton, Qt::WindowModal,
failure_details.join(QStringLiteral("\n\n")));
}
void MenuBar::ExportWiiSaves()
{
const QString export_dir = DolphinFileDialog::getExistingDirectory(