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 );
}
MEMCARDMAN->RefreshNames();
// Reset the USB storage device numbers -after- saving
CHECKPOINT;
MEMCARDMAN->FlushAllDisks();
MEMCARDMAN->FlushAndReset();
CHECKPOINT;
SONGMAN->FreeAllLoadedFromProfiles();
+4 -23
View File
@@ -176,8 +176,8 @@ void MemoryCardManager::AssignUnassignedCards()
continue;
vector<UsbStorageDevice>::iterator it = find(vUnassignedDevices.begin(),vUnassignedDevices.end(),m_Device[p]);
ASSERT( it != vUnassignedDevices.end() ) // the assigned card better be connected!
vUnassignedDevices.erase( it );
if( it != vUnassignedDevices.end() )
vUnassignedDevices.erase( it );
}
}
@@ -259,7 +259,7 @@ match:
}
}
void MemoryCardManager::FlushAllDisks()
void MemoryCardManager::FlushAndReset()
{
FOREACH_PlayerNumber( p )
{
@@ -270,7 +270,7 @@ void MemoryCardManager::FlushAllDisks()
m_pDriver->Flush(&m_Device[p]);
}
m_pDriver->ResetUsbStorage();
m_pDriver->ResetUsbStorage(); // forces cards to be re-detected
}
bool MemoryCardManager::PathIsMemCard( CString sDir ) const
@@ -285,22 +285,3 @@ CString MemoryCardManager::GetName( PlayerNumber pn ) const
{
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 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;
CString GetName( PlayerNumber pn ) const;
void RefreshNames();
protected:
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++ )
{
CString sChoice = Capitalize( as[i] );
CString sCondition = CONDITION(sChoice);
CString sCondition = CONDITION(sChoice);
if( Lua::RunExpression(sCondition) )
{
@@ -15,6 +15,7 @@ struct UsbStorageDevice
sScsiDevice = "";
sSerial = "";
sOsMountDir = "";
sName = "";
};
int iBus;
int iPort;
@@ -30,13 +31,14 @@ struct UsbStorageDevice
bool operator==(const UsbStorageDevice& other) const
{
if( (iBus!=-1 || other.iBus!=-1) && iBus != other.iBus )
return false;
if( (iPort!=-1 || other.iPort!=-1) && iPort != other.iPort )
return false;
if( (iLevel!=-1 || other.iLevel!=-1) && iLevel != other.iLevel )
return false;
return sOsMountDir==other.sOsMountDir; // every time a device is plugged in, it gets a unique device number
#define COMPARE(x) if( x != other.x ) return false;
COMPARE( iBus );
COMPARE( iPort );
COMPARE( iLevel );
COMPARE( sName );
COMPARE( sOsMountDir );
return true;
#undef COMPARE
}
bool operator!=(const UsbStorageDevice& other) const
{
@@ -14,6 +14,8 @@ const CString TEMP_MOUNT_POINT = "@mctemp/";
MemoryCardDriverThreaded_Windows::MemoryCardDriverThreaded_Windows()
{
m_bReset = false;
StartThread();
}
@@ -59,6 +61,12 @@ void MemoryCardDriverThreaded_Windows::MountThreadMain()
while( !m_bShutdown )
{
if( m_bReset )
{
dwLastLogicalDrives = 0;
m_bReset = false;
}
DWORD dwNewLogicalDrives = ::GetLogicalDrives();
if( dwNewLogicalDrives != dwLastLogicalDrives )
{
@@ -141,6 +149,11 @@ void MemoryCardDriverThreaded_Windows::Flush( UsbStorageDevice* pDevice )
// 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.
* Chris Danford
@@ -10,10 +10,12 @@ public:
virtual void Unmount( UsbStorageDevice* pDevice, CString sMountPoint );
virtual void Flush( UsbStorageDevice* pDevice );
virtual void ResetUsbStorage() {}
virtual void ResetUsbStorage();
protected:
virtual void MountThreadMain();
virtual void Mount( UsbStorageDevice* pDevice, CString sMountPoint );
bool m_bReset;
};
#endif