diff --git a/stepmania/src/MemoryCardManager.cpp b/stepmania/src/MemoryCardManager.cpp index fc1a5ae9ed..17ff5385b2 100644 --- a/stepmania/src/MemoryCardManager.cpp +++ b/stepmania/src/MemoryCardManager.cpp @@ -56,7 +56,7 @@ struct UsbStorageDevice vector g_StorageDevices; -bool UpdateAttachedUsbStorageDevices() +void UpdateAttachedUsbStorageDevices() { vector &vDevicesOut = g_StorageDevices; @@ -92,7 +92,7 @@ bool UpdateAttachedUsbStorageDevices() if( !f.is_open() ) { LOG->Warn( "can't open '%s'", fn.c_str() ); - return false; + return; } UsbStorageDevice usbd; @@ -155,7 +155,7 @@ bool UpdateAttachedUsbStorageDevices() if( !f.is_open() ) { LOG->Warn( "can't open '%s'", fn.c_str() ); - return false; + return; } CString sLine; @@ -186,7 +186,7 @@ bool UpdateAttachedUsbStorageDevices() if( !f.is_open() ) { LOG->Warn( "can't open '%s'", fn.c_str() ); - return false; + return; } CString sLine; @@ -216,11 +216,11 @@ bool UpdateAttachedUsbStorageDevices() } } } - return true; + return; #elif defined(_WINDOWS) - return false; + #else - return false; + #endif } @@ -235,35 +235,59 @@ MemoryCardManager::~MemoryCardManager() } +bool UsbChanged() +{ +#if defined(LINUX) + // UGLY: if the system log changed, then a USB device was connected or + // disconnected. Use this as a trivial check. + static const CString VAR_LOG_MESSAGES = "/var/log/messages"; + static bool bFirstTime = false; + static _stat old_stat; + if( bFirstTime ) + { + _fstat(VAR_LOG_MESSAGES, &old_stat); + bFirstTime = false; + return true; + } + else + { + _stat new_stat; + _fstat(VAR_LOG_MESSAGES, &new_stat); + bool bChanged = old_stat != new_stat; + old_stat = new_stat; + return bChanged; + } +#elif defined(_WINDOWS) + return false; +#else + return false; +#endif +} + void MemoryCardManager::Update( float fDelta ) { - /* - static count = 0; - count++; - if( count != 20 ) - return; - count = 0; - - vector vOld = g_StorageDevices; - UpdateAttachedUsbStorageDevices(); - vector &vNew = g_StorageDevices; - - unsigned i; - - // check for disconnects - for( i=0; iSystemMessage( ssprintf("Disconnected bus %d port %d device %d", old.iBus, old.iPortOnHub, old.iDeviceOnBus) ); - } + vector vOld = g_StorageDevices; // make a copy + UpdateAttachedUsbStorageDevices(); + vector &vNew = g_StorageDevices; - // check for connects - for( i=0; iSystemMessage( ssprintf("Connected bus %d port %d device %d", newd.iBus, newd.iPortOnHub, newd.iDeviceOnBus) ); + unsigned i; + + // check for disconnects + for( i=0; iSystemMessage( ssprintf("Disconnected bus %d port %d device %d", old.iBus, old.iPortOnHub, old.iDeviceOnBus) ); + } + + // check for connects + for( i=0; iSystemMessage( ssprintf("Connected bus %d port %d device %d", newd.iBus, newd.iPortOnHub, newd.iDeviceOnBus) ); + } } - */ }