diff --git a/pcsx2/gui/MemoryCardFolder.cpp b/pcsx2/gui/MemoryCardFolder.cpp index f7adc8d92f..c5cfd1767e 100644 --- a/pcsx2/gui/MemoryCardFolder.cpp +++ b/pcsx2/gui/MemoryCardFolder.cpp @@ -1410,6 +1410,17 @@ wxFFile* FileAccessHelper::ReOpen( const wxFileName& folderName, MemoryCardFileM } } +void FileAccessHelper::CloseFileHandle( wxFFile* file, const MemoryCardFileEntry* entry ) { + file->Close(); + + if ( entry != nullptr ) { + wxFileName fn( file->GetName() ); + fn.SetTimes( nullptr, &entry->entry.data.timeModified.ToWxDateTime(), &entry->entry.data.timeCreated.ToWxDateTime() ); + } + + delete file; +} + void FileAccessHelper::CloseMatching( const wxString& path ) { wxFileName fn( path ); fn.Normalize(); @@ -1417,8 +1428,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 ) ) { - it->second->Close(); - delete it->second; + CloseFileHandle( it->second, it->first ); it = m_files.erase( it ); } else { ++it; @@ -1428,8 +1438,7 @@ void FileAccessHelper::CloseMatching( const wxString& path ) { void FileAccessHelper::CloseAll() { for ( auto it = m_files.begin(); it != m_files.end(); ++it ) { - it->second->Close(); - delete it->second; + CloseFileHandle( it->second, it->first ); } m_files.clear(); } diff --git a/pcsx2/gui/MemoryCardFolder.h b/pcsx2/gui/MemoryCardFolder.h index 9886bd4093..c09b23d0b3 100644 --- a/pcsx2/gui/MemoryCardFolder.h +++ b/pcsx2/gui/MemoryCardFolder.h @@ -85,6 +85,19 @@ struct MemoryCardFileEntryDateTime { return t; } + wxDateTime ToWxDateTime() const { + wxDateTime::Tm tm; + tm.sec = this->second; + tm.min = this->minute; + tm.hour = this->hour; + tm.mday = this->day; + tm.mon = (wxDateTime::Month)(this->month - 1); + tm.year = this->year; + + wxDateTime time( tm ); + return time.FromTimezone( wxDateTime::GMT9 ); + } + bool operator==( const MemoryCardFileEntryDateTime& other ) const { return unused == other.unused && second == other.second && minute == other.minute && hour == other.hour && day == other.day && month == other.month && year == other.year; @@ -210,6 +223,9 @@ public: protected: // Open a new file and remember it for later wxFFile* Open( const wxFileName& folderName, MemoryCardFileMetadataReference* fileRef, bool writeMetadata = false ); + // Close a file and delete its handle + // If entry is given, it also attempts to set the created and modified timestamps of the file according to the entry + void CloseFileHandle( wxFFile* file, const MemoryCardFileEntry* entry = nullptr ); void WriteMetadata( const wxFileName& folderName, MemoryCardFileMetadataReference* fileRef ); void WriteMetadata( bool metadataIsNonstandard, const wxFileName& metadataFilename, const MemoryCardFileEntry* const entry );