From 80b3d7ccb8a3199b7f9a98cc2d3e7a92a0b1842e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 13 May 2018 15:34:30 +0200 Subject: [PATCH] WiiSave: Allow users to specify export directory Export and ExportAll now open a directory picker (that defaults to the previous default directory, i.e. the Dolphin user dir). Also removes the need to return the path in the export functions since the user knows which path they chose. --- Source/Core/Core/HW/WiiSave.cpp | 26 +++++++++----------- Source/Core/Core/HW/WiiSave.h | 13 +++++----- Source/Core/DolphinQt2/GameList/GameList.cpp | 16 ++++++------ Source/Core/DolphinQt2/MenuBar.cpp | 11 ++++++--- Source/Core/DolphinWX/FrameTools.cpp | 2 +- Source/Core/DolphinWX/GameListCtrl.cpp | 2 +- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/Source/Core/Core/HW/WiiSave.cpp b/Source/Core/Core/HW/WiiSave.cpp index 7314b28b5f..5909c00e7f 100644 --- a/Source/Core/Core/HW/WiiSave.cpp +++ b/Source/Core/Core/HW/WiiSave.cpp @@ -40,19 +40,19 @@ constexpr Md5 s_md5_blanker{{0x0E, 0x65, 0x37, 0x81, 0x99, 0xBE, 0x45, 0x17, 0xA 0x45, 0x1A, 0x57, 0x93}}; constexpr u32 s_ng_id = 0x0403AC68; -bool WiiSave::Import(const std::string& filename) +bool WiiSave::Import(std::string filename) { - WiiSave save_file{filename}; + WiiSave save_file{std::move(filename)}; return save_file.Import(); } -std::string WiiSave::Export(u64 title_id) +bool WiiSave::Export(u64 title_id, std::string export_path) { - WiiSave export_save{title_id}; - return export_save.Export() ? export_save.m_encrypted_save_path : ""; + WiiSave export_save{title_id, std::move(export_path)}; + return export_save.Export(); } -std::pair WiiSave::ExportAll() +size_t WiiSave::ExportAll(std::string export_path) { std::string title_folder = File::GetUserPath(D_WIIROOT_IDX) + "/title"; std::vector titles; @@ -83,11 +83,11 @@ std::pair WiiSave::ExportAll() size_t exported_save_count = 0; for (const u64& title : titles) { - WiiSave export_save{title}; + WiiSave export_save{title, export_path}; if (export_save.Export()) ++exported_save_count; } - return {exported_save_count, File::GetUserPath(D_USER_IDX) + "private/wii/title/"}; + return exported_save_count; } WiiSave::WiiSave(std::string filename) @@ -105,7 +105,8 @@ bool WiiSave::Import() return m_valid; } -WiiSave::WiiSave(u64 title_id) : m_sd_iv{s_sd_initial_iv}, m_title_id{title_id} +WiiSave::WiiSave(u64 title_id, std::string export_path) + : m_sd_iv{s_sd_initial_iv}, m_encrypted_save_path(std::move(export_path)), m_title_id{title_id} { mbedtls_aes_setkey_enc(&m_aes_ctx, s_sd_key.data(), 128); @@ -571,12 +572,7 @@ bool WiiSave::getPaths(bool for_export) ERROR_LOG(CONSOLE, "No banner file found for title %s", game_id); return false; } - if (m_encrypted_save_path.length() == 0) - { - // If no path was passed, use User folder - m_encrypted_save_path = File::GetUserPath(D_USER_IDX); - } - m_encrypted_save_path += StringFromFormat("private/wii/title/%s/data.bin", game_id); + m_encrypted_save_path += StringFromFormat("/private/wii/title/%s/data.bin", game_id); File::CreateFullPath(m_encrypted_save_path); } else diff --git a/Source/Core/Core/HW/WiiSave.h b/Source/Core/Core/HW/WiiSave.h index dbc33b446b..995082eebd 100644 --- a/Source/Core/Core/HW/WiiSave.h +++ b/Source/Core/Core/HW/WiiSave.h @@ -17,16 +17,15 @@ class WiiSave { public: /// Import a save into the NAND from a .bin file. - static bool Import(const std::string& filename); - /// 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(); + static bool Import(std::string filename); + /// Export a save to a .bin file. + static bool Export(u64 title_id, std::string export_path); + /// Export all saves that are in the NAND. Returns the number of exported saves. + static size_t ExportAll(std::string export_path); private: explicit WiiSave(std::string filename); - explicit WiiSave(u64 title_id); + explicit WiiSave(u64 title_id, std::string export_path); ~WiiSave(); bool Import(); diff --git a/Source/Core/DolphinQt2/GameList/GameList.cpp b/Source/Core/DolphinQt2/GameList/GameList.cpp index 184f45622a..00e30abace 100644 --- a/Source/Core/DolphinQt2/GameList/GameList.cpp +++ b/Source/Core/DolphinQt2/GameList/GameList.cpp @@ -258,16 +258,16 @@ void GameList::OpenProperties() void GameList::ExportWiiSave() { - QMessageBox result_dialog(this); + const QString export_dir = QFileDialog::getExistingDirectory( + this, tr("Select Export Directory"), QString::fromStdString(File::GetUserPath(D_USER_IDX)), + QFileDialog::ShowDirsOnly); + if (export_dir.isEmpty()) + return; - const QString bin_path = QString::fromStdString(WiiSave::Export(GetSelectedGame()->GetTitleID())); - - 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)); + if (WiiSave::Export(GetSelectedGame()->GetTitleID(), export_dir.toStdString())) + QMessageBox::information(this, tr("Save Export"), tr("Successfully exported save files")); else - result_dialog.setText(tr("Failed to export save files.")); - result_dialog.exec(); + QMessageBox::critical(this, tr("Save Export"), tr("Failed to export save files.")); } void GameList::OpenWiki() diff --git a/Source/Core/DolphinQt2/MenuBar.cpp b/Source/Core/DolphinQt2/MenuBar.cpp index 61df3f967c..5f939fb087 100644 --- a/Source/Core/DolphinQt2/MenuBar.cpp +++ b/Source/Core/DolphinQt2/MenuBar.cpp @@ -907,10 +907,15 @@ void MenuBar::ImportWiiSave() void MenuBar::ExportWiiSaves() { - const std::pair result = WiiSave::ExportAll(); + const QString export_dir = QFileDialog::getExistingDirectory( + this, tr("Select Export Directory"), QString::fromStdString(File::GetUserPath(D_USER_IDX)), + QFileDialog::ShowDirsOnly); + if (export_dir.isEmpty()) + return; + + const size_t count = WiiSave::ExportAll(export_dir.toStdString()); QMessageBox::information(this, tr("Save Export"), - tr("Exported %n save(s) to %1", "", static_cast(result.first)) - .arg(QString::fromStdString(result.second))); + tr("Exported %n save(s)", "", static_cast(count))); } void MenuBar::CheckNAND() diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index da34972d94..ea6f504e7c 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -1204,7 +1204,7 @@ void CFrame::OnLoadGameCubeIPLEUR(wxCommandEvent&) void CFrame::OnExportAllSaves(wxCommandEvent& WXUNUSED(event)) { - WiiSave::ExportAll(); + WiiSave::ExportAll(File::GetUserPath(D_USER_IDX)); } void CFrame::OnImportSave(wxCommandEvent& WXUNUSED(event)) diff --git a/Source/Core/DolphinWX/GameListCtrl.cpp b/Source/Core/DolphinWX/GameListCtrl.cpp index d0d9dfeeac..fcf0aa3d0f 100644 --- a/Source/Core/DolphinWX/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/GameListCtrl.cpp @@ -988,7 +988,7 @@ void GameListCtrl::OnExportSave(wxCommandEvent& WXUNUSED(event)) { const UICommon::GameFile* iso = GetSelectedISO(); if (iso) - WiiSave::Export(iso->GetTitleID()); + WiiSave::Export(iso->GetTitleID(), File::GetUserPath(D_USER_IDX)); } // Save this file as the default file