From 4448fb5a5af1ebddedd08a931b7f7ea46860132e Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 10 Dec 2005 02:19:00 +0000 Subject: [PATCH] update --- .../MemoryCardDriverThreaded_Linux.cpp | 123 ++---------------- .../MemoryCardDriverThreaded_Linux.h | 4 +- 2 files changed, 13 insertions(+), 114 deletions(-) diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp index b44c89e486..9e1cde5f89 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp @@ -19,10 +19,6 @@ #include #include -const CString TEMP_MOUNT_POINT = "/@mctemp/"; - -void GetUSBStorageDevices( vector& vDevicesOut ); - template bool VectorsAreEqual( const T &a, const T &b ) { @@ -38,9 +34,15 @@ bool VectorsAreEqual( const T &a, const T &b ) return true; } -static bool TestWrite( CCStringRef sDir ) +bool MemoryCardDriverThreaded_Linux::TestWrite( UsbStorageDevice* pDevice ) { - return access(sDir, W_OK) == 0; + if( access(pDevice->sOsMountDir, W_OK) == -1 ) + { + pDevice->SetError( "TestFailed" ); + return false; + } + + return true; } static bool ExecuteCommand( CCStringRef sCommand ) @@ -110,7 +112,7 @@ static void GetFileList( const CString &sPath, vector &out ) closedir( dp ); } -static bool BlockDevicesChanged() +bool MemoryCardDriverThreaded_Linux::USBStorageDevicesChanged() { static CString sLastDevices = ""; CString sThisDevices; @@ -138,112 +140,7 @@ static bool BlockDevicesChanged() return bChanged; } -bool MemoryCardDriverThreaded_Linux::NeedUpdate( bool bMount ) const -{ - if( bMount ) - { - /* Check if any devices need a write test. */ - for( unsigned i=0; i& vStorageDevicesOut ) -{ - if( !NeedUpdate(bMount) ) - return false; - - vector vOld = m_vDevicesLastSeen; // copy - GetUSBStorageDevices( vStorageDevicesOut ); - - // log connects - FOREACH( UsbStorageDevice, vStorageDevicesOut, newd ) - { - vector::iterator iter = find( vOld.begin(), vOld.end(), *newd ); - if( iter == vOld.end() ) // didn't find - LOG->Trace( "New device connected: %s", newd->sDevice.c_str() ); - } - - /* When we first see a device, regardless of bMount, just return it as CHECKING, - * so the main thread knows about the device. On the next call where bMount is - * true, check it. */ - for( unsigned i=0; i::iterator iter = find( vOld.begin(), vOld.end(), d ); - if( iter == vOld.end() ) // didn't find - { - LOG->Trace( "New device entering CHECKING: %s", d.sDevice.c_str() ); - d.m_State = UsbStorageDevice::STATE_CHECKING; - continue; - } - - /* Preserve the state of the device, and any data loaded from previous checks. */ - d.m_State = iter->m_State; - d.bIsNameAvailable = iter->bIsNameAvailable; - d.sName = iter->sName; - - /* The device was here last time. If CHECKING, check the device now, if - * we're allowed to. */ - if( d.m_State == UsbStorageDevice::STATE_CHECKING ) - { - if( !bMount ) - { - /* We can't check it now. Keep STATE_CHECKING, and check it when we can. */ - d.m_State = UsbStorageDevice::STATE_CHECKING; - continue; - } - - if( !this->Mount(&d) ) - { - d.SetError( "MountFailed" ); - continue; - } - - if( !TestWrite(d.sOsMountDir) ) - { - d.SetError( "TestFailed" ); - } - else - { - /* We've successfully mounted and tested the device. Read the - * profile name (by mounting a temporary, private mountpoint), - * and then unmount it until Mount() is called. */ - d.m_State = UsbStorageDevice::STATE_READY; - - FILEMAN->Mount( "dir", d.sOsMountDir, TEMP_MOUNT_POINT ); - d.bIsNameAvailable = PROFILEMAN->FastLoadProfileNameFromMemoryCard( TEMP_MOUNT_POINT, d.sName ); - FILEMAN->Unmount( "dir", d.sOsMountDir, TEMP_MOUNT_POINT ); - } - - this->Unmount( &d ); - - LOG->Trace( "WriteTest: %s, Name: %s", d.m_State == UsbStorageDevice::STATE_ERROR? "failed":"succeeded", d.sName.c_str() ); - } - } - - m_vDevicesLastSeen = vStorageDevicesOut; - - return true; -} - -void GetUSBStorageDevices( vector& vDevicesOut ) +void MemoryCardDriverThreaded_Linux::GetUSBStorageDevices( vector& vDevicesOut ) { LOG->Trace( "GetUSBStorageDevices" ); diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.h b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.h index 5f9757f7d4..95a0bd396c 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.h +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.h @@ -16,7 +16,9 @@ public: virtual void Reset(); protected: - bool NeedUpdate( bool bMount ) const; + void GetUSBStorageDevices( vector& vDevicesOut ); + bool USBStorageDevicesChanged(); + bool TestWrite( UsbStorageDevice* pDevice ); vector m_vDevicesLastSeen; };