MemoryCard: Purge use of ByteStream

This commit is contained in:
Stenzek
2024-07-28 23:28:13 +10:00
parent b5009da2bc
commit dd8bf2c9d9
8 changed files with 86 additions and 73 deletions

View File

@ -33,6 +33,7 @@
#include "util/gpu_device.h"
#include "common/assert.h"
#include "common/error.h"
#include "common/file_system.h"
#include "common/log.h"
@ -2965,9 +2966,14 @@ void MainWindow::openMemoryCardEditor(const QString& card_a_path, const QString&
tr("Memory card '%1' does not exist. Do you want to create an empty memory card?").arg(card_path),
QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
{
if (!MemoryCardEditorWindow::createMemoryCard(card_path))
Error error;
if (!MemoryCardEditorWindow::createMemoryCard(card_path, &error))
{
QMessageBox::critical(this, tr("Memory Card Not Found"),
tr("Failed to create memory card '%1'").arg(card_path));
tr("Failed to create memory card '%1': %2")
.arg(card_path)
.arg(QString::fromStdString(error.GetDescription())));
}
}
}
}

View File

@ -96,12 +96,12 @@ bool MemoryCardEditorWindow::setCardB(const QString& path)
return true;
}
bool MemoryCardEditorWindow::createMemoryCard(const QString& path)
bool MemoryCardEditorWindow::createMemoryCard(const QString& path, Error* error)
{
MemoryCardImage::DataArray data;
MemoryCardImage::Format(&data);
return MemoryCardImage::SaveToFile(data, path.toUtf8().constData());
return MemoryCardImage::SaveToFile(data, path.toUtf8().constData(), error);
}
void MemoryCardEditorWindow::resizeEvent(QResizeEvent* ev)
@ -232,10 +232,12 @@ bool MemoryCardEditorWindow::loadCard(const QString& filename, Card* card)
return false;
}
Error error;
std::string filename_str = filename.toStdString();
if (!MemoryCardImage::LoadFromFile(&card->data, filename_str.c_str()))
if (!MemoryCardImage::LoadFromFile(&card->data, filename_str.c_str(), &error))
{
QMessageBox::critical(this, tr("Error"), tr("Failed to load memory card image."));
QMessageBox::critical(this, tr("Error"),
tr("Failed to load memory card: %1").arg(QString::fromStdString(error.GetDescription())));
return false;
}
@ -343,9 +345,11 @@ void MemoryCardEditorWindow::openCard(Card* card)
if (filename.isEmpty())
return;
if (!MemoryCardImage::LoadFromFile(&card->data, filename.toUtf8().constData()))
Error error;
if (!MemoryCardImage::LoadFromFile(&card->data, filename.toUtf8().constData(), &error))
{
QMessageBox::critical(this, tr("Error"), tr("Failed to load memory card image."));
QMessageBox::critical(this, tr("Error"),
tr("Failed to load memory card: %1").arg(QString::fromStdString(error.GetDescription())));
return;
}
@ -368,10 +372,11 @@ void MemoryCardEditorWindow::saveCard(Card* card)
if (card->filename.empty())
return;
if (!MemoryCardImage::SaveToFile(card->data, card->filename.c_str()))
Error error;
if (!MemoryCardImage::SaveToFile(card->data, card->filename.c_str(), &error))
{
QMessageBox::critical(this, tr("Error"),
tr("Failed to write card to '%1'").arg(QString::fromStdString(card->filename)));
tr("Failed to save memory card: %1").arg(QString::fromStdString(error.GetDescription())));
return;
}

View File

@ -14,6 +14,8 @@
#include <QtWidgets/QPushButton>
#include <QtWidgets/QTableWidget>
class Error;
class MemoryCardEditorWindow : public QWidget
{
Q_OBJECT
@ -25,7 +27,7 @@ public:
bool setCardA(const QString& path);
bool setCardB(const QString& path);
static bool createMemoryCard(const QString& path);
static bool createMemoryCard(const QString& path, Error* error);
protected:
void resizeEvent(QResizeEvent* ev);