FolderMemoryCard: Abort Flush operation when remnants of an incomplete save operation are found.

This commit is contained in:
Admiral H. Curtiss 2015-06-02 19:42:39 +02:00
parent 541a254c60
commit c3694c4ad1
2 changed files with 13 additions and 2 deletions

View File

@ -487,7 +487,7 @@ u8* FolderMemoryCard::GetSystemBlockPointer( const u32 adr ) {
} else if ( block == m_superBlock.data.backup_block1 ) { } else if ( block == m_superBlock.data.backup_block1 ) {
src = &m_backupBlock1[( page % 16 ) * PageSize + offset]; src = &m_backupBlock1[( page % 16 ) * PageSize + offset];
} else if ( block == m_superBlock.data.backup_block2 ) { } else if ( block == m_superBlock.data.backup_block2 ) {
src = &m_backupBlock2[( page % 16 ) * PageSize + offset]; src = &m_backupBlock2.raw[( page % 16 ) * PageSize + offset];
} else { } else {
// trying to access indirect FAT? // trying to access indirect FAT?
for ( int i = 0; i < IndirectFatClusterCount; ++i ) { for ( int i = 0; i < IndirectFatClusterCount; ++i ) {
@ -737,6 +737,14 @@ void FolderMemoryCard::Flush() {
FlushBlock( 0 ); FlushBlock( 0 );
if ( !IsFormatted() ) { return; } 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 clusterCount = GetSizeInClusters();
const u32 pageCount = clusterCount * 2; const u32 pageCount = clusterCount * 2;

View File

@ -191,7 +191,10 @@ protected:
u8 raw[IndirectFatClusterCount][ClusterSize / 4][ClusterSize]; u8 raw[IndirectFatClusterCount][ClusterSize / 4][ClusterSize];
} m_fat; } m_fat;
u8 m_backupBlock1[BlockSize]; u8 m_backupBlock1[BlockSize];
u8 m_backupBlock2[BlockSize]; union backupBlock2Union {
u32 programmedBlock;
u8 raw[BlockSize];
} m_backupBlock2;
// stores directory and file metadata // stores directory and file metadata
std::map<u32, MemoryCardFileEntryCluster> m_fileEntryDict; std::map<u32, MemoryCardFileEntryCluster> m_fileEntryDict;