clean up memory card logic:
- Don't do the OS mount for cards during the attract screens. Only do OS mounts in the time between BeginGame and PlayersFinalized. - Remove logic for fast load of a Profile from the MemoryCard. Instead, load the whole profile all at once on PlayersFinalized.
This commit is contained in:
@@ -47,10 +47,13 @@ public:
|
||||
virtual void Unmount( UsbStorageDevice* pDevice, CString sMountPoint ) = 0;
|
||||
virtual void Flush( UsbStorageDevice* pDevice ) = 0;
|
||||
virtual void ResetUsbStorage() = 0;
|
||||
virtual void PauseMountingThread() = 0;
|
||||
virtual void UnPauseMountingThread() = 0;
|
||||
virtual void DoOsMount() = 0;
|
||||
virtual void DontDoOsMount() = 0;
|
||||
enum MountThreadState
|
||||
{
|
||||
detect_and_mount,
|
||||
detect_and_dont_mount,
|
||||
paused
|
||||
};
|
||||
virtual void SetMountThreadState( MountThreadState mts ) = 0;
|
||||
};
|
||||
|
||||
MemoryCardDriver *MakeMemoryCardDriver();
|
||||
|
||||
@@ -25,8 +25,9 @@ MemoryCardDriverThreaded::MemoryCardDriverThreaded() :
|
||||
m_mutexStorageDevices("StorageDevices")
|
||||
{
|
||||
m_bShutdownNextUpdate = false;
|
||||
m_bForceRedetectNextUpdate = true;
|
||||
m_bStorageDevicesChanged = false;
|
||||
m_bDoOsMount = true;
|
||||
m_MountThreadState = detect_and_mount;
|
||||
}
|
||||
|
||||
void MemoryCardDriverThreaded::StartThread()
|
||||
@@ -52,24 +53,26 @@ MemoryCardDriverThreaded::~MemoryCardDriverThreaded()
|
||||
ASSERT( !m_threadMemoryCardMount.IsCreated() );
|
||||
}
|
||||
|
||||
void MemoryCardDriverThreaded::PauseMountingThread()
|
||||
void MemoryCardDriverThreaded::SetMountThreadState( MountThreadState mts )
|
||||
{
|
||||
m_mutexPause.Lock();
|
||||
}
|
||||
CHECKPOINT;
|
||||
|
||||
void MemoryCardDriverThreaded::UnPauseMountingThread()
|
||||
{
|
||||
m_mutexPause.Unlock();
|
||||
}
|
||||
MountThreadState old = m_MountThreadState;
|
||||
|
||||
void MemoryCardDriverThreaded::DoOsMount()
|
||||
{
|
||||
m_bDoOsMount = true;
|
||||
}
|
||||
if( old != paused && mts == paused )
|
||||
m_mutexPause.Lock();
|
||||
|
||||
void MemoryCardDriverThreaded::DontDoOsMount()
|
||||
{
|
||||
m_bDoOsMount = false;
|
||||
if( old == paused && mts != paused )
|
||||
m_mutexPause.Unlock();
|
||||
|
||||
if( old == detect_and_dont_mount && mts == detect_and_mount )
|
||||
{
|
||||
m_bForceRedetectNextUpdate = true;
|
||||
LockMut( m_mutexStorageDevices );
|
||||
m_vStorageDevices.clear();
|
||||
}
|
||||
|
||||
m_MountThreadState = mts;
|
||||
}
|
||||
|
||||
int MemoryCardDriverThreaded::MountThread_Start( void *p )
|
||||
@@ -80,6 +83,8 @@ int MemoryCardDriverThreaded::MountThread_Start( void *p )
|
||||
|
||||
void MemoryCardDriverThreaded::MountThreadMain()
|
||||
{
|
||||
CHECKPOINT;
|
||||
|
||||
while( !m_bShutdownNextUpdate )
|
||||
{
|
||||
LockMut( m_mutexPause ); // wait until we're unpaused
|
||||
@@ -89,6 +94,8 @@ void MemoryCardDriverThreaded::MountThreadMain()
|
||||
|
||||
bool MemoryCardDriverThreaded::StorageDevicesChanged()
|
||||
{
|
||||
CHECKPOINT;
|
||||
|
||||
LockMut( m_mutexStorageDevices );
|
||||
if( m_bStorageDevicesChanged )
|
||||
{
|
||||
@@ -103,6 +110,8 @@ bool MemoryCardDriverThreaded::StorageDevicesChanged()
|
||||
|
||||
void MemoryCardDriverThreaded::GetStorageDevices( vector<UsbStorageDevice>& vDevicesOut )
|
||||
{
|
||||
CHECKPOINT;
|
||||
|
||||
LockMut( m_mutexStorageDevices );
|
||||
vDevicesOut.clear();
|
||||
for( unsigned i=0; i<m_vStorageDevices.size(); i++ )
|
||||
|
||||
@@ -10,6 +10,7 @@ struct UsbStorageDeviceEx : public UsbStorageDevice
|
||||
|
||||
void MakeBlank()
|
||||
{
|
||||
UsbStorageDevice::MakeBlank();
|
||||
bWriteTestSucceeded = false;
|
||||
}
|
||||
|
||||
@@ -25,10 +26,7 @@ public:
|
||||
virtual bool StorageDevicesChanged();
|
||||
virtual void GetStorageDevices( vector<UsbStorageDevice>& vStorageDevicesOut );
|
||||
virtual bool MountAndTestWrite( UsbStorageDevice* pDevice, CString sMountPoint );
|
||||
virtual void PauseMountingThread();
|
||||
virtual void UnPauseMountingThread();
|
||||
virtual void DoOsMount();
|
||||
virtual void DontDoOsMount();
|
||||
virtual void SetMountThreadState( MountThreadState mts );
|
||||
|
||||
private:
|
||||
static int MountThread_Start( void *p );
|
||||
@@ -42,20 +40,19 @@ private:
|
||||
// will temporarily halt.
|
||||
RageMutex m_mutexPause;
|
||||
|
||||
// If true, detect and report changes in connected devices, but don't don't
|
||||
// do the OS mount or unmount.
|
||||
bool m_bDoOsMount;
|
||||
MountThreadState m_MountThreadState;
|
||||
|
||||
protected:
|
||||
void StartThread(); // call this in the derived constructor to start the mounting thread
|
||||
void StopThread(); // call this in the derived desstructor to stop the mounting thread
|
||||
virtual void MountThreadDoOneUpdate() = 0; // this will get called as fast as possible
|
||||
virtual void Mount( UsbStorageDevice* pDevice, CString sMountPoint ) = 0;
|
||||
bool ShouldDoOsMount() { return m_bDoOsMount; }
|
||||
bool ShouldDoOsMount() { return m_MountThreadState==detect_and_mount; }
|
||||
|
||||
vector<UsbStorageDeviceEx> m_vStorageDevices;
|
||||
bool m_bStorageDevicesChanged;
|
||||
RageMutex m_mutexStorageDevices; // protects the above two
|
||||
bool m_bForceRedetectNextUpdate; // on the next update, redetect from scratch report new devices found
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -131,8 +131,6 @@ MemoryCardDriverThreaded_Linux::MemoryCardDriverThreaded_Linux()
|
||||
if( m_fd == -1 )
|
||||
LOG->Warn( "Failed to open \"%s\": %s", USB_DEVICE_LIST_FILE, strerror(errno) );
|
||||
|
||||
m_bForceRedetect = false;
|
||||
|
||||
this->StartThread();
|
||||
}
|
||||
|
||||
@@ -164,8 +162,7 @@ void MemoryCardDriverThreaded_Linux::ResetUsbStorage()
|
||||
ExecuteCommand( "rmmod usb-storage" );
|
||||
ExecuteCommand( "modprobe usb-storage" );
|
||||
|
||||
m_vDevicesLastSeen.clear();
|
||||
m_bForceRedetect = true;
|
||||
m_bForceRedetectNextUpdate = true;
|
||||
|
||||
MountThreadDoOneUpdate();
|
||||
}
|
||||
@@ -178,9 +175,10 @@ void MemoryCardDriverThreaded_Linux::MountThreadDoOneUpdate()
|
||||
return;
|
||||
}
|
||||
|
||||
if( m_bForceRedetect )
|
||||
if( m_bForceRedetectNextUpdate )
|
||||
{
|
||||
m_bForceRedetect = false;
|
||||
m_vDevicesLastSeen.clear();
|
||||
m_bForceRedetectNextUpdate = false;
|
||||
// fall through
|
||||
}
|
||||
else
|
||||
|
||||
@@ -18,7 +18,6 @@ protected:
|
||||
|
||||
int m_fd;
|
||||
vector<UsbStorageDeviceEx> m_vDevicesLastSeen;
|
||||
bool m_bForceRedetect;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -67,7 +67,17 @@ void MemoryCardDriverThreaded_Windows::ResetUsbStorage()
|
||||
void MemoryCardDriverThreaded_Windows::MountThreadDoOneUpdate()
|
||||
{
|
||||
DWORD dwNewLogicalDrives = ::GetLogicalDrives();
|
||||
if( dwNewLogicalDrives != m_dwLastLogicalDrives )
|
||||
|
||||
if( m_bForceRedetectNextUpdate )
|
||||
{
|
||||
m_bForceRedetectNextUpdate = false;
|
||||
}
|
||||
else if( dwNewLogicalDrives == m_dwLastLogicalDrives )
|
||||
{
|
||||
// no change from last update
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
vector<UsbStorageDeviceEx> vNewStorageDevices;
|
||||
|
||||
@@ -89,29 +99,36 @@ void MemoryCardDriverThreaded_Windows::MountThreadDoOneUpdate()
|
||||
|
||||
UsbStorageDeviceEx usbd;
|
||||
usbd.sOsMountDir = sDrive;
|
||||
usbd.bWriteTestSucceeded = TestWrite( sDrive );
|
||||
|
||||
// read name
|
||||
this->Mount( &usbd, TEMP_MOUNT_POINT );
|
||||
FILEMAN->FlushDirCache( TEMP_MOUNT_POINT );
|
||||
Profile profile;
|
||||
CString sProfileDir = TEMP_MOUNT_POINT + PREFSMAN->m_sMemoryCardProfileSubdir + '/';
|
||||
profile.LoadEditableDataFromDir( sProfileDir );
|
||||
usbd.sName = profile.GetDisplayName();
|
||||
if( ShouldDoOsMount() )
|
||||
{
|
||||
usbd.bWriteTestSucceeded = TestWrite( sDrive );
|
||||
|
||||
// read name
|
||||
this->Mount( &usbd, TEMP_MOUNT_POINT );
|
||||
FILEMAN->FlushDirCache( TEMP_MOUNT_POINT );
|
||||
Profile profile;
|
||||
CString sProfileDir = TEMP_MOUNT_POINT + PREFSMAN->m_sMemoryCardProfileSubdir + '/';
|
||||
profile.LoadEditableDataFromDir( sProfileDir );
|
||||
usbd.sName = profile.GetDisplayName();
|
||||
}
|
||||
|
||||
vNewStorageDevices.push_back( usbd );
|
||||
}
|
||||
}
|
||||
|
||||
CHECKPOINT;
|
||||
|
||||
{
|
||||
LockMut( m_mutexStorageDevices );
|
||||
m_bStorageDevicesChanged = true;
|
||||
m_vStorageDevices = vNewStorageDevices;
|
||||
}
|
||||
}
|
||||
m_dwLastLogicalDrives = dwNewLogicalDrives;
|
||||
|
||||
usleep( 100000 );
|
||||
CHECKPOINT;
|
||||
|
||||
m_dwLastLogicalDrives = dwNewLogicalDrives;
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCardDriverThreaded_Windows::Mount( UsbStorageDevice* pDevice, CString sMountPoint )
|
||||
|
||||
@@ -17,6 +17,7 @@ public:
|
||||
virtual void UnPauseMountingThread() {}
|
||||
virtual void DoOsMount() {}
|
||||
virtual void DontDoOsMount() {}
|
||||
virtual void SetMountThreadState( MountThreadState mts ) {}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user