fix Windows prompts to insert disk if memory card not present

This commit is contained in:
Chris Danford
2003-11-09 10:53:19 +00:00
parent 7bf6dfb631
commit c98956653e
+34 -14
View File
@@ -131,21 +131,41 @@ bool ProfileManager::IsMemoryCardInserted( PlayerNumber pn )
if( sDir.empty() ) if( sDir.empty() )
return false; return false;
// #ifdef _WINDOWS
// Test whether a memory card is available by trying to write a file. // Windows will throw up a message box if we try to write to a
// // removable drive with no disk inserted. Find out whether there's a
CString sFile = sDir + "temp"; // disk in the drive w/o writing a file.
FILE* fp = fopen( sFile, "w" );
if( fp ) // find drive letter
{ vector<CString> matches;
fclose( fp ); static Regex parse("^([A-Za-z]+):");
remove( sFile ); parse.Compare(sDir, matches);
return true; if( matches.size() != 1 )
}
else
{ {
return false; return false;
} }
else
{
CString sDrive = matches[0];
TCHAR szVolumeNameBuffer[MAX_PATH];
DWORD dwVolumeSerialNumber;
DWORD dwMaximumComponentLength;
DWORD lpFileSystemFlags;
TCHAR szFileSystemNameBuffer[MAX_PATH];
BOOL bResult = GetVolumeInformation(
sDrive + ":",
szVolumeNameBuffer,
sizeof(szVolumeNameBuffer),
&dwVolumeSerialNumber,
&dwMaximumComponentLength,
&lpFileSystemFlags,
szFileSystemNameBuffer,
sizeof(szFileSystemNameBuffer) );
return !!bResult;
}
#endif
return true;
} }
bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn ) bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn )
@@ -161,13 +181,13 @@ bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn )
} }
bool ProfileManager::LoadFirstAvailableProfile( PlayerNumber pn ) bool ProfileManager::LoadFirstAvailableProfile( PlayerNumber pn )
{
if( IsMemoryCardInserted(pn) )
{ {
if( LoadProfileFromMemoryCard(pn) ) if( LoadProfileFromMemoryCard(pn) )
return true; return true;
CString sDir = GetMemCardDir( pn ); CString sDir = GetMemCardDir( pn );
if( !sDir.empty() )
{
CreateProfile( sDir, NEW_MEM_CARD_NAME ); CreateProfile( sDir, NEW_MEM_CARD_NAME );
if( LoadProfileFromMemoryCard(pn) ) if( LoadProfileFromMemoryCard(pn) )
return true; return true;