Merge pull request #1275 from AdmiralCurtiss/memcard-plugin-switch-filter-reset

Move folder memcard filter management into the actual folder memcard class to fix #1179 and similar.
This commit is contained in:
Jonathan Li 2016-04-06 23:59:36 +01:00
commit 0ab7b6340d
8 changed files with 67 additions and 30 deletions

View File

@ -1109,7 +1109,7 @@ typedef struct _PS2E_ComponentAPI_Mcd
// Used by the FolderMemoryCard to find a good time to flush written data to the host file system. // Used by the FolderMemoryCard to find a good time to flush written data to the host file system.
void (PS2E_CALLBACK* McdNextFrame)( PS2E_THISPTR thisptr, uint port, uint slot ); void (PS2E_CALLBACK* McdNextFrame)( PS2E_THISPTR thisptr, uint port, uint slot );
void (PS2E_CALLBACK* McdReIndex)( PS2E_THISPTR thisptr, uint port, uint slot, const wxString& filter ); bool (PS2E_CALLBACK* McdReIndex)( PS2E_THISPTR thisptr, uint port, uint slot, const wxString& filter );
void* reserved[6]; void* reserved[6];

View File

@ -70,8 +70,8 @@ void SysPluginBindings::McdNextFrame( uint port, uint slot ) {
Mcd->McdNextFrame( (PS2E_THISPTR) Mcd, port, slot ); Mcd->McdNextFrame( (PS2E_THISPTR) Mcd, port, slot );
} }
void SysPluginBindings::McdReIndex( uint port, uint slot, const wxString& filter ) { bool SysPluginBindings::McdReIndex( uint port, uint slot, const wxString& filter ) {
Mcd->McdReIndex( (PS2E_THISPTR) Mcd, port, slot, filter ); return Mcd->McdReIndex( (PS2E_THISPTR) Mcd, port, slot, filter );
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -242,7 +242,7 @@ public:
void McdEraseBlock( uint port, uint slot, u32 adr ); void McdEraseBlock( uint port, uint slot, u32 adr );
u64 McdGetCRC( uint port, uint slot ); u64 McdGetCRC( uint port, uint slot );
void McdNextFrame( uint port, uint slot ); void McdNextFrame( uint port, uint slot );
void McdReIndex( uint port, uint slot, const wxString& filter ); bool McdReIndex( uint port, uint slot, const wxString& filter );
friend class SysCorePlugins; friend class SysCorePlugins;
}; };

View File

@ -53,18 +53,30 @@ wxString GetTimeMsStr(){
} }
//allow timeout also for the mcd manager panel //allow timeout also for the mcd manager panel
void SetForceMcdEjectTimeoutNow() void SetForceMcdEjectTimeoutNow( uint port, uint slot )
{ {
for( u8 port=0; port<2; ++port )
for( u8 slot=0; slot<4; ++slot )
mcds[port][slot].ForceEjection_Timeout = FORCED_MCD_EJECTION_MAX_TRIES; mcds[port][slot].ForceEjection_Timeout = FORCED_MCD_EJECTION_MAX_TRIES;
} }
void SetForceMcdEjectTimeoutNow()
{
for ( uint port = 0; port < 2; ++port ) {
for ( uint slot = 0; slot < 4; ++slot ) {
SetForceMcdEjectTimeoutNow( port, slot );
}
}
}
void ClearMcdEjectTimeoutNow( uint port, uint slot )
{
mcds[port][slot].ForceEjection_Timeout = 0;
}
void ClearMcdEjectTimeoutNow() void ClearMcdEjectTimeoutNow()
{ {
for( u8 port=0; port<2; ++port ) for ( uint port = 0; port < 2; ++port ) {
for( u8 slot=0; slot<4; ++slot ) for ( uint slot = 0; slot < 4; ++slot ) {
mcds[port][slot].ForceEjection_Timeout = 0; ClearMcdEjectTimeoutNow( port, slot );
}
}
} }
// SIO Inline'd IRQs : Calls the SIO interrupt handlers directly instead of // SIO Inline'd IRQs : Calls the SIO interrupt handlers directly instead of
@ -886,18 +898,14 @@ void sioNextFrame() {
} }
} }
// Used to figure out when a new game boots, so that memory cards can re-index themselves and only load data relevant to that game.
wxString SioCurrentGameSerial = L"";
void sioSetGameSerial( const wxString& serial ) { void sioSetGameSerial( const wxString& serial ) {
if ( serial == SioCurrentGameSerial ) { return; }
SioCurrentGameSerial = serial;
for ( uint port = 0; port < 2; ++port ) { for ( uint port = 0; port < 2; ++port ) {
for ( uint slot = 0; slot < 4; ++slot ) { for ( uint slot = 0; slot < 4; ++slot ) {
mcds[port][slot].ReIndex( serial ); if ( mcds[port][slot].ReIndex( serial ) ) {
SetForceMcdEjectTimeoutNow( port, slot );
}
} }
} }
SetForceMcdEjectTimeoutNow();
} }
void SaveStateBase::sioFreeze() void SaveStateBase::sioFreeze()

