simplify name update logic

This commit is contained in:
Chris Danford
2004-05-03 00:34:54 +00:00
parent d30a6fe77b
commit bfd7b1930c
7 changed files with 32 additions and 37 deletions
+1 -3
View File
@@ -368,11 +368,9 @@ void GameState::EndGame()
PROFILEMAN->UnloadProfile( pn ); PROFILEMAN->UnloadProfile( pn );
} }
MEMCARDMAN->RefreshNames();
// Reset the USB storage device numbers -after- saving // Reset the USB storage device numbers -after- saving
CHECKPOINT; CHECKPOINT;
MEMCARDMAN->FlushAllDisks(); MEMCARDMAN->FlushAndReset();
CHECKPOINT; CHECKPOINT;
SONGMAN->FreeAllLoadedFromProfiles(); SONGMAN->FreeAllLoadedFromProfiles();
+4 -23
View File
@@ -176,8 +176,8 @@ void MemoryCardManager::AssignUnassignedCards()
continue; continue;
vector<UsbStorageDevice>::iterator it = find(vUnassignedDevices.begin(),vUnassignedDevices.end(),m_Device[p]); vector<UsbStorageDevice>::iterator it = find(vUnassignedDevices.begin(),vUnassignedDevices.end(),m_Device[p]);
ASSERT( it != vUnassignedDevices.end() ) // the assigned card better be connected! if( it != vUnassignedDevices.end() )
vUnassignedDevices.erase( it ); vUnassignedDevices.erase( it );
} }
} }
@@ -259,7 +259,7 @@ match:
} }
} }
void MemoryCardManager::FlushAllDisks() void MemoryCardManager::FlushAndReset()
{ {
FOREACH_PlayerNumber( p ) FOREACH_PlayerNumber( p )
{ {
@@ -270,7 +270,7 @@ void MemoryCardManager::FlushAllDisks()
m_pDriver->Flush(&m_Device[p]); m_pDriver->Flush(&m_Device[p]);
} }
m_pDriver->ResetUsbStorage(); m_pDriver->ResetUsbStorage(); // forces cards to be re-detected
} }
bool MemoryCardManager::PathIsMemCard( CString sDir ) const bool MemoryCardManager::PathIsMemCard( CString sDir ) const
@@ -285,22 +285,3 @@ CString MemoryCardManager::GetName( PlayerNumber pn ) const
{ {
return m_Device[pn].sName; return m_Device[pn].sName;
} }
void MemoryCardManager::RefreshNames()
{
// HACK: UsbStorageDevice::sName is only read when the device is connected.
// If the player leaves their memory card in after the game ends and they
// immediate start another game, then sName isn't re-read automatically.
// It's much harder to add logic to read the name again to MemoryCardDriver
// than to add a small hack here.
FOREACH_PlayerNumber( p )
{
if( m_Device[p].IsBlank() ) // no card assigned
continue; // skip
if( m_bWriteError[p] || m_bTooLate[p] )
continue; // skip
CString sProfileDir = MEM_CARD_MOUNT_POINT[p] + PREFSMAN->m_sMemoryCardProfileSubdir + '/';
m_Device[p].sName = Profile::GetProfileDisplayNameFromDir( sProfileDir );
}
}
+1 -2
View File
@@ -37,12 +37,11 @@ public:
void LockCards( bool bLock ); // prevent removing or changing of memory cards void LockCards( bool bLock ); // prevent removing or changing of memory cards
void FlushAllDisks(); // force all files to be written to mounted memory cards void FlushAndReset(); // force all files to be written to mounted memory cards
bool PathIsMemCard( CString sDir ) const; bool PathIsMemCard( CString sDir ) const;
CString GetName( PlayerNumber pn ) const; CString GetName( PlayerNumber pn ) const;
void RefreshNames();
protected: protected:
void AssignUnassignedCards(); // do our best to assign a Device to each player void AssignUnassignedCards(); // do our best to assign a Device to each player
+1 -1
View File
@@ -30,7 +30,7 @@ ScreenBranch::ScreenBranch( CString sClassName ) : Screen( sClassName )
for( unsigned i=0; i<as.size(); i++ ) for( unsigned i=0; i<as.size(); i++ )
{ {
CString sChoice = Capitalize( as[i] ); CString sChoice = Capitalize( as[i] );
CString sCondition = CONDITION(sChoice); CString sCondition = CONDITION(sChoice);
if( Lua::RunExpression(sCondition) ) if( Lua::RunExpression(sCondition) )
{ {
@@ -15,6 +15,7 @@ struct UsbStorageDevice
sScsiDevice = ""; sScsiDevice = "";
sSerial = ""; sSerial = "";
sOsMountDir = ""; sOsMountDir = "";
sName = "";
}; };
int iBus; int iBus;
int iPort; int iPort;
@@ -30,13 +31,14 @@ struct UsbStorageDevice
bool operator==(const UsbStorageDevice& other) const bool operator==(const UsbStorageDevice& other) const
{ {
if( (iBus!=-1 || other.iBus!=-1) && iBus != other.iBus ) #define COMPARE(x) if( x != other.x ) return false;
return false; COMPARE( iBus );
if( (iPort!=-1 || other.iPort!=-1) && iPort != other.iPort ) COMPARE( iPort );
return false; COMPARE( iLevel );
if( (iLevel!=-1 || other.iLevel!=-1) && iLevel != other.iLevel ) COMPARE( sName );
return false; COMPARE( sOsMountDir );
return sOsMountDir==other.sOsMountDir; // every time a device is plugged in, it gets a unique device number return true;
#undef COMPARE
} }
bool operator!=(const UsbStorageDevice& other) const bool operator!=(const UsbStorageDevice& other) const
{ {
@@ -14,6 +14,8 @@ const CString TEMP_MOUNT_POINT = "@mctemp/";
MemoryCardDriverThreaded_Windows::MemoryCardDriverThreaded_Windows() MemoryCardDriverThreaded_Windows::MemoryCardDriverThreaded_Windows()
{ {
m_bReset = false;
StartThread(); StartThread();
} }
@@ -59,6 +61,12 @@ void MemoryCardDriverThreaded_Windows::MountThreadMain()
while( !m_bShutdown ) while( !m_bShutdown )
{ {
if( m_bReset )
{
dwLastLogicalDrives = 0;
m_bReset = false;
}
DWORD dwNewLogicalDrives = ::GetLogicalDrives(); DWORD dwNewLogicalDrives = ::GetLogicalDrives();
if( dwNewLogicalDrives != dwLastLogicalDrives ) if( dwNewLogicalDrives != dwLastLogicalDrives )
{ {
@@ -141,6 +149,11 @@ void MemoryCardDriverThreaded_Windows::Flush( UsbStorageDevice* pDevice )
// Windows flushes automatically every ~2 seconds. -Chris // Windows flushes automatically every ~2 seconds. -Chris
} }
void MemoryCardDriverThreaded_Windows::ResetUsbStorage()
{
m_bReset = true;
}
/* /*
* Copyright (c) 2003 by the person(s) listed below. All rights reserved. * Copyright (c) 2003 by the person(s) listed below. All rights reserved.
* Chris Danford * Chris Danford
@@ -10,10 +10,12 @@ public:
virtual void Unmount( UsbStorageDevice* pDevice, CString sMountPoint ); virtual void Unmount( UsbStorageDevice* pDevice, CString sMountPoint );
virtual void Flush( UsbStorageDevice* pDevice ); virtual void Flush( UsbStorageDevice* pDevice );
virtual void ResetUsbStorage() {} virtual void ResetUsbStorage();
protected: protected:
virtual void MountThreadMain(); virtual void MountThreadMain();
virtual void Mount( UsbStorageDevice* pDevice, CString sMountPoint ); virtual void Mount( UsbStorageDevice* pDevice, CString sMountPoint );
bool m_bReset;
}; };
#endif #endif