mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-15 05:47:56 -07:00
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:
parent
87e5cd73dc
commit
80b3d7ccb8
@ -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<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::vector<u64> titles;
|
||||
@ -83,11 +83,11 @@ std::pair<size_t, std::string> 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
|
||||
|
@ -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<size_t, std::string> 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();
|
||||
|
@ -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()
|
||||
|
@ -907,10 +907,15 @@ void MenuBar::ImportWiiSave()
|
||||
|
||||
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"),
|
||||
tr("Exported %n save(s) to %1", "", static_cast<int>(result.first))
|
||||
.arg(QString::fromStdString(result.second)));
|
||||
tr("Exported %n save(s)", "", static_cast<int>(count)));
|
||||
}
|
||||
|
||||
void MenuBar::CheckNAND()
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user