View File

@ -87,8 +87,8 @@ struct _mcd
SysPlugins.McdNextFrame( port, slot ); SysPlugins.McdNextFrame( port, slot );
} }
void ReIndex(const wxString& filter = L"") { bool ReIndex(const wxString& filter = L"") {
SysPlugins.McdReIndex( port, slot, filter ); return SysPlugins.McdReIndex( port, slot, filter );
} }
}; };

View File

@ -563,17 +563,17 @@ static void PS2E_CALLBACK FileMcd_NextFrame( PS2E_THISPTR thisptr, uint port, ui
} }
} }
static void PS2E_CALLBACK FileMcd_ReIndex( PS2E_THISPTR thisptr, uint port, uint slot, const wxString& filter ) { static bool PS2E_CALLBACK FileMcd_ReIndex( PS2E_THISPTR thisptr, uint port, uint slot, const wxString& filter ) {
const uint combinedSlot = FileMcd_ConvertToSlot( port, slot ); const uint combinedSlot = FileMcd_ConvertToSlot( port, slot );
switch ( g_Conf->Mcd[combinedSlot].Type ) { switch ( g_Conf->Mcd[combinedSlot].Type ) {
//case MemoryCardType::MemoryCard_File: //case MemoryCardType::MemoryCard_File:
// thisptr->impl.ReIndex( combinedSlot, filter ); // return thisptr->impl.ReIndex( combinedSlot, filter );
// break; // break;
case MemoryCardType::MemoryCard_Folder: case MemoryCardType::MemoryCard_Folder:
thisptr->implFolder.ReIndex( combinedSlot, g_Conf->EmuOptions.McdFolderAutoManage, filter ); return thisptr->implFolder.ReIndex( combinedSlot, g_Conf->EmuOptions.McdFolderAutoManage, filter );
break; break;
default: default:
return; return false;
} }
} }

View File

