2018-01-10 16:49:43 -05:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QMessageBox>
|
2019-01-07 20:04:20 -05:00
|
|
|
#include "QStringUtils.h"
|
2016-08-10 14:56:16 +01:00
|
|
|
#include "memorycardmanagerdialog.h"
|
|
|
|
#include "ui_memorycardmanager.h"
|
|
|
|
#include "StdStream.h"
|
|
|
|
#include "StdStreamUtils.h"
|
2018-01-10 16:49:43 -05:00
|
|
|
#include "AppConfig.h"
|
2018-01-10 16:58:03 -05:00
|
|
|
#include "../PS2VM_Preferences.h"
|
2016-08-10 14:56:16 +01:00
|
|
|
|
2018-01-10 14:58:25 -05:00
|
|
|
MemoryCardManagerDialog::MemoryCardManagerDialog(QWidget* parent)
|
|
|
|
: QDialog(parent)
|
|
|
|
, ui(new Ui::MemoryCardManagerDialog)
|
2018-01-15 16:57:42 -05:00
|
|
|
, m_MemoryCard0(CAppConfig::GetInstance().GetPreferencePath(PREF_PS2_MC0_DIRECTORY))
|
|
|
|
, m_MemoryCard1(CAppConfig::GetInstance().GetPreferencePath(PREF_PS2_MC1_DIRECTORY))
|
2016-08-10 14:56:16 +01:00
|
|
|
{
|
2018-01-10 14:58:25 -05:00
|
|
|
ui->setupUi(this);
|
2016-08-10 14:56:16 +01:00
|
|
|
|
2018-01-10 14:58:25 -05:00
|
|
|
m_pMemoryCard[0] = &m_MemoryCard0;
|
|
|
|
m_pMemoryCard[1] = &m_MemoryCard1;
|
2016-08-10 14:56:16 +01:00
|
|
|
|
2018-01-10 14:58:25 -05:00
|
|
|
m_pCurrentMemoryCard = m_pMemoryCard[0];
|
2016-08-10 14:56:16 +01:00
|
|
|
|
2018-01-10 14:58:25 -05:00
|
|
|
populateSaveList();
|
2016-08-10 14:56:16 +01:00
|
|
|
|
2018-01-10 14:58:25 -05:00
|
|
|
ui->label_name->setWordWrap(true);
|
2016-08-10 14:56:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
MemoryCardManagerDialog::~MemoryCardManagerDialog()
|
|
|
|
{
|
2018-01-10 14:58:25 -05:00
|
|
|
delete ui;
|
2016-08-10 14:56:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardManagerDialog::on_import_saves_button_clicked()
|
|
|
|
{
|
2018-01-10 14:58:25 -05:00
|
|
|
QFileDialog dialog(this);
|
|
|
|
dialog.setDirectory(m_lastpath);
|
|
|
|
dialog.setFileMode(QFileDialog::ExistingFiles);
|
|
|
|
dialog.setNameFilter(tr("All Supported types (*.psu *.sps *.xps *.max);;EMS Memory Adapter Save Dumps (*.psu);;Sharkport/X-Port Save Dumps (*.sps; *.xps);;Action Replay MAX Save Dumps (*.max);;All files (*.*)"));
|
|
|
|
if(dialog.exec())
|
|
|
|
{
|
|
|
|
QString fileName = dialog.selectedFiles().first();
|
|
|
|
m_lastpath = QFileInfo(fileName).path();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2019-01-07 20:04:20 -05:00
|
|
|
auto filePath = QStringToPath(fileName);
|
|
|
|
auto input = Framework::CreateInputStdStream(filePath.native());
|
2018-01-10 14:58:25 -05:00
|
|
|
CSaveImporter::ImportSave(input, m_pCurrentMemoryCard->GetBasePath(),
|
|
|
|
std::bind(&MemoryCardManagerDialog::OnImportOverwrite, this, std::placeholders::_1));
|
|
|
|
}
|
|
|
|
catch(const std::exception& Exception)
|
|
|
|
{
|
2018-04-30 21:01:23 +01:00
|
|
|
QString msg("Couldn't import save(s):\n\n%1");
|
2018-01-10 14:58:25 -05:00
|
|
|
QMessageBox messageBox;
|
|
|
|
messageBox.critical(this, "Error", msg.arg(Exception.what()));
|
|
|
|
messageBox.show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pCurrentMemoryCard->RefreshContents();
|
|
|
|
populateSaveList();
|
|
|
|
}
|
2016-08-10 14:56:16 +01:00
|
|
|
}
|
|
|
|
|
2019-10-16 20:51:11 -04:00
|
|
|
CSaveImporterBase::OVERWRITE_PROMPT_RETURN MemoryCardManagerDialog::OnImportOverwrite(const fs::path& filePath)
|
2016-08-10 14:56:16 +01:00
|
|
|
{
|
2019-10-16 20:51:11 -04:00
|
|
|
std::string fileName = filePath.filename().string();
|
2018-04-30 21:01:23 +01:00
|
|
|
QString msg("File %1 already exists.\n\nOverwrite?");
|
2018-01-10 14:58:25 -05:00
|
|
|
QMessageBox::StandardButton resBtn = QMessageBox::question(this, "Overwrite?",
|
|
|
|
msg.arg(fileName.c_str()),
|
|
|
|
QMessageBox::Yes | QMessageBox::No,
|
|
|
|
QMessageBox::Yes);
|
|
|
|
return (resBtn == QMessageBox::Yes) ? CSaveImporterBase::OVERWRITE_YES : CSaveImporterBase::OVERWRITE_NO;
|
2016-08-10 14:56:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardManagerDialog::on_comboBox_currentIndexChanged(int index)
|
|
|
|
{
|
2018-01-10 14:58:25 -05:00
|
|
|
m_pCurrentMemoryCard = m_pMemoryCard[index];
|
|
|
|
populateSaveList();
|
2016-08-10 14:56:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardManagerDialog::populateSaveList()
|
|
|
|
{
|
2018-01-10 14:58:25 -05:00
|
|
|
unsigned int nItemCount = static_cast<unsigned int>(m_pCurrentMemoryCard->GetSaveCount());
|
|
|
|
ui->savelistWidget->clear();
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < nItemCount; i++)
|
|
|
|
{
|
|
|
|
QString name = QString::fromWCharArray(m_pCurrentMemoryCard->GetSaveByIndex(i)->GetName());
|
|
|
|
ui->savelistWidget->addItem(name);
|
|
|
|
}
|
2016-08-10 14:56:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardManagerDialog::on_savelistWidget_currentRowChanged(int currentRow)
|
|
|
|
{
|
2018-01-10 14:58:25 -05:00
|
|
|
int nItemCount = static_cast<int>(m_pCurrentMemoryCard->GetSaveCount() - 1);
|
|
|
|
if(currentRow >= 0 && currentRow <= nItemCount)
|
|
|
|
{
|
|
|
|
const CSave* save = m_pCurrentMemoryCard->GetSaveByIndex(currentRow);
|
2018-04-30 21:01:23 +01:00
|
|
|
QDateTime* dt = new QDateTime;
|
2018-01-10 14:58:25 -05:00
|
|
|
dt->setTime_t(save->GetLastModificationTime());
|
|
|
|
QString datetime = dt->toUTC().toString("hh:mm - dd.MM.yyyy");
|
|
|
|
|
|
|
|
ui->label_name->setText(QString::fromWCharArray(save->GetName()));
|
|
|
|
ui->label_name->setMinimumSize(ui->label_name->sizeHint());
|
|
|
|
ui->label_id->setText(QString(save->GetId()));
|
|
|
|
QString size("%1kb");
|
|
|
|
ui->label_size->setText(size.arg(QString::number(save->GetSize() / 1000)));
|
|
|
|
ui->label_last_mod->setText(datetime);
|
|
|
|
ui->delete_save_button->setEnabled(true);
|
|
|
|
ui->export_save_button->setEnabled(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->label_name->setText("--");
|
|
|
|
ui->label_id->setText("--");
|
|
|
|
ui->label_size->setText("--");
|
|
|
|
ui->label_last_mod->setText("--");
|
|
|
|
ui->delete_save_button->setEnabled(false);
|
|
|
|
ui->export_save_button->setEnabled(false);
|
|
|
|
}
|
2016-08-10 14:56:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardManagerDialog::on_delete_save_button_clicked()
|
|
|
|
{
|
2018-01-10 14:58:25 -05:00
|
|
|
QMessageBox::StandardButton resBtn = QMessageBox::question(this, "Overwrite?",
|
|
|
|
"Are you sure you want to delete the currently selected entry",
|
|
|
|
QMessageBox::Yes | QMessageBox::No,
|
|
|
|
QMessageBox::Yes);
|
|
|
|
if(resBtn == QMessageBox::Yes)
|
|
|
|
{
|
|
|
|
int currentRow = ui->savelistWidget->currentRow();
|
|
|
|
int nItemCount = static_cast<int>(m_pCurrentMemoryCard->GetSaveCount() - 1);
|
|
|
|
if(currentRow >= 0 && currentRow <= nItemCount)
|
|
|
|
{
|
|
|
|
const CSave* save = m_pCurrentMemoryCard->GetSaveByIndex(currentRow);
|
2019-10-16 20:51:11 -04:00
|
|
|
fs::remove_all(save->GetPath());
|
2018-01-10 14:58:25 -05:00
|
|
|
m_pCurrentMemoryCard->RefreshContents();
|
|
|
|
populateSaveList();
|
|
|
|
}
|
|
|
|
}
|
2016-08-10 14:56:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryCardManagerDialog::on_export_save_button_clicked()
|
|
|
|
{
|
2018-01-10 14:58:25 -05:00
|
|
|
int currentRow = ui->savelistWidget->currentRow();
|
|
|
|
int nItemCount = static_cast<int>(m_pCurrentMemoryCard->GetSaveCount() - 1);
|
|
|
|
if(currentRow >= 0 && currentRow <= nItemCount)
|
|
|
|
{
|
|
|
|
const CSave* save = m_pCurrentMemoryCard->GetSaveByIndex(currentRow);
|
|
|
|
if(save != NULL)
|
|
|
|
{
|
|
|
|
QFileDialog dialog(this);
|
|
|
|
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
|
|
|
dialog.setNameFilter(tr("EMS Memory Adapter Save Dumps (*.psu)"));
|
|
|
|
dialog.setDefaultSuffix("psu");
|
|
|
|
if(dialog.exec())
|
|
|
|
{
|
|
|
|
QString fileName = dialog.selectedFiles().first();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2019-01-07 20:04:20 -05:00
|
|
|
auto filePath = QStringToPath(fileName);
|
|
|
|
auto output = Framework::CreateOutputStdStream(filePath.native());
|
2018-01-10 14:58:25 -05:00
|
|
|
CSaveExporter::ExportPSU(output, save->GetPath());
|
|
|
|
}
|
|
|
|
catch(const std::exception& Exception)
|
|
|
|
{
|
2018-04-30 21:01:23 +01:00
|
|
|
QString msg("Couldn't export save(s):\n\n%1");
|
2018-01-10 14:58:25 -05:00
|
|
|
QMessageBox messageBox;
|
|
|
|
messageBox.critical(this, "Error", msg.arg(Exception.what()));
|
|
|
|
messageBox.show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
QString msg("Save exported successfully.");
|
2018-01-10 14:58:25 -05:00
|
|
|
QMessageBox messageBox;
|
|
|
|
messageBox.information(this, "Success", msg);
|
|
|
|
messageBox.show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-30 21:01:23 +01:00
|
|
|
QString msg("Save export Cancelled.");
|
2018-01-10 14:58:25 -05:00
|
|
|
QMessageBox messageBox;
|
|
|
|
messageBox.warning(this, "Cancelled", msg);
|
|
|
|
messageBox.show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-30 21:01:23 +01:00
|
|
|
QString msg("Save not found,\nPlease try again.");
|
2018-01-10 14:58:25 -05:00
|
|
|
QMessageBox messageBox;
|
|
|
|
messageBox.critical(this, "Error", msg);
|
|
|
|
messageBox.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-30 21:01:23 +01:00
|
|
|
QString msg("Invalid selection,\nPlease try again.");
|
2018-01-10 14:58:25 -05:00
|
|
|
QMessageBox messageBox;
|
|
|
|
messageBox.critical(this, "Error", msg);
|
|
|
|
messageBox.show();
|
|
|
|
}
|
2016-08-10 14:56:16 +01:00
|
|
|
}
|