GCMemcardManager: Detect attempt to import multiple save files with the same internal name.

This commit is contained in:
Admiral H. Curtiss 2021-01-27 22:15:18 +01:00
parent 74b56a8c7f
commit e47eb16641
3 changed files with 22 additions and 0 deletions

View file

@ -72,6 +72,19 @@ bool HasSameIdentity(const DEntry& lhs, const DEntry& rhs)
return true;
}
bool HasDuplicateIdentity(const std::vector<Savefile>& savefiles)
{
for (size_t i = 0; i < savefiles.size(); ++i)
{
for (size_t j = i + 1; j < savefiles.size(); ++j)
{
if (HasSameIdentity(savefiles[i].dir_entry, savefiles[j].dir_entry))
return true;
}
}
return false;
}
static void ByteswapDEntrySavHeader(std::array<u8, DENTRY_SIZE>& entry)
{
// several bytes in SAV are swapped compared to the internal memory card format

View file

@ -13,6 +13,9 @@ namespace Memcard
{
bool HasSameIdentity(const DEntry& lhs, const DEntry& rhs);
// Check if any two given savefiles have the same identity.
bool HasDuplicateIdentity(const std::vector<Savefile>& savefiles);
enum class ReadSavefileErrorCode
{
OpenFileFail,

View file

@ -515,6 +515,12 @@ void GCMemcardManager::ImportFiles(int slot, const std::vector<Memcard::Savefile
"", static_cast<int>(number_of_blocks)));
}
if (Memcard::HasDuplicateIdentity(savefiles))
{
error_messages.push_back(
tr("At least two of the selected save files have the same internal filename."));
}
for (const Memcard::Savefile& savefile : savefiles)
{
if (card->TitlePresent(savefile.dir_entry))