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.
This commit is contained in:
Léo Lam 2018-05-13 15:34:30 +02:00
parent 87e5cd73dc
commit 80b3d7ccb8
6 changed files with 35 additions and 35 deletions

View File

@ -40,19 +40,19 @@ constexpr Md5 s_md5_blanker{{0x0E, 0x65, 0x37, 0x81, 0x99, 0xBE, 0x45, 0x17, 0xA
0x45, 0x1A, 0x57, 0x93}}; 0x45, 0x1A, 0x57, 0x93}};
constexpr u32 s_ng_id = 0x0403AC68; 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(); 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}; WiiSave export_save{title_id, std::move(export_path)};
return export_save.Export() ? export_save.m_encrypted_save_path : ""; return export_save.Export();
} }
std::pair<size_t, std::string> WiiSave::ExportAll() size_t WiiSave::ExportAll(std::string export_path)
{ {
std::string title_folder = File::GetUserPath(D_WIIROOT_IDX) + "/title"; std::string title_folder = File::GetUserPath(D_WIIROOT_IDX) + "/title";
std::vector<u64> titles; std::vector<u64> titles;
@ -83,11 +83,11 @@ std::pair<size_t, std::string> WiiSave::ExportAll()
size_t exported_save_count = 0; size_t exported_save_count = 0;
for (const u64& title : titles) for (const u64& title : titles)
{ {
WiiSave export_save{title}; WiiSave export_save{title, export_path};
if (export_save.Export()) if (export_save.Export())
++exported_save_count; ++exported_save_count;
} }
return {exported_save_count, File::GetUserPath(D_USER_IDX) + "private/wii/title/"}; return exported_save_count;
} }
WiiSave::WiiSave(std::string filename) WiiSave::WiiSave(std::string filename)
@ -105,7 +105,8 @@ bool WiiSave::Import()
return m_valid; 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); 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); ERROR_LOG(CONSOLE, "No banner file found for title %s", game_id);
return false; return false;
} }
if (m_encrypted_save_path.length() == 0) m_encrypted_save_path += StringFromFormat("/private/wii/title/%s/data.bin", game_id);
{
// 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);
File::CreateFullPath(m_encrypted_save_path); File::CreateFullPath(m_encrypted_save_path);
} }
else else

View File

@ -17,16 +17,15 @@ class WiiSave
{ {
public: public:
/// Import a save into the NAND from a .bin file. /// Import a save into the NAND from a .bin file.
static bool Import(const std::string& filename); static bool Import(std::string filename);
/// Export a save to a .bin file. Returns the path to the .bin. /// Export a save to a .bin file.
static std::string Export(u64 title_id); static bool Export(u64 title_id, std::string export_path);
/// Export all saves that are in the NAND. Returns the number of exported saves and a path /// Export all saves that are in the NAND. Returns the number of exported saves.
/// to the .bins. static size_t ExportAll(std::string export_path);
static std::pair<size_t, std::string> ExportAll();
private: private:
explicit WiiSave(std::string filename); explicit WiiSave(std::string filename);
explicit WiiSave(u64 title_id); explicit WiiSave(u64 title_id, std::string export_path);
~WiiSave(); ~WiiSave();
bool Import(); bool Import();

View File

@ -258,16 +258,16 @@ void GameList::OpenProperties()
void GameList::ExportWiiSave() 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())); if (WiiSave::Export(GetSelectedGame()->GetTitleID(), export_dir.toStdString()))
QMessageBox::information(this, tr("Save Export"), tr("Successfully exported 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 else
result_dialog.setText(tr("Failed to export save files.")); QMessageBox::critical(this, tr("Save Export"), tr("Failed to export save files."));
result_dialog.exec();
} }
void GameList::OpenWiki() void GameList::OpenWiki()

View File

@ -907,10 +907,15 @@ void MenuBar::ImportWiiSave()
void MenuBar::ExportWiiSaves() void MenuBar::ExportWiiSaves()
{ {
const std::pair<size_t, std::string> 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"), QMessageBox::information(this, tr("Save Export"),
tr("Exported %n save(s) to %1", "", static_cast<int>(result.first)) tr("Exported %n save(s)", "", static_cast<int>(count)));
.arg(QString::fromStdString(result.second)));
} }
void MenuBar::CheckNAND() void MenuBar::CheckNAND()

View File

@ -1204,7 +1204,7 @@ void CFrame::OnLoadGameCubeIPLEUR(wxCommandEvent&)
void CFrame::OnExportAllSaves(wxCommandEvent& WXUNUSED(event)) void CFrame::OnExportAllSaves(wxCommandEvent& WXUNUSED(event))
{ {
WiiSave::ExportAll(); WiiSave::ExportAll(File::GetUserPath(D_USER_IDX));
} }
void CFrame::OnImportSave(wxCommandEvent& WXUNUSED(event)) void CFrame::OnImportSave(wxCommandEvent& WXUNUSED(event))

View File

@ -988,7 +988,7 @@ void GameListCtrl::OnExportSave(wxCommandEvent& WXUNUSED(event))
{ {
const UICommon::GameFile* iso = GetSelectedISO(); const UICommon::GameFile* iso = GetSelectedISO();
if (iso) if (iso)
WiiSave::Export(iso->GetTitleID()); WiiSave::Export(iso->GetTitleID(), File::GetUserPath(D_USER_IDX));
} }
// Save this file as the default file // Save this file as the default file