diff --git a/pcsx2/gui/MemoryCardFolder.cpp b/pcsx2/gui/MemoryCardFolder.cpp index 6708e62aeb..2bca4591f0 100644 --- a/pcsx2/gui/MemoryCardFolder.cpp +++ b/pcsx2/gui/MemoryCardFolder.cpp @@ -1396,7 +1396,10 @@ wxFFile* FileAccessHelper::Open( const wxFileName& folderName, MemoryCardFileMet const MemoryCardFileEntry* const entry = fileRef->entry; wxFFile* file = new wxFFile( filename, L"r+b" ); - m_files.emplace( entry, file ); + + std::string internalPath; + fileRef->GetInternalPath( &internalPath ); + m_files.emplace( internalPath, file ); if ( writeMetadata ) { fn.AppendDir( L"_pcsx2_meta" ); @@ -1444,7 +1447,9 @@ void FileAccessHelper::WriteMetadata( bool metadataIsNonstandard, wxFileName& me } wxFFile* FileAccessHelper::ReOpen( const wxFileName& folderName, MemoryCardFileMetadataReference* fileRef, bool writeMetadata ) { - auto it = m_files.find( fileRef->entry ); + std::string internalPath; + fileRef->GetInternalPath( &internalPath ); + auto it = m_files.find( internalPath ); if ( it != m_files.end() ) { // we already have a handle to this file @@ -1486,7 +1491,7 @@ void FileAccessHelper::CloseMatching( const wxString& path ) { for ( auto it = m_files.begin(); it != m_files.end(); ) { wxString openPath = it->second->GetName(); if ( openPath.StartsWith( pathNormalized ) ) { - CloseFileHandle( it->second, it->first ); + CloseFileHandle( it->second, nullptr ); it = m_files.erase( it ); } else { ++it; @@ -1496,7 +1501,7 @@ void FileAccessHelper::CloseMatching( const wxString& path ) { void FileAccessHelper::CloseAll() { for ( auto it = m_files.begin(); it != m_files.end(); ++it ) { - CloseFileHandle( it->second, it->first ); + CloseFileHandle( it->second, nullptr ); } m_files.clear(); } @@ -1547,6 +1552,17 @@ bool MemoryCardFileMetadataReference::GetPath( wxFileName* fileName ) const { return parentCleaned || localCleaned; } +void MemoryCardFileMetadataReference::GetInternalPath( std::string* fileName ) const { + if ( parent ) { + parent->GetInternalPath( fileName ); + } + + fileName->append( (const char*)entry->entry.data.name ); + + if ( entry->IsDir() ) { + fileName->append( "/" ); + } +} FolderMemoryCardAggregator::FolderMemoryCardAggregator() { for ( uint i = 0; i < TotalCardSlots; ++i ) { diff --git a/pcsx2/gui/MemoryCardFolder.h b/pcsx2/gui/MemoryCardFolder.h index 31b23ee2fe..08c6bbf11e 100644 --- a/pcsx2/gui/MemoryCardFolder.h +++ b/pcsx2/gui/MemoryCardFolder.h @@ -197,6 +197,9 @@ struct MemoryCardFileMetadataReference { // returns true if filename was modified and metadata containing the actual filename should be written bool GetPath( wxFileName* fileName ) const; + + // gives the internal memory card file system path, not to be used for writes to the host file system + void GetInternalPath( std::string* fileName ) const; }; // -------------------------------------------------------------------------------------- @@ -205,7 +208,7 @@ struct MemoryCardFileMetadataReference { // Small helper class to keep memory card files opened between calls to Read()/Save() class FileAccessHelper { protected: - std::map m_files; + std::map m_files; MemoryCardFileMetadataReference* m_lastWrittenFileRef; // we remember this to reduce redundant metadata checks/writes public: