From c3694c4ad187d52ce815448491c482a5f5bff91f Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Tue, 2 Jun 2015 19:42:39 +0200 Subject: [PATCH] FolderMemoryCard: Abort Flush operation when remnants of an incomplete save operation are found. --- pcsx2/gui/MemoryCardFolder.cpp | 10 +++++++++- pcsx2/gui/MemoryCardFolder.h | 5 ++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pcsx2/gui/MemoryCardFolder.cpp b/pcsx2/gui/MemoryCardFolder.cpp index 51b9d9f9e2..4e060ad485 100644 --- a/pcsx2/gui/MemoryCardFolder.cpp +++ b/pcsx2/gui/MemoryCardFolder.cpp @@ -487,7 +487,7 @@ u8* FolderMemoryCard::GetSystemBlockPointer( const u32 adr ) { } else if ( block == m_superBlock.data.backup_block1 ) { src = &m_backupBlock1[( page % 16 ) * PageSize + offset]; } else if ( block == m_superBlock.data.backup_block2 ) { - src = &m_backupBlock2[( page % 16 ) * PageSize + offset]; + src = &m_backupBlock2.raw[( page % 16 ) * PageSize + offset]; } else { // trying to access indirect FAT? for ( int i = 0; i < IndirectFatClusterCount; ++i ) { @@ -737,6 +737,14 @@ void FolderMemoryCard::Flush() { FlushBlock( 0 ); if ( !IsFormatted() ) { return; } + // check if we were interrupted in the middle of a save operation, if yes abort + FlushBlock( m_superBlock.data.backup_block1 ); + FlushBlock( m_superBlock.data.backup_block2 ); + if ( m_backupBlock2.programmedBlock != 0xFFFFFFFFu ) { + Console.Warning( L"(FolderMcd) Aborting flush of slot %u, emulation was interrupted during save process!", m_slot ); + return; + } + const u32 clusterCount = GetSizeInClusters(); const u32 pageCount = clusterCount * 2; diff --git a/pcsx2/gui/MemoryCardFolder.h b/pcsx2/gui/MemoryCardFolder.h index 0a58ee030c..5b14cc865a 100644 --- a/pcsx2/gui/MemoryCardFolder.h +++ b/pcsx2/gui/MemoryCardFolder.h @@ -191,7 +191,10 @@ protected: u8 raw[IndirectFatClusterCount][ClusterSize / 4][ClusterSize]; } m_fat; u8 m_backupBlock1[BlockSize]; - u8 m_backupBlock2[BlockSize]; + union backupBlock2Union { + u32 programmedBlock; + u8 raw[BlockSize]; + } m_backupBlock2; // stores directory and file metadata std::map m_fileEntryDict;