fix Windows prompts to insert disk if memory card not present
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user