Merge pull request #8873 from AdmiralCurtiss/gcmemcard-namespace

GCMemcard: Move into a Memcard namespace.
This commit is contained in:
Tilka
2020-06-16 19:55:06 +01:00
committed by GitHub
17 changed files with 156 additions and 118 deletions

View File

@ -75,7 +75,7 @@ bool GCMemcardCreateNewDialog::CreateCard()
return false;
const std::string p = path.toStdString();
auto memcard = GCMemcard::Create(p, size, is_shift_jis);
auto memcard = Memcard::GCMemcard::Create(p, size, is_shift_jis);
if (memcard && memcard->Save())
{
m_card_path = p;

View File

@ -248,7 +248,7 @@ void GCMemcardManager::UpdateSlotTable(int slot)
m_slot_stat_label[slot]->setText(tr("%1 Free Blocks; %2 Free Dir Entries")
.arg(memcard->GetFreeBlocks())
.arg(DIRLEN - memcard->GetNumFiles()));
.arg(Memcard::DIRLEN - memcard->GetNumFiles()));
}
void GCMemcardManager::UpdateActions()
@ -268,12 +268,12 @@ void GCMemcardManager::UpdateActions()
void GCMemcardManager::SetSlotFile(int slot, QString path)
{
auto [error_code, memcard] = GCMemcard::Open(path.toStdString());
auto [error_code, memcard] = Memcard::GCMemcard::Open(path.toStdString());
if (!error_code.HasCriticalErrors() && memcard && memcard->IsValid())
{
m_slot_file_edit[slot]->setText(path);
m_slot_memcard[slot] = std::make_unique<GCMemcard>(std::move(*memcard));
m_slot_memcard[slot] = std::make_unique<Memcard::GCMemcard>(std::move(*memcard));
}
else
{
@ -336,7 +336,7 @@ void GCMemcardManager::ExportFiles(bool prompt)
// TODO: This is obviously intended to check for success instead.
const auto exportRetval = memcard->ExportGci(file_index, path.toStdString(), "");
if (exportRetval == GCMemcardExportFileRetVal::UNUSED)
if (exportRetval == Memcard::GCMemcardExportFileRetVal::UNUSED)
{
File::Delete(path.toStdString());
}
@ -366,7 +366,7 @@ void GCMemcardManager::ImportFile()
const auto result = m_slot_memcard[m_active_slot]->ImportGci(path.toStdString());
if (result != GCMemcardImportFileRetVal::SUCCESS)
if (result != Memcard::GCMemcardImportFileRetVal::SUCCESS)
{
ModalMessageBox::critical(this, tr("Import failed"), tr("Failed to import \"%1\".").arg(path));
return;
@ -392,7 +392,7 @@ void GCMemcardManager::CopyFiles()
const auto result = m_slot_memcard[!m_active_slot]->CopyFrom(*memcard, file_index);
if (result != GCMemcardImportFileRetVal::SUCCESS)
if (result != Memcard::GCMemcardImportFileRetVal::SUCCESS)
{
ModalMessageBox::warning(this, tr("Copy failed"), tr("Failed to copy file"));
}
@ -436,7 +436,7 @@ void GCMemcardManager::DeleteFiles()
for (int file_index : file_indices)
{
if (memcard->RemoveFile(file_index) != GCMemcardRemoveFileRetVal::SUCCESS)
if (memcard->RemoveFile(file_index) != Memcard::GCMemcardRemoveFileRetVal::SUCCESS)
{
ModalMessageBox::warning(this, tr("Remove failed"), tr("Failed to remove file"));
}
@ -522,8 +522,8 @@ QPixmap GCMemcardManager::GetBannerFromSaveFile(int file_index, int slot)
QImage image;
if (pxdata)
{
image = QImage(reinterpret_cast<u8*>(pxdata->data()), MEMORY_CARD_BANNER_WIDTH,
MEMORY_CARD_BANNER_HEIGHT, QImage::Format_ARGB32);
image = QImage(reinterpret_cast<u8*>(pxdata->data()), Memcard::MEMORY_CARD_BANNER_WIDTH,
Memcard::MEMORY_CARD_BANNER_HEIGHT, QImage::Format_ARGB32);
}
return QPixmap::fromImage(image);
@ -545,7 +545,8 @@ GCMemcardManager::IconAnimationData GCMemcardManager::GetIconFromSaveFile(int fi
for (size_t f = 0; f < decoded_data->size(); ++f)
{
QImage img(reinterpret_cast<const u8*>((*decoded_data)[f].image_data.data()),
MEMORY_CARD_ICON_WIDTH, MEMORY_CARD_ICON_HEIGHT, QImage::Format_ARGB32);
Memcard::MEMORY_CARD_ICON_WIDTH, Memcard::MEMORY_CARD_ICON_HEIGHT,
QImage::Format_ARGB32);
frame_data.m_frames.push_back(QPixmap::fromImage(img));
for (int i = 0; i < (*decoded_data)[f].delay; ++i)
{
@ -579,32 +580,32 @@ GCMemcardManager::IconAnimationData GCMemcardManager::GetIconFromSaveFile(int fi
return frame_data;
}
QString GCMemcardManager::GetErrorMessagesForErrorCode(const GCMemcardErrorCode& code)
QString GCMemcardManager::GetErrorMessagesForErrorCode(const Memcard::GCMemcardErrorCode& code)
{
QStringList sl;
if (code.Test(GCMemcardValidityIssues::FAILED_TO_OPEN))
if (code.Test(Memcard::GCMemcardValidityIssues::FAILED_TO_OPEN))
sl.push_back(tr("Couldn't open file."));
if (code.Test(GCMemcardValidityIssues::IO_ERROR))
if (code.Test(Memcard::GCMemcardValidityIssues::IO_ERROR))
sl.push_back(tr("Couldn't read file."));
if (code.Test(GCMemcardValidityIssues::INVALID_CARD_SIZE))
if (code.Test(Memcard::GCMemcardValidityIssues::INVALID_CARD_SIZE))
sl.push_back(tr("Filesize does not match any known GameCube Memory Card size."));
if (code.Test(GCMemcardValidityIssues::MISMATCHED_CARD_SIZE))
if (code.Test(Memcard::GCMemcardValidityIssues::MISMATCHED_CARD_SIZE))
sl.push_back(tr("Filesize in header mismatches actual card size."));
if (code.Test(GCMemcardValidityIssues::INVALID_CHECKSUM))
if (code.Test(Memcard::GCMemcardValidityIssues::INVALID_CHECKSUM))
sl.push_back(tr("Invalid checksums."));
if (code.Test(GCMemcardValidityIssues::FREE_BLOCK_MISMATCH))
if (code.Test(Memcard::GCMemcardValidityIssues::FREE_BLOCK_MISMATCH))
sl.push_back(tr("Mismatch between free block count in header and actually unused blocks."));
if (code.Test(GCMemcardValidityIssues::DIR_BAT_INCONSISTENT))
if (code.Test(Memcard::GCMemcardValidityIssues::DIR_BAT_INCONSISTENT))
sl.push_back(tr("Mismatch between internal data structures."));
if (code.Test(GCMemcardValidityIssues::DATA_IN_UNUSED_AREA))
if (code.Test(Memcard::GCMemcardValidityIssues::DATA_IN_UNUSED_AREA))
sl.push_back(tr("Data in area of file that should be unused."));
if (sl.empty())

View File

@ -13,8 +13,11 @@
#include "Common/CommonTypes.h"
namespace Memcard
{
class GCMemcard;
class GCMemcardErrorCode;
} // namespace Memcard
class QDialogButtonBox;
class QGroupBox;
@ -33,7 +36,7 @@ public:
explicit GCMemcardManager(QWidget* parent = nullptr);
~GCMemcardManager();
static QString GetErrorMessagesForErrorCode(const GCMemcardErrorCode& code);
static QString GetErrorMessagesForErrorCode(const Memcard::GCMemcardErrorCode& code);
private:
struct IconAnimationData;
@ -73,7 +76,7 @@ private:
// Slots
static constexpr int SLOT_COUNT = 2;
std::array<std::vector<IconAnimationData>, SLOT_COUNT> m_slot_active_icons;
std::array<std::unique_ptr<GCMemcard>, SLOT_COUNT> m_slot_memcard;
std::array<std::unique_ptr<Memcard::GCMemcard>, SLOT_COUNT> m_slot_memcard;
std::array<QGroupBox*, SLOT_COUNT> m_slot_group;
std::array<QLineEdit*, SLOT_COUNT> m_slot_file_edit;
std::array<QPushButton*, SLOT_COUNT> m_slot_open_button;

View File

@ -210,7 +210,7 @@ void GameCubePane::OnConfigPressed(int slot)
{
if (File::Exists(filename.toStdString()))
{
auto [error_code, mc] = GCMemcard::Open(filename.toStdString());
auto [error_code, mc] = Memcard::GCMemcard::Open(filename.toStdString());
if (error_code.HasCriticalErrors() || !mc || !mc->IsValid())
{