From ae319bd14ecd5d8e8b6a3994507687623751b113 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sat, 14 Aug 2004 19:38:37 +0000 Subject: [PATCH] refactor common unmount code --- .../arch/MemoryCard/MemoryCardDriverThreaded.cpp | 15 +++++++++++++++ .../arch/MemoryCard/MemoryCardDriverThreaded.h | 4 ++++ .../MemoryCard/MemoryCardDriverThreaded_Linux.cpp | 15 +++------------ .../MemoryCardDriverThreaded_Windows.cpp | 13 ++----------- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.cpp index c7f4188962..d17ca2691b 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.cpp +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.cpp @@ -135,6 +135,21 @@ bool MemoryCardDriverThreaded::MountAndTestWrite( UsbStorageDevice* pDevice, CSt return true; } + +void MemoryCardDriverThreaded::UnmountMountPoint( const CString &sMountPoint ) +{ + vector Mounts; + FILEMAN->GetLoadedDrivers( Mounts ); + for( unsigned i = 0; i < Mounts.size(); ++i ) + { + if( Mounts[i].Type.CompareNoCase( "dir" ) ) + continue; // wrong type + if( Mounts[i].MountPoint.CompareNoCase( sMountPoint ) ) + continue; // wrong mount point + FILEMAN->Unmount( Mounts[i].Type, Mounts[i].Root, Mounts[i].MountPoint ); + } +} + /* * (c) 2003-2004 Chris Danford * All rights reserved. diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.h b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.h index 8455fd0dec..290f72ec3a 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.h +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.h @@ -53,6 +53,10 @@ protected: bool m_bStorageDevicesChanged; RageMutex m_mutexStorageDevices; // protects the above two bool m_bForceRedetectNextUpdate; // on the next update, redetect from scratch report new devices found + + + // placed here for use by derivitives to eliminate duplicate code + void UnmountMountPoint( const CString &sMountPoint ); }; #endif diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp index 91b9c4df8e..2a367c3121 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp @@ -276,7 +276,8 @@ void MemoryCardDriverThreaded_Linux::MountThreadDoOneUpdate() CString sProfileDir = TEMP_MOUNT_POINT + PREFSMAN->m_sMemoryCardProfileSubdir + '/'; profile.LoadEditableDataFromDir( sProfileDir ); d.sName = profile.GetDisplayName(); - + UnmountMountPoint( TEMP_MOUNT_POINT ); + LOG->Trace( "write test %s", d.bWriteTestSucceeded ? "succeeded" : "failed" ); } } @@ -645,17 +646,7 @@ void MemoryCardDriverThreaded_Linux::Mount( UsbStorageDevice* pDevice, CString s { ASSERT( !pDevice->sOsMountDir.empty() ); - /* Unmount any previous mounts for this mountpoint. */ - vector Mounts; - FILEMAN->GetLoadedDrivers( Mounts ); - for( unsigned i = 0; i < Mounts.size(); ++i ) - { - if( Mounts[i].Type.CompareNoCase( "dir" ) ) - continue; // wrong type - if( Mounts[i].MountPoint.CompareNoCase( sMountPoint ) ) - continue; // wrong mount point - FILEMAN->Unmount( Mounts[i].Type, Mounts[i].Root, Mounts[i].MountPoint ); - } + UnmountMountPoint( sMountPoint ); FILEMAN->Mount( "dir", pDevice->sOsMountDir, sMountPoint.c_str() ); LOG->Trace( "FILEMAN->Mount %s %s", pDevice->sOsMountDir.c_str(), sMountPoint.c_str() ); diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp index 18aa565fd7..35d60721f8 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp @@ -112,6 +112,7 @@ void MemoryCardDriverThreaded_Windows::MountThreadDoOneUpdate() CString sProfileDir = TEMP_MOUNT_POINT + PREFSMAN->m_sMemoryCardProfileSubdir + '/'; profile.LoadEditableDataFromDir( sProfileDir ); usbd.sName = profile.GetDisplayName(); + UnmountMountPoint( TEMP_MOUNT_POINT ); } vNewStorageDevices.push_back( usbd ); @@ -136,17 +137,7 @@ void MemoryCardDriverThreaded_Windows::Mount( UsbStorageDevice* pDevice, CString { ASSERT( !pDevice->sOsMountDir.empty() ); - /* Unmount any previous mounts for this mountpoint. */ - vector Mounts; - FILEMAN->GetLoadedDrivers( Mounts ); - for( unsigned i = 0; i < Mounts.size(); ++i ) - { - if( Mounts[i].Type.CompareNoCase( "dir" ) ) - continue; // wrong type - if( Mounts[i].MountPoint.CompareNoCase( sMountPoint ) ) - continue; // wrong mount point - FILEMAN->Unmount( Mounts[i].Type, Mounts[i].Root, Mounts[i].MountPoint ); - } + UnmountMountPoint( sMountPoint ); FILEMAN->Mount( "dir", pDevice->sOsMountDir, sMountPoint.c_str() ); LOG->Trace( "FILEMAN->Mount %s %s", pDevice->sOsMountDir.c_str(), sMountPoint.c_str() );