GCMemcardDirectory: Compare GCI files in GetFileNamesForGameID() by their identity instead of their default filename.

This commit is contained in:
Admiral H. Curtiss 2022-11-07 06:16:34 +01:00
parent 4b0312ecf8
commit 1089d3cab6
No known key found for this signature in database
GPG key ID: F051B4C4044F33FB
3 changed files with 11 additions and 11 deletions

View file

@ -125,8 +125,7 @@ bool GCMemcardDirectory::LoadGCI(Memcard::GCIFile gci)
// This is only used by NetPlay but it made sense to put it here to keep the relevant code together // This is only used by NetPlay but it made sense to put it here to keep the relevant code together
std::vector<std::string> GCMemcardDirectory::GetFileNamesForGameID(const std::string& directory, std::vector<std::string> GCMemcardDirectory::GetFileNamesForGameID(const std::string& directory,
const std::string& game_id, const std::string& game_id)
bool card_encoding_is_shift_jis)
{ {
std::vector<std::string> filenames; std::vector<std::string> filenames;
@ -134,7 +133,7 @@ std::vector<std::string> GCMemcardDirectory::GetFileNamesForGameID(const std::st
if (game_id.length() >= 4 && game_id != "00000000") if (game_id.length() >= 4 && game_id != "00000000")
game_code = Common::swap32(reinterpret_cast<const u8*>(game_id.c_str())); game_code = Common::swap32(reinterpret_cast<const u8*>(game_id.c_str()));
std::vector<std::string> loaded_saves; std::vector<Memcard::DEntry> loaded_saves;
for (const std::string& file_name : Common::DoFileSearch({directory}, {".gci"})) for (const std::string& file_name : Common::DoFileSearch({directory}, {".gci"}))
{ {
File::IOFile gci_file(file_name, "rb"); File::IOFile gci_file(file_name, "rb");
@ -147,9 +146,11 @@ std::vector<std::string> GCMemcardDirectory::GetFileNamesForGameID(const std::st
if (!gci_file.ReadBytes(&gci.m_gci_header, Memcard::DENTRY_SIZE)) if (!gci_file.ReadBytes(&gci.m_gci_header, Memcard::DENTRY_SIZE))
continue; continue;
const std::string gci_filename = const auto same_identity_save_it = std::find_if(
GenerateDefaultGCIFilename(gci.m_gci_header, card_encoding_is_shift_jis); loaded_saves.begin(), loaded_saves.end(), [&gci](const Memcard::DEntry& entry) {
if (std::find(loaded_saves.begin(), loaded_saves.end(), gci_filename) != loaded_saves.end()) return Memcard::HasSameIdentity(gci.m_gci_header, entry);
});
if (same_identity_save_it != loaded_saves.end())
continue; continue;
const u16 num_blocks = gci.m_gci_header.m_block_count; const u16 num_blocks = gci.m_gci_header.m_block_count;
@ -169,7 +170,7 @@ std::vector<std::string> GCMemcardDirectory::GetFileNamesForGameID(const std::st
if (game_code == Common::swap32(gci.m_gci_header.m_gamecode.data())) if (game_code == Common::swap32(gci.m_gci_header.m_gamecode.data()))
{ {
loaded_saves.push_back(gci_filename); loaded_saves.push_back(gci.m_gci_header);
filenames.push_back(file_name); filenames.push_back(file_name);
} }
} }

View file

@ -32,8 +32,7 @@ public:
GCMemcardDirectory& operator=(GCMemcardDirectory&&) = delete; GCMemcardDirectory& operator=(GCMemcardDirectory&&) = delete;
static std::vector<std::string> GetFileNamesForGameID(const std::string& directory, static std::vector<std::string> GetFileNamesForGameID(const std::string& directory,
const std::string& game_id, const std::string& game_id);
bool card_encoding_is_shift_jis);
void FlushToFile(); void FlushToFile();
void FlushThread(); void FlushThread();
s32 Read(u32 src_address, s32 length, u8* dest_address) override; s32 Read(u32 src_address, s32 length, u8* dest_address) override;

View file

@ -1734,8 +1734,8 @@ bool NetPlayServer::SyncSaveData(const SaveSyncInfo& sync_info)
if (File::IsDirectory(path)) if (File::IsDirectory(path))
{ {
std::vector<std::string> files = GCMemcardDirectory::GetFileNamesForGameID( std::vector<std::string> files =
path + DIR_SEP, sync_info.game->GetGameID(), gamecube_region == DiscIO::Region::NTSC_J); GCMemcardDirectory::GetFileNamesForGameID(path + DIR_SEP, sync_info.game->GetGameID());
pac << static_cast<u8>(files.size()); pac << static_cast<u8>(files.size());