@ -32,6 +32,8 @@ FolderMemoryCard::FolderMemoryCard() {
m_performFileWrites = false; m_performFileWrites = false;
m_framesUntilFlush = 0; m_framesUntilFlush = 0;
m_timeLastWritten = 0; m_timeLastWritten = 0;
m_filteringEnabled = false;
m_filteringString = L"";
} }
void FolderMemoryCard::InitializeInternalData() { void FolderMemoryCard::InitializeInternalData() {
@ -42,12 +44,14 @@ void FolderMemoryCard::InitializeInternalData() {
memset( &m_backupBlock2, 0xFF, sizeof( m_backupBlock2 ) ); memset( &m_backupBlock2, 0xFF, sizeof( m_backupBlock2 ) );
m_cache.clear(); m_cache.clear();
m_oldDataCache.clear(); m_oldDataCache.clear();
m_lastAccessedFile.CloseAll();
m_fileMetadataQuickAccess.clear(); m_fileMetadataQuickAccess.clear();
m_timeLastWritten = 0; m_timeLastWritten = 0;
m_isEnabled = false; m_isEnabled = false;
m_framesUntilFlush = 0; m_framesUntilFlush = 0;
m_lastAccessedFile.CloseAll();
m_performFileWrites = true; m_performFileWrites = true;
m_filteringEnabled = false;
m_filteringString = L"";
} }
bool FolderMemoryCard::IsFormatted() const { bool FolderMemoryCard::IsFormatted() const {
@ -94,6 +98,8 @@ void FolderMemoryCard::Open( const wxString& fullPath, const AppConfig::McdOptio
if ( disabled ) return; if ( disabled ) return;
m_isEnabled = true; m_isEnabled = true;
m_filteringEnabled = enableFiltering;
m_filteringString = filter;
LoadMemoryCardData( sizeInClusters, enableFiltering, filter ); LoadMemoryCardData( sizeInClusters, enableFiltering, filter );
SetTimeLastWrittenToNow(); SetTimeLastWrittenToNow();
@ -113,6 +119,18 @@ void FolderMemoryCard::Close( bool flush ) {
m_fileMetadataQuickAccess.clear(); m_fileMetadataQuickAccess.clear();
} }
bool FolderMemoryCard::ReIndex( bool enableFiltering, const wxString& filter ) {
if ( !m_isEnabled ) { return false; }
if ( m_filteringEnabled != enableFiltering || m_filteringString != filter ) {
Close();
Open( enableFiltering, filter );
return true;
}
return false;
}
void FolderMemoryCard::LoadMemoryCardData( const u32 sizeInClusters, const bool enableFiltering, const wxString& filter ) { void FolderMemoryCard::LoadMemoryCardData( const u32 sizeInClusters, const bool enableFiltering, const wxString& filter ) {
bool formatted = false; bool formatted = false;
@ -1648,11 +1666,13 @@ void FolderMemoryCardAggregator::NextFrame( uint slot ) {
m_cards[slot].NextFrame(); m_cards[slot].NextFrame();
} }
void FolderMemoryCardAggregator::ReIndex( uint slot, const bool enableFiltering, const wxString& filter ) { bool FolderMemoryCardAggregator::ReIndex( uint slot, const bool enableFiltering, const wxString& filter ) {
m_cards[slot].Close(); if ( m_cards[slot].ReIndex( enableFiltering, filter ) ) {
m_cards[slot].Open( enableFiltering, filter );
SetFiltering( enableFiltering ); SetFiltering( enableFiltering );
m_lastKnownFilter = filter; m_lastKnownFilter = filter;
return true;
}
return false;
} }

View File

@ -327,6 +327,10 @@ protected:
// if set to false, nothing is actually written to the file system while flushing, and data is discarded instead // if set to false, nothing is actually written to the file system while flushing, and data is discarded instead
bool m_performFileWrites; bool m_performFileWrites;
// currently active filter settings
bool m_filteringEnabled;
wxString m_filteringString;
public: public:
FolderMemoryCard(); FolderMemoryCard();
virtual ~FolderMemoryCard() throw() {} virtual ~FolderMemoryCard() throw() {}
@ -341,6 +345,11 @@ public:
// Close the memory card and flush changes to the file system. Set flush to false to not store changes. // Close the memory card and flush changes to the file system. Set flush to false to not store changes.
void Close( bool flush = true ); void Close( bool flush = true );
// Closes and reopens card with given filter options if they differ from the current ones (returns true),
// or does nothing if they match already (returns false).
// Does nothing and returns false when called on a closed memory card.
bool ReIndex( bool enableFiltering, const wxString& filter );
s32 IsPresent() const; s32 IsPresent() const;
void GetSizeInfo( PS2E_McdSizeInfo& outways ) const; void GetSizeInfo( PS2E_McdSizeInfo& outways ) const;
bool IsPSX() const; bool IsPSX() const;
@ -562,5 +571,5 @@ public:
s32 EraseBlock( uint slot, u32 adr ); s32 EraseBlock( uint slot, u32 adr );
u64 GetCRC( uint slot ); u64 GetCRC( uint slot );
void NextFrame( uint slot ); void NextFrame( uint slot );
void ReIndex( uint slot, const bool enableFiltering, const wxString& filter ); bool ReIndex( uint slot, const bool enableFiltering, const wxString& filter );
}; };