From 41c3eacb6fbd9ae33fecb7985d71752e9d175cc5 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Mon, 1 Jun 2015 18:18:15 +0200 Subject: [PATCH] FolderMemoryCard: Move file existence check into the helper class, so that it gets called much less often. This *drastically* increases performance, bizarrely enough. --- pcsx2/gui/MemoryCardFolder.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pcsx2/gui/MemoryCardFolder.cpp b/pcsx2/gui/MemoryCardFolder.cpp index e0f147a5ea..0f243a5d74 100644 --- a/pcsx2/gui/MemoryCardFolder.cpp +++ b/pcsx2/gui/MemoryCardFolder.cpp @@ -589,9 +589,6 @@ bool FolderMemoryCard::ReadFromFile( u8 *dest, u32 adr, u32 dataLength ) { u32 clusterNumber; const MemoryCardFileEntry* const entry = GetFileEntryFromFileDataCluster( m_superBlock.data.rootdir_cluster, fatCluster, &fileName, fileName.GetDirCount(), &clusterNumber ); if ( entry != nullptr ) { - if ( !fileName.DirExists() ) { - fileName.Mkdir(); - } wxFFile* file = m_lastAccessedFile.ReOpen( fileName.GetFullPath(), L"rb" ); if ( file->IsOpened() ) { const u32 clusterOffset = ( page % 2 ) * PageSize + offset; @@ -879,13 +876,6 @@ bool FolderMemoryCard::WriteToFile( const u8* src, u32 adr, u32 dataLength ) { u32 clusterNumber; const MemoryCardFileEntry* const entry = GetFileEntryFromFileDataCluster( m_superBlock.data.rootdir_cluster, fatCluster, &fileName, fileName.GetDirCount(), &clusterNumber ); if ( entry != nullptr ) { - if ( !fileName.DirExists() ) { - fileName.Mkdir(); - } - if ( !fileName.FileExists() ) { - wxFFile createEmptyFile( fileName.GetFullPath(), L"wb" ); - createEmptyFile.Close(); - } wxFFile* file = m_lastAccessedFile.ReOpen( fileName.GetFullPath(), L"r+b" ); if ( file->IsOpened() ) { const u32 clusterOffset = ( page % 2 ) * PageSize + offset; @@ -1061,6 +1051,16 @@ FileAccessHelper::~FileAccessHelper() { wxFFile* FileAccessHelper::Open( const wxString& filename, const wxString& mode ) { this->Close(); + + wxFileName fn( filename ); + if ( !fn.FileExists() ) { + if ( !fn.DirExists() ) { + fn.Mkdir(); + } + wxFFile createEmptyFile( filename, L"wb" ); + createEmptyFile.Close(); + } + m_file = new wxFFile( filename, mode ); m_filename = filename; m_mode = mode;