windows memory card fixes/cleanup

This commit is contained in:
Chris Danford
2003-12-18 07:46:21 +00:00
parent eb0620add8
commit 1ba5e253ca
4 changed files with 115 additions and 25 deletions
+95 -16
View File
@@ -16,10 +16,11 @@
#include "arch/arch.h"
#include "ScreenManager.h"
#include "ThemeManager.h"
#include "PrefsManager.h"
#include "RageLog.h"
MemoryCardManager* MEMCARDMAN = NULL; // global and accessable from anywhere in our program
vector<UsbStorageDevice> g_StorageDevices;
MemoryCardManager::MemoryCardManager()
{
@@ -30,7 +31,8 @@ MemoryCardManager::MemoryCardManager()
m_bTooLate[NUM_PLAYERS] = false;
m_bWriteError[NUM_PLAYERS] = false;
}
m_pDriver->GetStorageDevices( g_StorageDevices );
m_pDriver->GetStorageDevices( m_vStorageDevices );
ReassignCards();
m_soundConnect.Load( THEME->GetPathToS("MemoryCardManager connect") );
m_soundDisconnect.Load( THEME->GetPathToS("MemoryCardManager disconnect") );
@@ -45,9 +47,11 @@ void MemoryCardManager::Update( float fDelta )
{
if( m_pDriver->StorageDevicesChanged() )
{
vector<UsbStorageDevice> vOld = g_StorageDevices; // make a copy
m_pDriver->GetStorageDevices( g_StorageDevices );
vector<UsbStorageDevice> &vNew = g_StorageDevices;
vector<UsbStorageDevice> vOld = m_vStorageDevices; // copy
m_pDriver->GetStorageDevices( m_vStorageDevices );
vector<UsbStorageDevice> &vNew = m_vStorageDevices;
vector<UsbStorageDevice> vConnects; // fill these in below
vector<UsbStorageDevice> vDisconnects; // fill these in below
unsigned i;
@@ -55,10 +59,10 @@ void MemoryCardManager::Update( float fDelta )
for( i=0; i<vOld.size(); i++ )
{
const UsbStorageDevice old = vOld[i];
if( find(vNew.begin(),vNew.end(),old) == vNew.end() )
if( find(vNew.begin(),vNew.end(),old) == vNew.end() ) // didn't find
{
SCREENMAN->SystemMessage( ssprintf("Disconnected bus %d port %d device %d path %s", old.iBus, old.iPortOnHub, old.iDeviceOnBus, old.sOsMountDir.c_str()) );
m_soundDisconnect.Play();
LOG->Trace( ssprintf("Disconnected bus %d port %d device %d path %s", old.iBus, old.iPortOnHub, old.iDeviceOnBus, old.sOsMountDir.c_str()) );
vDisconnects.push_back( old );
}
}
@@ -66,18 +70,47 @@ void MemoryCardManager::Update( float fDelta )
for( i=0; i<vNew.size(); i++ )
{
const UsbStorageDevice newd = vNew[i];
if( find(vOld.begin(),vOld.end(),newd) == vOld.end() )
if( find(vOld.begin(),vOld.end(),newd) == vOld.end() ) // didn't find
{
SCREENMAN->SystemMessage( ssprintf("Connected bus %d port %d device %d path %s", newd.iBus, newd.iPortOnHub, newd.iDeviceOnBus, newd.sOsMountDir.c_str()) );
m_soundConnect.Play();
LOG->Trace( ssprintf("Connected bus %d port %d device %d path %s", newd.iBus, newd.iPortOnHub, newd.iDeviceOnBus, newd.sOsMountDir.c_str()) );
vConnects.push_back( newd );
}
}
if( m_bCardsLocked ) // Cards are locked and play has begun.
{
// Don't re-assign devices
// play disconnect sound if locked card was removed
for( int p=0; p<NUM_PLAYERS; p++ )
{
if( !m_Device[p].IsBlank() ) // card is in use
{
if( find(vOld.begin(),vOld.end(),m_Device[p]) != vOld.end() ) // match
{
m_Device[p].MakeBlank();
m_soundDisconnect.Play();
}
}
}
}
else // cards aren't locked.
{
// play sound for connects or disconnects
if( !vConnects.empty() )
m_soundConnect.Play();
if( !vDisconnects.empty() )
m_soundDisconnect.Play();
ReassignCards();
}
}
}
MemoryCardManager::CardState MemoryCardManager::GetCardState( PlayerNumber pn )
{
if( m_pDevice[pn] == NULL )
if( m_Device[pn].IsBlank() )
return no_card;
else if( m_bTooLate[pn] )
return too_late;
@@ -89,10 +122,10 @@ MemoryCardManager::CardState MemoryCardManager::GetCardState( PlayerNumber pn )
CString MemoryCardManager::GetOsMountDir( PlayerNumber pn )
{
if( m_pDevice[pn] == NULL )
if( m_Device[pn].IsBlank() )
return "";
else
return m_pDevice[pn]->sOsMountDir;
return m_Device[pn].sOsMountDir;
}
void MemoryCardManager::LockCards( bool bLock )
@@ -107,8 +140,8 @@ void MemoryCardManager::LockCards( bool bLock )
// try mounting
for( int p=0; p<NUM_PLAYERS; p++ )
{
if( m_pDevice[p] )
m_bWriteError[p] = m_pDriver->MountAndTestWrite( m_pDevice[p] );
if( !m_Device[p].IsBlank() )
m_bWriteError[p] = m_pDriver->MountAndTestWrite( &m_Device[p] );
}
}
else
@@ -119,6 +152,52 @@ void MemoryCardManager::LockCards( bool bLock )
m_bTooLate[p] = false;
m_bWriteError[p] = false;
}
ReassignCards();
}
}
void MemoryCardManager::ReassignCards()
{
// Do re-assigning: choose a storage device for each player
vector<UsbStorageDevice> vDevices = m_vStorageDevices; // copy
for( int p=0; p<NUM_PLAYERS; p++ )
{
m_Device[p].MakeBlank();
int i;
// search for card dir match
if( !PREFSMAN->m_sMemoryCardDir[p].empty() )
{
for( i=0; i<vDevices.size(); i++ )
{
UsbStorageDevice &usd = vDevices[i];
if( usd.sOsMountDir.CompareNoCase(PREFSMAN->m_sMemoryCardDir[p]) == 0 ) // match
goto match;
}
}
// search for USB bus match
for( i=0; i<vDevices.size(); i++ )
{
UsbStorageDevice &usd = vDevices[i];
if( PREFSMAN->m_iMemoryCardUsbBus[p] != -1 &&
PREFSMAN->m_iMemoryCardUsbBus[p] != usd.iBus )
continue; // not a match
if( PREFSMAN->m_iMemoryCardUsbPort[p] != -1 &&
PREFSMAN->m_iMemoryCardUsbPort[p] != usd.iPortOnHub )
continue; // not a match
goto match;
}
LOG->Trace( "Player %d memory card: none", p+1 );
continue; // no matches
match:
m_Device[p] = vDevices[i]; // save a copy
LOG->Trace( "Player %d memory card: '%s'", p+1, m_Device[p].sOsMountDir.c_str() );
vDevices.erase( vDevices.begin()+i ); // remove the device so we don't match it for another player
}
}
+6 -4
View File
@@ -12,9 +12,7 @@
*/
#include "PlayerNumber.h"
#include "RageSound.h"
struct UsbStorageDevice;
class MemoryCardDriver;
#include "arch/MemoryCard/MemoryCardDriver.h"
class MemoryCardManager
{
@@ -33,12 +31,16 @@ public:
void LockCards( bool bLock ); // prevent removing or changing of memory cards
protected:
void ReassignCards(); // do our best to assign a Device to each player
MemoryCardDriver *m_pDriver;
vector<UsbStorageDevice> m_vStorageDevices; // all currently connected
bool m_bCardsLocked;
bool m_bTooLate[NUM_PLAYERS]; // card was inserted after lock
bool m_bWriteError[NUM_PLAYERS]; // couldn't write to the card
UsbStorageDevice* m_pDevice[NUM_PLAYERS]; // device in the memory card slot, NULL if none
UsbStorageDevice m_Device[NUM_PLAYERS]; // device in the memory card slot, NULL if none
RageSound m_soundConnect;
RageSound m_soundDisconnect;
+1 -1
View File
@@ -121,7 +121,7 @@ public:
int m_iEndlessBreakLength;
CString m_sLanguage;
CString m_sDefaultLocalProfileID[NUM_PLAYERS];
CString m_sMemoryCardDir[NUM_PLAYERS]; // always use this dir for the memory card
CString m_sMemoryCardDir[NUM_PLAYERS]; // if set, always use this dir for the memory card
int m_iMemoryCardUsbBus[NUM_PLAYERS]; // take the first storage device on this usb bus
int m_iMemoryCardUsbPort[NUM_PLAYERS]; // take the first storage device on this usb bus
int m_iCenterImageTranslateX;
@@ -4,7 +4,9 @@
struct UsbStorageDevice
{
UsbStorageDevice()
UsbStorageDevice() { MakeBlank(); }
void MakeBlank()
{
iBus = -1;
iDeviceOnBus = -1;
@@ -18,11 +20,18 @@ struct UsbStorageDevice
int iUsbStorageIndex;
CString sOsMountDir; // WITHOUT trailing slash
bool IsBlank() { return sOsMountDir.empty(); }
bool operator==(const UsbStorageDevice& other)
{
return
iBus==other.iBus &&
iDeviceOnBus==other.iDeviceOnBus; // every time a device is plugged in, it gets a unique device number
// ugly...
#if _WINDOWS
// we don't have hub/port number info on Windows
return sOsMountDir==other.sOsMountDir; // every time a device is plugged in, it gets a unique device number
#else // LINUX or other
return iBus==other.iBus &&
iDeviceOnBus==other.iDeviceOnBus; // every time a device is plugged in, it gets a unique device number
#endif
}
};