FolderMemoryCard: Allow multiple save names in the save file filtering.

Split multiple save names to be filtered with a "/", ie the filter "A/B" matches both save folders that contain "A" and save folders that contain "B".
This commit is contained in:
Admiral H. Curtiss 2015-05-22 19:30:41 +02:00
parent 880be6f602
commit 2ee1cb81dd
1 changed files with 28 additions and 1 deletions

View File

@ -264,6 +264,26 @@ MemoryCardFileEntry* FolderMemoryCard::AppendFileEntryToDir( MemoryCardFileEntry
return newFileEntry;
}
bool FilterMatches( const wxString& fileName, const wxString& filter ) {
size_t start = 0;
size_t len = filter.Len();
while ( start < len ) {
size_t end = filter.find( '/', start );
if ( end == wxString::npos ) {
end = len;
}
wxString singleFilter = filter.Mid( start, end - start );
if ( fileName.Contains( singleFilter ) ) {
return true;
}
start = end + 1;
}
return false;
}
bool FolderMemoryCard::AddFolder( MemoryCardFileEntry* const dirEntry, const wxString& dirPath, const wxString& filter ) {
wxDir dir( dirPath );
if ( dir.IsOpened() ) {
@ -274,6 +294,12 @@ bool FolderMemoryCard::AddFolder( MemoryCardFileEntry* const dirEntry, const wxS
wxString fileName;
bool hasNext;
wxString localFilter;
bool hasFilter = !filter.IsEmpty();
if ( hasFilter ) {
localFilter = L"DATA-SYSTEM/" + filter;
}
int entryNumber = 2; // include . and ..
hasNext = dir.GetFirst( &fileName );
while ( hasNext ) {
@ -293,7 +319,7 @@ bool FolderMemoryCard::AddFolder( MemoryCardFileEntry* const dirEntry, const wxS
// if possible filter added directories by game serial
// this has the effective result of only files relevant to the current game being loaded into the memory card
// which means every game essentially sees the memory card as if no other files exist
if ( !filter.IsEmpty() && !fileName.Contains( filter ) ) {
if ( hasFilter && !FilterMatches( fileName, localFilter ) ) {
hasNext = dir.GetNext( &fileName );
continue;
}
@ -1043,6 +1069,7 @@ void FolderMemoryCardAggregator::NextFrame( uint slot ) {
void FolderMemoryCardAggregator::ReIndex( uint slot, const wxString& filter ) {
m_cards[slot].Close();
Console.WriteLn( Color_Green, L"(FolderMcd) Re-Indexing slot %u with filter \"%s\"", slot, WX_STR( filter ) );
m_cards[slot].Open( filter );
}