Add option to enable/disable the filtering of the FolderMemoryCard.

This commit is contained in:
Admiral H. Curtiss 2015-05-25 14:39:35 +02:00
parent 72dcb9b94c
commit f40b679653
7 changed files with 53 additions and 25 deletions

View File

@ -441,6 +441,7 @@ struct Pcsx2Config
BackupSavestate :1,
// enables simulated ejection of memory cards when loading savestates
McdEnableEjection :1,
McdFolderAutoManage :1,
MultitapPort0_Enabled:1,
MultitapPort1_Enabled:1,

View File

@ -398,6 +398,7 @@ Pcsx2Config::Pcsx2Config()
bitset = 0;
// Set defaults for fresh installs / reset settings
McdEnableEjection = true;
McdFolderAutoManage = true;
EnablePatches = true;
BackupSavestate = true;
}
@ -417,6 +418,7 @@ void Pcsx2Config::LoadSave( IniInterface& ini )
IniBitBool( BackupSavestate );
IniBitBool( McdEnableEjection );
IniBitBool( McdFolderAutoManage );
IniBitBool( MultitapPort0_Enabled );
IniBitBool( MultitapPort1_Enabled );

View File

@ -40,6 +40,12 @@ Panels::McdConfigPanel_Toggles::McdConfigPanel_Toggles(wxWindow *parent)
)
);
m_folderAutoIndex = new pxCheckBox( this,
_( "Automatically manage saves based on running game" ),
pxE( L"(Folder type only) Re-index memory card content every time the running software changes. This prevents the memory card from running out of space for saves."
)
);
//m_check_SavestateBackup = new pxCheckBox( this, pxsFmt(_("Backup existing Savestate when creating a new one")) );
/*
for( uint i=0; i<2; ++i )
@ -64,6 +70,7 @@ Panels::McdConfigPanel_Toggles::McdConfigPanel_Toggles(wxWindow *parent)
*this += new wxStaticLine( this ) | StdExpand();
*this += m_check_Ejection;
*this += m_folderAutoIndex;
}
void Panels::McdConfigPanel_Toggles::Apply()
@ -73,6 +80,7 @@ void Panels::McdConfigPanel_Toggles::Apply()
//g_Conf->EmuOptions.BackupSavestate = m_check_SavestateBackup->GetValue();
g_Conf->EmuOptions.McdEnableEjection = m_check_Ejection->GetValue();
g_Conf->EmuOptions.McdFolderAutoManage = m_folderAutoIndex->GetValue();
}
void Panels::McdConfigPanel_Toggles::AppStatusEvent_OnSettingsApplied()
@ -82,6 +90,7 @@ void Panels::McdConfigPanel_Toggles::AppStatusEvent_OnSettingsApplied()
//m_check_SavestateBackup ->SetValue( g_Conf->EmuOptions.BackupSavestate );
m_check_Ejection ->SetValue( g_Conf->EmuOptions.McdEnableEjection );
m_folderAutoIndex ->SetValue( g_Conf->EmuOptions.McdFolderAutoManage );
}

View File

@ -436,6 +436,7 @@ uint FileMcd_ConvertToSlot( uint port, uint slot )
static void PS2E_CALLBACK FileMcd_EmuOpen( PS2E_THISPTR thisptr, const PS2E_SessionInfo *session )
{
thisptr->impl.Open();
thisptr->implFolder.SetFiltering( g_Conf->EmuOptions.McdFolderAutoManage );
thisptr->implFolder.Open();
}
@ -559,7 +560,7 @@ static void PS2E_CALLBACK FileMcd_ReIndex( PS2E_THISPTR thisptr, uint port, uint
// thisptr->impl.ReIndex( combinedSlot, filter );
// break;
case MemoryCardType::MemoryCard_Folder:
thisptr->implFolder.ReIndex( combinedSlot, filter );
thisptr->implFolder.ReIndex( combinedSlot, g_Conf->EmuOptions.McdFolderAutoManage, filter );
break;
default:
return;

View File

@ -46,11 +46,7 @@ bool FolderMemoryCard::IsFormatted() {
return m_superBlock.raw[0x16] == 0x6F;
}
void FolderMemoryCard::Open() {
Open( L"" );
}
void FolderMemoryCard::Open( const wxString& filter ) {
void FolderMemoryCard::Open( const bool enableFiltering, const wxString& filter ) {
InitializeInternalData();
wxFileName configuredFileName( g_Conf->FullpathToMcd( m_slot ) );
@ -84,7 +80,7 @@ void FolderMemoryCard::Open( const wxString& filter ) {
if ( disabled ) return;
m_isEnabled = true;
LoadMemoryCardData( filter );
LoadMemoryCardData( enableFiltering, filter );
SetTimeLastWrittenToNow();
m_framesUntilFlush = 0;
@ -102,7 +98,7 @@ void FolderMemoryCard::Close() {
}
}
void FolderMemoryCard::LoadMemoryCardData( const wxString& filter ) {
void FolderMemoryCard::LoadMemoryCardData( const bool enableFiltering, const wxString& filter ) {
bool formatted = false;
// read superblock if it exists
@ -116,10 +112,16 @@ void FolderMemoryCard::LoadMemoryCardData( const wxString& filter ) {
// if superblock was valid, load folders and files
if ( formatted ) {
if ( enableFiltering ) {
Console.WriteLn( Color_Green, L"(FolderMcd) Indexing slot %u with filter \"%s\".", m_slot, WX_STR( filter ) );
} else {
Console.WriteLn( Color_Green, L"(FolderMcd) Indexing slot %u without filter.", m_slot );
}
CreateFat();
CreateRootDir();
MemoryCardFileEntry* const rootDirEntry = &m_fileEntryDict[m_superBlock.data.rootdir_cluster].entries[0];
AddFolder( rootDirEntry, folderName.GetPath(), filter );
AddFolder( rootDirEntry, folderName.GetPath(), enableFiltering, filter );
}
}
@ -284,7 +286,7 @@ bool FilterMatches( const wxString& fileName, const wxString& filter ) {
return false;
}
bool FolderMemoryCard::AddFolder( MemoryCardFileEntry* const dirEntry, const wxString& dirPath, const wxString& filter ) {
bool FolderMemoryCard::AddFolder( MemoryCardFileEntry* const dirEntry, const wxString& dirPath, const bool enableFiltering, const wxString& filter ) {
wxDir dir( dirPath );
if ( dir.IsOpened() ) {
Console.WriteLn( L"(FolderMcd) Adding folder: %s", WX_STR( dirPath ) );
@ -295,12 +297,14 @@ bool FolderMemoryCard::AddFolder( MemoryCardFileEntry* const dirEntry, const wxS
bool hasNext;
wxString localFilter;
if ( enableFiltering ) {
bool hasFilter = !filter.IsEmpty();
if ( hasFilter ) {
localFilter = L"DATA-SYSTEM/" + filter;
} else {
localFilter = L"DATA-SYSTEM";
}
}
int entryNumber = 2; // include . and ..
hasNext = dir.GetFirst( &fileName );
@ -321,7 +325,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 ( !FilterMatches( fileName, localFilter ) ) {
if ( enableFiltering && !FilterMatches( fileName, localFilter ) ) {
hasNext = dir.GetNext( &fileName );
continue;
}
@ -1027,7 +1031,7 @@ FolderMemoryCardAggregator::FolderMemoryCardAggregator() {
void FolderMemoryCardAggregator::Open() {
for ( int i = 0; i < totalCardSlots; ++i ) {
m_cards[i].Open( m_lastKnownFilter );
m_cards[i].Open( m_enableFiltering, m_lastKnownFilter );
}
}
@ -1037,6 +1041,10 @@ void FolderMemoryCardAggregator::Close() {
}
}
void FolderMemoryCardAggregator::SetFiltering( const bool enableFiltering ) {
m_enableFiltering = enableFiltering;
}
s32 FolderMemoryCardAggregator::IsPresent( uint slot ) {
return m_cards[slot].IsPresent();
}
@ -1069,10 +1077,11 @@ void FolderMemoryCardAggregator::NextFrame( uint slot ) {
m_cards[slot].NextFrame();
}
void FolderMemoryCardAggregator::ReIndex( uint slot, const wxString& filter ) {
void FolderMemoryCardAggregator::ReIndex( uint slot, const bool enableFiltering, 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 );
m_cards[slot].Open( enableFiltering, filter );
SetFiltering( enableFiltering );
m_lastKnownFilter = filter;
}

View File

@ -168,8 +168,7 @@ public:
void Lock();
void Unlock();
void Open();
void Open( const wxString& filter );
void Open( const bool enableFiltering, const wxString& filter );
void Close();
s32 IsPresent();
@ -220,7 +219,9 @@ protected:
// loads files and folders from the host file system if a superblock exists in the root directory
void LoadMemoryCardData( const wxString& filter );
// if enableFiltering is set to true, only folders whose name contain the filter string are loaded
// filter string can include multiple filters by separating them with "/"
void LoadMemoryCardData( const bool enableFiltering, const wxString& filter );
// creates the FAT and indirect FAT
void CreateFat();
@ -253,7 +254,8 @@ protected:
// adds a folder in the host file system to the memory card, including all files and subdirectories
// - dirEntry: the entry of the directory in the parent directory, or the root "." entry
// - dirPath: the full path to the directory in the host file system
bool AddFolder( MemoryCardFileEntry* const dirEntry, const wxString& dirPath, const wxString& filter = L"" );
// - enableFiltering and filter: filter loaded contents, see LoadMemoryCardData()
bool AddFolder( MemoryCardFileEntry* const dirEntry, const wxString& dirPath, const bool enableFiltering = false, const wxString& filter = L"" );
// adds a file in the host file sytem to the memory card
// - dirEntry: the entry of the directory in the parent directory, or the root "." entry
@ -298,6 +300,7 @@ class FolderMemoryCardAggregator {
protected:
static const int totalCardSlots = 8;
FolderMemoryCard m_cards[totalCardSlots];
bool m_enableFiltering = true;
wxString m_lastKnownFilter = L"";
public:
@ -307,6 +310,8 @@ public:
void Open();
void Close();
void SetFiltering( const bool enableFiltering );
s32 IsPresent( uint slot );
void GetSizeInfo( uint slot, PS2E_McdSizeInfo& outways );
bool IsPSX( uint slot );
@ -315,5 +320,5 @@ public:
s32 EraseBlock( uint slot, u32 adr );
u64 GetCRC( uint slot );
void NextFrame( uint slot );
void ReIndex( uint slot, const wxString& filter );
void ReIndex( uint slot, const bool enableFiltering, const wxString& filter );
};

View File

@ -285,6 +285,7 @@ namespace Panels
protected:
//pxCheckBox* m_check_Multitap[2];
pxCheckBox* m_check_Ejection;
pxCheckBox* m_folderAutoIndex;
//moved to the system menu, just below "Save State"
//pxCheckBox* m_check_SavestateBackup;