From a93d816c283de6972e3994a7e89f3c423f6afef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 13 May 2018 13:18:19 +0200 Subject: [PATCH] WiiSave: Move dialogs to UI code This moves the result dialogs to DolphinQt2, since WiiSave should not really be responsible for interacting with the user as a simple Wii save importing/exporting class. This also fixes Wii save import/export showing result dialogs twice, once from WiiSave, and another time from DolphinQt2. --- Source/Core/Core/HW/WiiSave.cpp | 28 +++++--------------- Source/Core/Core/HW/WiiSave.h | 9 +++++-- Source/Core/DolphinQt2/GameList/GameList.cpp | 10 ++++--- Source/Core/DolphinQt2/MenuBar.cpp | 14 +++++++--- 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/Source/Core/Core/HW/WiiSave.cpp b/Source/Core/Core/HW/WiiSave.cpp index 89f33f8f94..a8fce79221 100644 --- a/Source/Core/Core/HW/WiiSave.cpp +++ b/Source/Core/Core/HW/WiiSave.cpp @@ -39,28 +39,16 @@ constexpr u32 s_ng_id = 0x0403AC68; bool WiiSave::Import(const std::string& filename) { WiiSave save_file{filename}; - if (save_file.Import()) - { - SuccessAlertT("Successfully imported save file(s)"); - return true; - } - PanicAlertT("Import failed"); - return false; + return save_file.Import(); } -bool WiiSave::Export(u64 title_id) +std::string WiiSave::Export(u64 title_id) { WiiSave export_save{title_id}; - if (export_save.Export()) - { - SuccessAlertT("Successfully exported file to %s", export_save.m_encrypted_save_path.c_str()); - return true; - } - PanicAlertT("Export failed"); - return false; + return export_save.Export() ? export_save.m_encrypted_save_path : ""; } -void WiiSave::ExportAll() +std::pair WiiSave::ExportAll() { std::string title_folder = File::GetUserPath(D_WIIROOT_IDX) + "/title"; std::vector titles; @@ -88,16 +76,14 @@ void WiiSave::ExportAll() } } } - SuccessAlertT("Found %zu save file(s)", titles.size()); - u32 success = 0; + size_t exported_save_count = 0; for (const u64& title : titles) { WiiSave export_save{title}; if (export_save.Export()) - success++; + ++exported_save_count; } - SuccessAlertT("Successfully exported %u save(s) to %s", success, - (File::GetUserPath(D_USER_IDX) + "private/wii/title/").c_str()); + return {exported_save_count, File::GetUserPath(D_USER_IDX) + "private/wii/title/"}; } WiiSave::WiiSave(std::string filename) : m_encrypted_save_path(std::move(filename)), m_valid{true} diff --git a/Source/Core/Core/HW/WiiSave.h b/Source/Core/Core/HW/WiiSave.h index 160c2b5452..0a4d993a29 100644 --- a/Source/Core/Core/HW/WiiSave.h +++ b/Source/Core/Core/HW/WiiSave.h @@ -6,6 +6,7 @@ #include #include +#include #include #include "Common/CommonTypes.h" @@ -14,9 +15,13 @@ class WiiSave { public: + /// Import a save into the NAND from a .bin file. static bool Import(const std::string& filename); - static bool Export(u64 title_id); - static void ExportAll(); + /// Export a save to a .bin file. Returns the path to the .bin. + static std::string Export(u64 title_id); + /// Export all saves that are in the NAND. Returns the number of exported saves and a path + /// to the .bins. + static std::pair ExportAll(); private: explicit WiiSave(std::string filename); diff --git a/Source/Core/DolphinQt2/GameList/GameList.cpp b/Source/Core/DolphinQt2/GameList/GameList.cpp index e3b21af6f7..184f45622a 100644 --- a/Source/Core/DolphinQt2/GameList/GameList.cpp +++ b/Source/Core/DolphinQt2/GameList/GameList.cpp @@ -260,11 +260,13 @@ void GameList::ExportWiiSave() { QMessageBox result_dialog(this); - const bool success = WiiSave::Export(GetSelectedGame()->GetTitleID()); + const QString bin_path = QString::fromStdString(WiiSave::Export(GetSelectedGame()->GetTitleID())); - result_dialog.setIcon(success ? QMessageBox::Information : QMessageBox::Critical); - result_dialog.setText(success ? tr("Successfully exported save files") : - tr("Failed to export save files!")); + result_dialog.setIcon(!bin_path.isEmpty() ? QMessageBox::Information : QMessageBox::Critical); + if (!bin_path.isEmpty()) + result_dialog.setText(tr("Successfully exported save files to %1").arg(bin_path)); + else + result_dialog.setText(tr("Failed to export save files.")); result_dialog.exec(); } diff --git a/Source/Core/DolphinQt2/MenuBar.cpp b/Source/Core/DolphinQt2/MenuBar.cpp index adadc6301a..61df3f967c 100644 --- a/Source/Core/DolphinQt2/MenuBar.cpp +++ b/Source/Core/DolphinQt2/MenuBar.cpp @@ -896,13 +896,21 @@ void MenuBar::ImportWiiSave() tr("Wii save files (*.bin);;" "All Files (*)")); - if (!file.isEmpty()) - WiiSave::Import(file.toStdString()); + if (file.isEmpty()) + return; + + if (WiiSave::Import(file.toStdString())) + QMessageBox::information(this, tr("Save Import"), tr("Successfully imported save files.")); + else + QMessageBox::critical(this, tr("Save Import"), tr("Failed to import save files.")); } void MenuBar::ExportWiiSaves() { - WiiSave::ExportAll(); + const std::pair result = WiiSave::ExportAll(); + QMessageBox::information(this, tr("Save Export"), + tr("Exported %n save(s) to %1", "", static_cast(result.first)) + .arg(QString::fromStdString(result.second))); } void MenuBar::CheckNAND()