From 9fe9b0884a2852c1245f2fd721e3435b92073e49 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sun, 3 Oct 2004 05:27:52 +0000 Subject: [PATCH] Add hack to not leave cards mounted --- stepmania/src/GameState.cpp | 7 ++++++- stepmania/src/MemoryCardManager.cpp | 23 +++++++++++++++++++++++ stepmania/src/MemoryCardManager.h | 3 +++ stepmania/src/PrefsManager.cpp | 5 ++++- stepmania/src/PrefsManager.h | 1 + stepmania/src/ScreenEvaluation.cpp | 7 +++++++ 6 files changed, 44 insertions(+), 2 deletions(-) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index 911cb0ec50..c4d35fcee4 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -234,7 +234,6 @@ void GameState::PlayersFinalized() MEMCARDMAN->LockCards( true ); - // apply saved default modifiers if any FOREACH_HumanPlayer( pn ) { @@ -270,6 +269,9 @@ void GameState::PlayersFinalized() if( !IsHumanPlayer(pn) ) ApplyModifiers( pn, DEFAULT_CPU_MODIFIERS ); } + + if( PREFSMAN->m_bMemoryCardsMountOnlyWhenNecessary ) + MEMCARDMAN->UnmountAllCards(); } /* This data is added to each player profile, and to the machine profile per-player. */ @@ -342,6 +344,9 @@ void GameState::EndGame() } + if( PREFSMAN->m_bMemoryCardsMountOnlyWhenNecessary ) + MEMCARDMAN->MountAllCards(); + BOOKKEEPER->WriteToDisk(); PROFILEMAN->SaveAllProfiles(); diff --git a/stepmania/src/MemoryCardManager.cpp b/stepmania/src/MemoryCardManager.cpp index 5bc4f75c38..c2c2c7660e 100644 --- a/stepmania/src/MemoryCardManager.cpp +++ b/stepmania/src/MemoryCardManager.cpp @@ -233,6 +233,29 @@ void MemoryCardManager::MountAllCards() } } +void MemoryCardManager::UnmountAllCards() +{ + FOREACH_PlayerNumber( p ) + { + if( m_Device[p].IsBlank() ) // they don't have an assigned card + continue; + + m_pDriver->Unmount(&m_Device[p], MEM_CARD_MOUNT_POINT[p]); + } +} + +void MemoryCardManager::MountCard( PlayerNumber pn ) +{ + ASSERT( !m_Device[pn].IsBlank() ); + m_pDriver->MountAndTestWrite(&m_Device[pn], MEM_CARD_MOUNT_POINT[pn]); +} + +void MemoryCardManager::UnmountCard( PlayerNumber pn ) +{ + ASSERT( !m_Device[pn].IsBlank() ); + m_pDriver->Unmount(&m_Device[pn], MEM_CARD_MOUNT_POINT[pn]); +} + void MemoryCardManager::FlushAndReset() { FOREACH_PlayerNumber( p ) diff --git a/stepmania/src/MemoryCardManager.h b/stepmania/src/MemoryCardManager.h index ca98bb77c5..c3b8fa3e48 100644 --- a/stepmania/src/MemoryCardManager.h +++ b/stepmania/src/MemoryCardManager.h @@ -28,6 +28,9 @@ public: void LockCards( bool bLock ); // prevent removing or changing of memory cards void MountAllCards(); + void UnmountAllCards(); + void MountCard( PlayerNumber pn ); + void UnmountCard( PlayerNumber pn ); void PauseMountingThread(); // call this before reading or writing to memory card void UnPauseMountingThread(); // call this when done reading or writing to memory card diff --git a/stepmania/src/PrefsManager.cpp b/stepmania/src/PrefsManager.cpp index a5905a7a9a..ffd8d5c9e3 100644 --- a/stepmania/src/PrefsManager.cpp +++ b/stepmania/src/PrefsManager.cpp @@ -311,7 +311,8 @@ void PrefsManager::Init() m_iMemoryCardUsbPort[p] = -1; m_iMemoryCardUsbLevel[p] = -1; } - + m_bMemoryCardsMountOnlyWhenNecessary = false; + m_sMemoryCardProfileSubdir = PRODUCT_NAME; m_iProductID = 1; @@ -547,6 +548,7 @@ void PrefsManager::ReadPrefsFromFile( CString sIni ) ini.GetValue( "Options", ssprintf("MemoryCardUsbPortP%d",p+1), m_iMemoryCardUsbPort[p] ); ini.GetValue( "Options", ssprintf("MemoryCardUsbLevelP%d",p+1), m_iMemoryCardUsbLevel[p] ); } + ini.GetValue( "Options", "MemoryCardsMountOnlyWhenNecessary", m_bMemoryCardsMountOnlyWhenNecessary ); ini.GetValue( "Options", "CenterImageTranslateX", m_iCenterImageTranslateX ); ini.GetValue( "Options", "CenterImageTranslateY", m_iCenterImageTranslateY ); @@ -777,6 +779,7 @@ void PrefsManager::SaveGlobalPrefsToDisk() const ini.SetValue( "Options", ssprintf("MemoryCardUsbPortP%d",p+1), m_iMemoryCardUsbPort[p] ); ini.SetValue( "Options", ssprintf("MemoryCardUsbLevelP%d",p+1), m_iMemoryCardUsbLevel[p] ); } + ini.SetValue( "Options", "MemoryCardsMountOnlyWhenNecessary", m_bMemoryCardsMountOnlyWhenNecessary ); ini.SetValue( "Options", "CenterImageTranslateX", m_iCenterImageTranslateX ); ini.SetValue( "Options", "CenterImageTranslateY", m_iCenterImageTranslateY ); diff --git a/stepmania/src/PrefsManager.h b/stepmania/src/PrefsManager.h index f22f45a0dc..b97f10fc0a 100644 --- a/stepmania/src/PrefsManager.h +++ b/stepmania/src/PrefsManager.h @@ -189,6 +189,7 @@ public: int m_iMemoryCardUsbBus[NUM_PLAYERS]; // look for this bus when assigning cards. -1 = match any int m_iMemoryCardUsbPort[NUM_PLAYERS]; // look for this port when assigning cards. -1 = match any int m_iMemoryCardUsbLevel[NUM_PLAYERS]; // look for this level when assigning cards. -1 = match any + bool m_bMemoryCardsMountOnlyWhenNecessary; int m_iCenterImageTranslateX; int m_iCenterImageTranslateY; float m_fCenterImageScaleX; diff --git a/stepmania/src/ScreenEvaluation.cpp b/stepmania/src/ScreenEvaluation.cpp index 25f34474bf..8cf5578d47 100644 --- a/stepmania/src/ScreenEvaluation.cpp +++ b/stepmania/src/ScreenEvaluation.cpp @@ -27,6 +27,7 @@ #include "StepMania.h" #include "CryptManager.h" #include "Style.h" +#include "MemoryCardManager.h" const int NUM_SCORE_DIGITS = 9; @@ -1352,12 +1353,18 @@ void ScreenEvaluation::Input( const DeviceInput& DeviceI, const InputEventType t if( !m_bSavedScreenshot[pn] && // only allow one screenshot PROFILEMAN->IsUsingProfile(pn) ) { + if( PREFSMAN->m_bMemoryCardsMountOnlyWhenNecessary ) + MEMCARDMAN->MountCard( pn ); + Profile* pProfile = PROFILEMAN->GetProfile(pn); CString sDir = PROFILEMAN->GetProfileDir((ProfileSlot)pn) + "Screenshots/"; int iScreenshotIndex = pProfile->GetNextScreenshotIndex(); CString sFileName = SaveScreenshot( sDir, true, true, iScreenshotIndex ); CString sPath = sDir+sFileName; + if( PREFSMAN->m_bMemoryCardsMountOnlyWhenNecessary ) + MEMCARDMAN->UnmountCard( pn ); + if( !sFileName.empty() ) { Screenshot screenshot;