move RageFileManager mounting into the MemoryCardDriver, not MemoryCardManager

This commit is contained in:
Chris Danford
2004-03-14 01:40:24 +00:00
parent 08db59fa25
commit 9555d508ee
9 changed files with 41 additions and 32 deletions
+7 -1
View File
@@ -126,6 +126,7 @@ MemoryCardState MemoryCardManager::GetCardState( PlayerNumber pn )
return MEMORY_CARD_STATE_READY; return MEMORY_CARD_STATE_READY;
} }
/*
CString MemoryCardManager::GetOsMountDir( PlayerNumber pn ) CString MemoryCardManager::GetOsMountDir( PlayerNumber pn )
{ {
if( m_Device[pn].IsBlank() ) if( m_Device[pn].IsBlank() )
@@ -139,6 +140,7 @@ CString MemoryCardManager::GetOsMountDir( PlayerNumber pn )
return sDir; return sDir;
} }
} }
*/
void MemoryCardManager::LockCards( bool bLock ) void MemoryCardManager::LockCards( bool bLock )
{ {
@@ -230,8 +232,12 @@ match:
m_bTooLate[p] = m_bCardsLocked; m_bTooLate[p] = m_bCardsLocked;
m_bWriteError[p] = false; m_bWriteError[p] = false;
if( !m_bCardsLocked ) if( !m_bCardsLocked )
if( !m_pDriver->MountAndTestWrite(&m_Device[p]) ) {
if( !m_pDriver->MountAndTestWrite(&m_Device[p], MEM_CARD_MOUNT_POINT[p]) )
{
m_bWriteError[p] = true; m_bWriteError[p] = true;
}
}
// play sound // play sound
if( m_bWriteError[p] ) if( m_bWriteError[p] )
+10 -1
View File
@@ -15,6 +15,15 @@
#include "RageSound.h" #include "RageSound.h"
#include "arch/MemoryCard/MemoryCardDriver.h" #include "arch/MemoryCard/MemoryCardDriver.h"
const CString MEM_CARD_MOUNT_POINT[NUM_PLAYERS] =
{
/* @ is importast; see RageFileManager LoadedDriver::GetPath */
"@mc1/",
"@mc2/",
};
class MemoryCardManager class MemoryCardManager
{ {
public: public:
@@ -25,7 +34,7 @@ public:
MemoryCardState GetCardState( PlayerNumber pn ); MemoryCardState GetCardState( PlayerNumber pn );
CString GetOsMountDir( PlayerNumber pn ); // only valid when state = ready // CString GetOsMountDir( PlayerNumber pn ); // only valid when state = ready
void LockCards( bool bLock ); // prevent removing or changing of memory cards void LockCards( bool bLock ); // prevent removing or changing of memory cards
+5 -23
View File
@@ -34,23 +34,11 @@
ProfileManager* PROFILEMAN = NULL; // global and accessable from anywhere in our program ProfileManager* PROFILEMAN = NULL; // global and accessable from anywhere in our program
#define NEW_MEM_CARD_NAME "" #define NEW_MEM_CARD_NAME ""
#define USER_PROFILES_DIR "Data/LocalProfiles/" #define USER_PROFILES_DIR "Data/LocalProfiles/"
#define MACHINE_PROFILE_DIR "Data/MachineProfile/" #define MACHINE_PROFILE_DIR "Data/MachineProfile/"
static const char *MEM_CARD_DIR[NUM_PLAYERS] =
{
/* @ is importast; see RageFileManager LoadedDriver::GetPath */
"@mc1/",
"@mc2/",
};
ProfileManager::ProfileManager() ProfileManager::ProfileManager()
{ {
PROFILEMAN = this; PROFILEMAN = this;
@@ -144,18 +132,10 @@ bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn )
{ {
UnloadProfile( pn ); UnloadProfile( pn );
#ifndef _XBOX #ifndef _XBOX
// moust slot // mount slot
if( MEMCARDMAN->GetCardState(pn) == MEMORY_CARD_STATE_READY ) if( MEMCARDMAN->GetCardState(pn) == MEMORY_CARD_STATE_READY )
{ {
// XXX: Remounting a different OS directory to the same mount point CString sDir = MEM_CARD_MOUNT_POINT[pn];
// seems to be broken. Investigate this later...
FILEMAN->Mount( "dir", MEMCARDMAN->GetOsMountDir(pn), MEM_CARD_DIR[pn] );
LOG->Trace( "mount %s %s", MEMCARDMAN->GetOsMountDir(pn).c_str(), MEM_CARD_DIR[pn] );
CString sDir = MEM_CARD_DIR[pn];
// CString sDir = MEMCARDMAN->GetOsMountDir(pn);
DEBUG_ASSERT( MEMCARDMAN->GetOsMountDir(pn) ); // should be called only if we've already mounted
// tack on a subdirectory so that we don't write everything to the root // tack on a subdirectory so that we don't write everything to the root
sDir += PREFSMAN->m_sMemoryCardProfileSubdir; sDir += PREFSMAN->m_sMemoryCardProfileSubdir;
@@ -179,7 +159,9 @@ bool ProfileManager::CreateMemoryCardProfile( PlayerNumber pn )
{ {
// CString sDir = MEM_CARD_DIR[pn]; // CString sDir = MEM_CARD_DIR[pn];
CString sDir = MEMCARDMAN->GetOsMountDir(pn); ASSERT( MEMCARDMAN->GetCardState(pn) == MEMORY_CARD_STATE_READY );
CString sDir = MEM_CARD_MOUNT_POINT[pn];
DEBUG_ASSERT( FILEMAN->IsMounted(sDir) ); // should be called only if we've already mounted DEBUG_ASSERT( FILEMAN->IsMounted(sDir) ); // should be called only if we've already mounted
@@ -1,7 +1,6 @@
#ifndef MEMORY_CARD_ENUMERATOR_H #ifndef MEMORY_CARD_ENUMERATOR_H
#define MEMORY_CARD_ENUMERATOR_H 1 #define MEMORY_CARD_ENUMERATOR_H 1
struct UsbStorageDevice struct UsbStorageDevice
{ {
UsbStorageDevice() { MakeBlank(); } UsbStorageDevice() { MakeBlank(); }
@@ -44,7 +43,7 @@ public:
virtual ~MemoryCardDriver() {}; virtual ~MemoryCardDriver() {};
virtual bool StorageDevicesChanged() = 0; virtual bool StorageDevicesChanged() = 0;
virtual void GetStorageDevices( vector<UsbStorageDevice>& vStorageDevicesOut ) = 0; virtual void GetStorageDevices( vector<UsbStorageDevice>& vStorageDevicesOut ) = 0;
virtual bool MountAndTestWrite( UsbStorageDevice* pDevice ) = 0; // return false if mount or write fails virtual bool MountAndTestWrite( UsbStorageDevice* pDevice, CString sMountPoint ) = 0; // return false if mount or write fails
virtual void Flush( UsbStorageDevice* pDevice ) {} virtual void Flush( UsbStorageDevice* pDevice ) {}
virtual void ResetUsbStorage() {}; virtual void ResetUsbStorage() {};
}; };
@@ -231,7 +231,7 @@ void MemoryCardDriver_Linux::GetStorageDevices( vector<UsbStorageDevice>& vDevic
} }
} }
bool MemoryCardDriver_Linux::MountAndTestWrite( UsbStorageDevice* pDevice ) bool MemoryCardDriver_Linux::MountAndTestWrite( UsbStorageDevice* pDevice, CString sMountPoint )
{ {
if( pDevice->sOsMountDir.empty() ) if( pDevice->sOsMountDir.empty() )
return false; return false;
@@ -255,6 +255,12 @@ bool MemoryCardDriver_Linux::MountAndTestWrite( UsbStorageDevice* pDevice )
fclose( fp ); fclose( fp );
remove( sFile ); remove( sFile );
// XXX: Remounting a different OS directory to the same mount point
// seems to be broken. Investigate this later...
FILEMAN->Mount( "dir", pDevice->sOsMountDir, sMountPoint.c_str() );
LOG->Trace( "FILEMAN->Mount %s %s", pDevice->sOsMountDir.c_str(), sMountPoint.c_str() );
return true; return true;
} }
@@ -10,7 +10,7 @@ public:
virtual ~MemoryCardDriver_Linux(); virtual ~MemoryCardDriver_Linux();
virtual bool StorageDevicesChanged(); virtual bool StorageDevicesChanged();
virtual void GetStorageDevices( vector<UsbStorageDevice>& vStorageDevicesOut ); virtual void GetStorageDevices( vector<UsbStorageDevice>& vStorageDevicesOut );
virtual bool MountAndTestWrite( UsbStorageDevice* pDevice ); virtual bool MountAndTestWrite( UsbStorageDevice* pDevice, CString sMountPoint );
virtual void Flush( UsbStorageDevice* pDevice ); virtual void Flush( UsbStorageDevice* pDevice );
virtual void ResetUsbStorage(); virtual void ResetUsbStorage();
protected: protected:
@@ -9,7 +9,7 @@ public:
MemoryCardDriver_Null() {}; MemoryCardDriver_Null() {};
virtual bool StorageDevicesChanged() { return false; }; virtual bool StorageDevicesChanged() { return false; };
virtual void GetStorageDevices( vector<UsbStorageDevice>& vStorageDevicesOut ) {}; virtual void GetStorageDevices( vector<UsbStorageDevice>& vStorageDevicesOut ) {};
virtual bool MountAndTestWrite( UsbStorageDevice* pDevice ) { return false; }; virtual bool MountAndTestWrite( UsbStorageDevice* pDevice, CString sMountPoint ) { return false; };
virtual void Flush( UsbStorageDevice* pDevice ) {}; virtual void Flush( UsbStorageDevice* pDevice ) {};
}; };
@@ -3,6 +3,8 @@
#include "RageUtil.h" #include "RageUtil.h"
#include <io.h> #include <io.h>
#include <fcntl.h> #include <fcntl.h>
#include "RageFileManager.h"
#include "RageLog.h"
MemoryCardDriver_Windows::MemoryCardDriver_Windows() MemoryCardDriver_Windows::MemoryCardDriver_Windows()
{ {
@@ -49,7 +51,7 @@ void MemoryCardDriver_Windows::GetStorageDevices( vector<UsbStorageDevice>& vDev
} }
} }
bool MemoryCardDriver_Windows::MountAndTestWrite( UsbStorageDevice* pDevice ) bool MemoryCardDriver_Windows::MountAndTestWrite( UsbStorageDevice* pDevice, CString sMountPoint )
{ {
if( pDevice->sOsMountDir.empty() ) if( pDevice->sOsMountDir.empty() )
return false; return false;
@@ -81,6 +83,11 @@ bool MemoryCardDriver_Windows::MountAndTestWrite( UsbStorageDevice* pDevice )
fclose( fp ); fclose( fp );
remove( sFile ); remove( sFile );
// XXX: Remounting a different OS directory to the same mount point
// seems to be broken. Investigate this later...
FILEMAN->Mount( "dir", pDevice->sOsMountDir, sMountPoint.c_str() );
LOG->Trace( "FILEMAN->Mount %s %s", pDevice->sOsMountDir.c_str(), sMountPoint.c_str() );
return true; return true;
} }
@@ -11,7 +11,7 @@ public:
virtual ~MemoryCardDriver_Windows(); virtual ~MemoryCardDriver_Windows();
virtual bool StorageDevicesChanged(); virtual bool StorageDevicesChanged();
virtual void GetStorageDevices( vector<UsbStorageDevice>& vStorageDevicesOut ); virtual void GetStorageDevices( vector<UsbStorageDevice>& vStorageDevicesOut );
virtual bool MountAndTestWrite( UsbStorageDevice* pDevice ); virtual bool MountAndTestWrite( UsbStorageDevice* pDevice, CString sMountPoint );
virtual void Flush( UsbStorageDevice* pDevice ); virtual void Flush( UsbStorageDevice* pDevice );
protected: protected:
DWORD m_dwLastLogicalDrives; DWORD m_dwLastLogicalDrives;