working on memory card detection for Windows

This commit is contained in:
Chris Danford
2003-12-18 03:59:44 +00:00
parent ca7d4b7456
commit 799a3062ca
6 changed files with 159 additions and 0 deletions
+27
View File
@@ -98,6 +98,10 @@ CPP=cl.exe
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_XBOX" /D "_DEBUG" /YX /FD /G6 /Ztmp /c # ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_XBOX" /D "_DEBUG" /YX /FD /G6 /Ztmp /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "." /I "SDL-1.2.5\include" /I "SDL_image-1.2" /I "plib-1.6.0" /I "SDL_sound-1.0.0" /D "WIN32" /D "_XBOX" /D "_DEBUG" /D "OGG_ONLY" /YX /FD /G6 /Ztmp /c # ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "." /I "SDL-1.2.5\include" /I "SDL_image-1.2" /I "plib-1.6.0" /I "SDL_sound-1.0.0" /D "WIN32" /D "_XBOX" /D "_DEBUG" /D "OGG_ONLY" /YX /FD /G6 /Ztmp /c
# Begin Special Build Tool # Begin Special Build Tool
IntDir=.\Debug
TargetDir=\stepmania\stepmania
TargetName=default
SOURCE="$(InputPath)"
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp \ PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp \
/Fo$(IntDir)\ /Fo$(IntDir)\
PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi ia32.vdi PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi ia32.vdi
@@ -176,6 +180,10 @@ CPP=cl.exe
# ADD CPP /nologo /MT /W3 /GX /O2 /I "." /I "SDL-1.2.5\include" /I "SDL_image-1.2" /I "plib-1.6.0" /I "SDL_sound-1.0.0" /D "WIN32" /D "_XBOX" /D "NDEBUG" /YX"global.h" /FD /c # ADD CPP /nologo /MT /W3 /GX /O2 /I "." /I "SDL-1.2.5\include" /I "SDL_image-1.2" /I "plib-1.6.0" /I "SDL_sound-1.0.0" /D "WIN32" /D "_XBOX" /D "NDEBUG" /YX"global.h" /FD /c
# SUBTRACT CPP /Fr # SUBTRACT CPP /Fr
# Begin Special Build Tool # Begin Special Build Tool
IntDir=.\StepMania___Xbox_Release
TargetDir=\stepmania\stepmania
TargetName=default
SOURCE="$(InputPath)"
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp \ PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp \
/Fo$(IntDir)\ /Fo$(IntDir)\
PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi ia32.vdi PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi ia32.vdi
@@ -2462,6 +2470,25 @@ SOURCE=.\arch\MemoryCard\MemoryCardDriver.h
SOURCE=.\arch\MemoryCard\MemoryCardDriver_Null.h SOURCE=.\arch\MemoryCard\MemoryCardDriver_Null.h
# End Source File # End Source File
# Begin Source File
SOURCE=.\arch\MemoryCard\MemoryCardDriver_Windows.cpp
!IF "$(CFG)" == "StepMania - Win32 Debug"
!ELSEIF "$(CFG)" == "StepMania - Xbox Debug"
!ELSEIF "$(CFG)" == "StepMania - Win32 Release"
!ELSEIF "$(CFG)" == "StepMania - Xbox Release"
!ENDIF
# End Source File
# Begin Source File
SOURCE=.\arch\MemoryCard\MemoryCardDriver_Windows.h
# End Source File
# End Group # End Group
# Begin Source File # Begin Source File
+6
View File
@@ -1001,6 +1001,12 @@ cl /Zl /nologo /c verstub.cpp /Fo"$(IntDir)"\
<File <File
RelativePath="arch\MemoryCard\MemoryCardDriver_Null.h"> RelativePath="arch\MemoryCard\MemoryCardDriver_Null.h">
</File> </File>
<File
RelativePath="arch\MemoryCard\MemoryCardDriver_Windows.cpp">
</File>
<File
RelativePath="arch\MemoryCard\MemoryCardDriver_Windows.h">
</File>
</Filter> </Filter>
</Filter> </Filter>
<Filter <Filter
@@ -0,0 +1,97 @@
#include "global.h"
#include "MemoryCardDriver_Windows.h"
#include "RageUtil.h"
#include <io.h>
#include <fcntl.h>
MemoryCardDriver_Windows::MemoryCardDriver_Windows()
{
m_dwLastLogicalDrives = GetLogicalDrives();
}
MemoryCardDriver_Windows::~MemoryCardDriver_Windows()
{
}
bool MemoryCardDriver_Windows::StorageDevicesChanged()
{
DWORD dwNewLogicalDrives = GetLogicalDrives();
bool bChanged = (dwNewLogicalDrives != m_dwLastLogicalDrives);
m_dwLastLogicalDrives = dwNewLogicalDrives;
return bChanged;
}
void MemoryCardDriver_Windows::GetStorageDevices( vector<UsbStorageDevice>& vDevicesOut )
{
vDevicesOut.clear();
int i = 2; // skip 'a:" and "b:"
const int MAX_DRIVES = sizeof(m_dwLastLogicalDrives)*8;
for( ; i<MAX_DRIVES; i++ )
{
DWORD mask = (1 << i);
if( m_dwLastLogicalDrives & mask ) // drive is valid
{
CString sDrive;
if( i >= 26 )
sDrive = ssprintf( "%c%c:\\", 'a'+(i/26)-1, i%26 );
else
sDrive = ssprintf( "%c:\\", 'a'+i%26 );
if( GetDriveType(sDrive) != DRIVE_REMOVABLE )
continue; // skip
UsbStorageDevice usbd;
usbd.sOsMountDir = sDrive;
vDevicesOut.push_back( usbd );
}
}
}
bool MemoryCardDriver_Windows::MountAndTestWrite( UsbStorageDevice* pDevice )
{
if( !pDevice->sOsMountDir.empty() )
return false;
// TODO: Use RageFileDirect here to detect ready state?
TCHAR szVolumeNameBuffer[MAX_PATH];
DWORD dwVolumeSerialNumber;
DWORD dwMaximumComponentLength;
DWORD lpFileSystemFlags;
TCHAR szFileSystemNameBuffer[MAX_PATH];
BOOL bReady = GetVolumeInformation(
pDevice->sOsMountDir,
szVolumeNameBuffer,
sizeof(szVolumeNameBuffer),
&dwVolumeSerialNumber,
&dwMaximumComponentLength,
&lpFileSystemFlags,
szFileSystemNameBuffer,
sizeof(szFileSystemNameBuffer) );
if( !bReady )
return false;
// Try to write a file.
// TODO: Can we use RageFile for this?
CString sFile = pDevice->sOsMountDir;
sFile += "temp";
int fd = open( sFile, _O_WRONLY|_O_CREAT|_O_TRUNC );
if( fd == -1 )
return false;
close( fd );
remove( sFile );
return true;
}
void MemoryCardDriver_Windows::Unmount( UsbStorageDevice* pDevice )
{
// Do we need anything here? I don't lose data if ejecting
// soon after a write... -Chris
}
/*
* Copyright (c) 2003 by the person(s) listed below. All rights reserved.
* Chris Danford
*/
@@ -0,0 +1,25 @@
#ifndef MEMORY_CARD_DRIVER_WINDOWS_H
#define MEMORY_CARD_DRIVER_WINDOWS_H 1
#include "MemoryCardDriver.h"
#include <windows.h>
class MemoryCardDriver_Windows : public MemoryCardDriver
{
public:
MemoryCardDriver_Windows();
virtual ~MemoryCardDriver_Windows();
virtual bool StorageDevicesChanged();
virtual void GetStorageDevices( vector<UsbStorageDevice>& vStorageDevicesOut );
virtual bool MountAndTestWrite( UsbStorageDevice* pDevice );
virtual void Unmount( UsbStorageDevice* pDevice );
protected:
DWORD m_dwLastLogicalDrives;
};
#endif
/*
* Copyright (c) 2003 by the person(s) listed below. All rights reserved.
* Chris Danford
*/
+2
View File
@@ -172,6 +172,8 @@ MemoryCardDriver *MakeMemoryCardDriver()
#ifdef LINUX #ifdef LINUX
ret = new MemoryCardDriver_Linux; ret = new MemoryCardDriver_Linux;
#elif _WINDOWS
ret = new MemoryCardDriver_Windows;
#endif #endif
if( !ret ) if( !ret )
ret = new MemoryCardDriver_Null; ret = new MemoryCardDriver_Null;
+2
View File
@@ -15,6 +15,8 @@
#include "Lights/LightsDriver_Win32Parallel.h" #include "Lights/LightsDriver_Win32Parallel.h"
#include "MemoryCard/MemoryCardDriver_Windows.h"
#undef SUPPORT_SDL_INPUT #undef SUPPORT_SDL_INPUT
#endif #endif