diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriver.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriver.cpp index 668085a7b7..76a69ba612 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriver.cpp +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriver.cpp @@ -2,9 +2,15 @@ #include "MemoryCardDriver.h" #include "PrefsManager.h" #include "MemoryCardDriver_Null.h" +#include "RageFileManager.h" +#include "RageLog.h" +#include "Foreach.h" +#include "ProfileManager.h" #include "Selector_MemoryCardDriver.h" +const CString TEMP_MOUNT_POINT = "/@mctemptimeout/"; + bool UsbStorageDevice::operator==(const UsbStorageDevice& other) const { // LOG->Trace( "Comparing %d %d %d %s %s to %d %d %d %s %s", @@ -24,6 +30,101 @@ void UsbStorageDevice::SetOsMountDir( const CString &s ) sOsMountDir = s; } +bool MemoryCardDriver::NeedUpdate( bool bMount ) +{ + 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) ) + { + /* 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; +} + /* * (c) 2002-2004 Glenn Maynard * All rights reserved. diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriver.h b/stepmania/src/arch/MemoryCard/MemoryCardDriver.h index 2d2ea57935..9c943ff013 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriver.h +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriver.h @@ -81,7 +81,16 @@ public: /* Poll for memory card changes. If anything has changed, fill in vStorageDevicesOut * and return true. */ - virtual bool DoOneUpdate( bool bMount, vector& vStorageDevicesOut ) = 0; + virtual bool DoOneUpdate( bool bMount, vector& vStorageDevicesOut ); + +protected: + virtual void GetUSBStorageDevices( vector& vDevicesOut ) { } + virtual bool USBStorageDevicesChanged() { return false; } + bool TestWrite( UsbStorageDevice* pDevice ) { return true; } + +private: + vector m_vDevicesLastSeen; + bool NeedUpdate( bool bMount ); }; #endif diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp index a3299d8e2b..d519001dea 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp @@ -1,15 +1,7 @@ #include "global.h" #include "MemoryCardDriverThreaded_Windows.h" #include "RageUtil.h" -#include "RageFileManager.h" #include "RageLog.h" -#include "ProfileManager.h" -#include "PrefsManager.h" -#include "Foreach.h" - -const CString TEMP_MOUNT_POINT_INTERNAL = "/@mctemp/"; -const CString TEMP_MOUNT_POINT = "/@mctemptimeout/"; - MemoryCardDriverThreaded_Windows::MemoryCardDriverThreaded_Windows() { @@ -41,13 +33,16 @@ static bool TestReady( const CString &sDrive, CString &sVolumeLabelOut ) return bRet; } -static bool TestWrite( const CString &sDrive ) +bool MemoryCardDriverThreaded_Windows::TestWrite( UsbStorageDevice* pDevice ) { // Try to write a file. - CString sFile = sDrive + "temp"; + CString sFile = pDevice->sOsMountDir + "temp"; FILE* fp = fopen( sFile, "w" ); if( fp == NULL ) + { + pDevice->SetError( "TestFailed" ); return false; + } fclose( fp ); remove( sFile ); @@ -118,19 +113,8 @@ void MemoryCardDriverThreaded_Windows::GetUSBStorageDevices( vector& 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; -} - bool MemoryCardDriverThreaded_Windows::Mount( UsbStorageDevice* pDevice ) { // nothing to do here... diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.h b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.h index 6e020e27a1..c45aeec5dc 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.h +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.h @@ -10,7 +10,6 @@ public: MemoryCardDriverThreaded_Windows(); virtual ~MemoryCardDriverThreaded_Windows(); - virtual bool DoOneUpdate( bool bMount, vector& vStorageDevicesOut ); virtual bool Mount( UsbStorageDevice* pDevice ); virtual void Unmount( UsbStorageDevice* pDevice ); virtual void Flush( UsbStorageDevice* pDevice ); @@ -18,10 +17,10 @@ public: private: void GetUSBStorageDevices( vector& vDevicesOut ); - bool NeedUpdate( bool bMount ); + bool USBStorageDevicesChanged(); + bool TestWrite( UsbStorageDevice* pDevice ); DWORD m_dwLastLogicalDrives; - vector m_vDevicesLastSeen; }; #ifdef ARCH_MEMORY_CARD_DRIVER