From 8eafd1928ef08e95a6001e78420393fb63167e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Fri, 1 Jun 2018 20:41:52 +0200 Subject: [PATCH] WiiSave: Move user interaction to UI frontends --- Source/Core/Core/HW/WiiSave.cpp | 8 ++------ Source/Core/Core/HW/WiiSave.h | 3 ++- Source/Core/DolphinQt2/MenuBar.cpp | 13 +++++++++++-- Source/Core/DolphinWX/FrameTools.cpp | 8 +++++++- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Source/Core/Core/HW/WiiSave.cpp b/Source/Core/Core/HW/WiiSave.cpp index bb7494ef5e..1ffe9d36f2 100644 --- a/Source/Core/Core/HW/WiiSave.cpp +++ b/Source/Core/Core/HW/WiiSave.cpp @@ -28,7 +28,6 @@ #include "Common/FileUtil.h" #include "Common/Lazy.h" #include "Common/Logging/Log.h" -#include "Common/MsgHandler.h" #include "Common/NandPaths.h" #include "Common/StringUtil.h" #include "Common/Swap.h" @@ -520,7 +519,7 @@ bool Copy(Storage* source, Storage* dest) Copy("files", source, &Storage::ReadFiles, dest, &Storage::WriteFiles); } -bool Import(const std::string& data_bin_path) +bool Import(const std::string& data_bin_path, std::function can_overwrite) { IOS::HLE::Kernel ios; const auto data_bin = MakeDataBinStorage(&ios.GetIOSC(), data_bin_path, "rb"); @@ -531,11 +530,8 @@ bool Import(const std::string& data_bin_path) return false; } const auto nand = MakeNandStorage(ios.GetFS().get(), header->hdr.tid); - if (nand->SaveExists() && !AskYesNoT("Save data for this title already exists. Consider backing " - "up the current data before overwriting.\nOverwrite now?")) - { + if (nand->SaveExists() && !can_overwrite()) return false; - } return Copy(data_bin.get(), nand.get()); } diff --git a/Source/Core/Core/HW/WiiSave.h b/Source/Core/Core/HW/WiiSave.h index 1ae03ed46a..cace7ba896 100644 --- a/Source/Core/Core/HW/WiiSave.h +++ b/Source/Core/Core/HW/WiiSave.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include @@ -37,7 +38,7 @@ StoragePointer MakeDataBinStorage(IOS::HLE::IOSC* iosc, const std::string& path, bool Copy(Storage* source, Storage* destination); /// Import a save into the NAND from a .bin file. -bool Import(const std::string& data_bin_path); +bool Import(const std::string& data_bin_path, std::function can_overwrite); /// Export a save to a .bin file. bool Export(u64 tid, const std::string& export_path); /// Export all saves that are in the NAND. Returns the number of exported saves. diff --git a/Source/Core/DolphinQt2/MenuBar.cpp b/Source/Core/DolphinQt2/MenuBar.cpp index 43ecf794f3..f7f4c047b0 100644 --- a/Source/Core/DolphinQt2/MenuBar.cpp +++ b/Source/Core/DolphinQt2/MenuBar.cpp @@ -958,9 +958,18 @@ void MenuBar::ImportWiiSave() if (file.isEmpty()) return; - if (WiiSave::Import(file.toStdString())) + bool cancelled = false; + auto can_overwrite = [&] { + bool yes = QMessageBox::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; + cancelled = !yes; + return yes; + }; + if (WiiSave::Import(file.toStdString(), can_overwrite)) QMessageBox::information(this, tr("Save Import"), tr("Successfully imported save files.")); - else + else if (!cancelled) QMessageBox::critical(this, tr("Save Import"), tr("Failed to import save files.")); } diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index ea6f504e7c..d6d53af3a4 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -1214,8 +1214,14 @@ void CFrame::OnImportSave(wxCommandEvent& WXUNUSED(event)) _("Wii save files (*.bin)") + "|*.bin|" + wxGetTranslation(wxALL_FILES), wxFD_OPEN | wxFD_PREVIEW | wxFD_FILE_MUST_EXIST, this); + auto can_overwrite = [this] { + return wxMessageBox(_("Save data for this title already exists in the NAND. Consider backing " + "up the current data before overwriting.\nOverwrite now?"), + _("Save Import"), wxYES_NO, this) == wxYES; + }; + if (!path.IsEmpty()) - WiiSave::Import(WxStrToStr(path)); + WiiSave::Import(WxStrToStr(path), can_overwrite); } void CFrame::OnShowCheatsWindow(wxCommandEvent& WXUNUSED(event))