WiiSave: Clean up constructors
Move the import/export operation into separate functions, as it doesn't really make sense for the constructor to do *everything*, including printing success/failure message boxes. The existing constructor was split into two: one that takes a path, and another taking a title ID. This makes it more obvious what is actually done when a path/TID is passed and also clarifies what parameters should be passed. (No more magic 0 or "" value.)
This commit is contained in:
parent
fbf36b85d2
commit
41c4486c65
|
@ -36,27 +36,31 @@ constexpr u8 s_md5_blanker[16] = {0x0E, 0x65, 0x37, 0x81, 0x99, 0xBE, 0x45, 0x17
|
|||
0xAB, 0x06, 0xEC, 0x22, 0x45, 0x1A, 0x57, 0x93};
|
||||
constexpr u32 s_ng_id = 0x0403AC68;
|
||||
|
||||
bool WiiSave::ImportWiiSave(const std::string& filename)
|
||||
bool WiiSave::Import(const std::string& filename)
|
||||
{
|
||||
WiiSave save_file(filename);
|
||||
return save_file.m_valid;
|
||||
WiiSave save_file{filename};
|
||||
if (save_file.Import())
|
||||
{
|
||||
SuccessAlertT("Successfully imported save file(s)");
|
||||
return true;
|
||||
}
|
||||
PanicAlertT("Import failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WiiSave::ExportWiiSave(u64 title_id)
|
||||
bool WiiSave::Export(u64 title_id)
|
||||
{
|
||||
WiiSave export_save("", title_id);
|
||||
if (export_save.m_valid)
|
||||
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;
|
||||
}
|
||||
else
|
||||
{
|
||||
PanicAlertT("Export failed");
|
||||
}
|
||||
return export_save.m_valid;
|
||||
PanicAlertT("Export failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
void WiiSave::ExportAllSaves()
|
||||
void WiiSave::ExportAll()
|
||||
{
|
||||
std::string title_folder = File::GetUserPath(D_WIIROOT_IDX) + "/title";
|
||||
std::vector<u64> titles;
|
||||
|
@ -88,49 +92,45 @@ void WiiSave::ExportAllSaves()
|
|||
u32 success = 0;
|
||||
for (const u64& title : titles)
|
||||
{
|
||||
WiiSave export_save{"", title};
|
||||
if (export_save.m_valid)
|
||||
WiiSave export_save{title};
|
||||
if (export_save.Export())
|
||||
success++;
|
||||
}
|
||||
SuccessAlertT("Successfully exported %u save(s) to %s", success,
|
||||
(File::GetUserPath(D_USER_IDX) + "private/wii/title/").c_str());
|
||||
}
|
||||
|
||||
WiiSave::WiiSave(const std::string& filename, u64 title_id)
|
||||
: m_encrypted_save_path(filename), m_title_id(title_id)
|
||||
WiiSave::WiiSave(std::string filename) : m_encrypted_save_path(std::move(filename)), m_valid{true}
|
||||
{
|
||||
memcpy(m_sd_iv, "\x21\x67\x12\xE6\xAA\x1F\x68\x9F\x95\xC5\xA2\x23\x24\xDC\x6A\x98", 0x10);
|
||||
mbedtls_aes_setkey_dec(&m_aes_ctx, s_sd_key, 128);
|
||||
}
|
||||
|
||||
if (!title_id) // Import
|
||||
{
|
||||
mbedtls_aes_setkey_dec(&m_aes_ctx, s_sd_key, 128);
|
||||
bool WiiSave::Import()
|
||||
{
|
||||
ReadHDR();
|
||||
ReadBKHDR();
|
||||
ImportWiiSaveFiles();
|
||||
// TODO: check_sig()
|
||||
return m_valid;
|
||||
}
|
||||
|
||||
WiiSave::WiiSave(u64 title_id) : m_title_id{title_id}
|
||||
{
|
||||
memcpy(m_sd_iv, "\x21\x67\x12\xE6\xAA\x1F\x68\x9F\x95\xC5\xA2\x23\x24\xDC\x6A\x98", 0x10);
|
||||
mbedtls_aes_setkey_enc(&m_aes_ctx, s_sd_key, 128);
|
||||
|
||||
if (getPaths(true))
|
||||
m_valid = true;
|
||||
ReadHDR();
|
||||
ReadBKHDR();
|
||||
ImportWiiSaveFiles();
|
||||
// TODO: check_sig()
|
||||
if (m_valid)
|
||||
{
|
||||
SuccessAlertT("Successfully imported save file(s)");
|
||||
}
|
||||
else
|
||||
{
|
||||
PanicAlertT("Import failed");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mbedtls_aes_setkey_enc(&m_aes_ctx, s_sd_key, 128);
|
||||
}
|
||||
|
||||
if (getPaths(true))
|
||||
{
|
||||
m_valid = true;
|
||||
WriteHDR();
|
||||
WriteBKHDR();
|
||||
ExportWiiSaveFiles();
|
||||
do_sig();
|
||||
}
|
||||
}
|
||||
bool WiiSave::Export()
|
||||
{
|
||||
WriteHDR();
|
||||
WriteBKHDR();
|
||||
ExportWiiSaveFiles();
|
||||
do_sig();
|
||||
return m_valid;
|
||||
}
|
||||
|
||||
void WiiSave::ReadHDR()
|
||||
|
|
|
@ -14,13 +14,18 @@
|
|||
class WiiSave
|
||||
{
|
||||
public:
|
||||
bool static ImportWiiSave(const std::string& filename);
|
||||
bool static ExportWiiSave(u64 title_id);
|
||||
void static ExportAllSaves();
|
||||
static bool Import(const std::string& filename);
|
||||
static bool Export(u64 title_id);
|
||||
static void ExportAll();
|
||||
|
||||
private:
|
||||
WiiSave(const std::string& filename, u64 title_id = 0);
|
||||
explicit WiiSave(std::string filename);
|
||||
explicit WiiSave(u64 title_id);
|
||||
~WiiSave();
|
||||
|
||||
bool Import();
|
||||
bool Export();
|
||||
|
||||
void ReadHDR();
|
||||
void ReadBKHDR();
|
||||
void WriteHDR();
|
||||
|
|
|
@ -260,7 +260,7 @@ void GameList::ExportWiiSave()
|
|||
{
|
||||
QMessageBox result_dialog(this);
|
||||
|
||||
const bool success = WiiSave::ExportWiiSave(GetSelectedGame()->GetTitleID());
|
||||
const bool success = WiiSave::Export(GetSelectedGame()->GetTitleID());
|
||||
|
||||
result_dialog.setIcon(success ? QMessageBox::Information : QMessageBox::Critical);
|
||||
result_dialog.setText(success ? tr("Successfully exported save files") :
|
||||
|
|
|
@ -897,12 +897,12 @@ void MenuBar::ImportWiiSave()
|
|||
"All Files (*)"));
|
||||
|
||||
if (!file.isEmpty())
|
||||
WiiSave::ImportWiiSave(file.toStdString());
|
||||
WiiSave::Import(file.toStdString());
|
||||
}
|
||||
|
||||
void MenuBar::ExportWiiSaves()
|
||||
{
|
||||
WiiSave::ExportAllSaves();
|
||||
WiiSave::ExportAll();
|
||||
}
|
||||
|
||||
void MenuBar::CheckNAND()
|
||||
|
|
|
@ -1204,7 +1204,7 @@ void CFrame::OnLoadGameCubeIPLEUR(wxCommandEvent&)
|
|||
|
||||
void CFrame::OnExportAllSaves(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
WiiSave::ExportAllSaves();
|
||||
WiiSave::ExportAll();
|
||||
}
|
||||
|
||||
void CFrame::OnImportSave(wxCommandEvent& WXUNUSED(event))
|
||||
|
@ -1215,7 +1215,7 @@ void CFrame::OnImportSave(wxCommandEvent& WXUNUSED(event))
|
|||
wxFD_OPEN | wxFD_PREVIEW | wxFD_FILE_MUST_EXIST, this);
|
||||
|
||||
if (!path.IsEmpty())
|
||||
WiiSave::ImportWiiSave(WxStrToStr(path));
|
||||
WiiSave::Import(WxStrToStr(path));
|
||||
}
|
||||
|
||||
void CFrame::OnShowCheatsWindow(wxCommandEvent& WXUNUSED(event))
|
||||
|
|
|
@ -988,7 +988,7 @@ void GameListCtrl::OnExportSave(wxCommandEvent& WXUNUSED(event))
|
|||
{
|
||||
const UICommon::GameFile* iso = GetSelectedISO();
|
||||
if (iso)
|
||||
WiiSave::ExportWiiSave(iso->GetTitleID());
|
||||
WiiSave::Export(iso->GetTitleID());
|
||||
}
|
||||
|
||||
// Save this file as the default file
|
||||
|
|
Loading…
Reference in New Issue