From 799a3062ca57a097e1c9e75c1185fa93857e47c8 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Thu, 18 Dec 2003 03:59:44 +0000 Subject: [PATCH] working on memory card detection for Windows --- stepmania/src/StepMania.dsp | 27 ++++++ stepmania/src/StepMania.vcproj | 6 ++ .../MemoryCard/MemoryCardDriver_Windows.cpp | 97 +++++++++++++++++++ .../MemoryCard/MemoryCardDriver_Windows.h | 25 +++++ stepmania/src/arch/arch.cpp | 2 + stepmania/src/arch/arch_Win32.h | 2 + 6 files changed, 159 insertions(+) create mode 100644 stepmania/src/arch/MemoryCard/MemoryCardDriver_Windows.cpp create mode 100644 stepmania/src/arch/MemoryCard/MemoryCardDriver_Windows.h diff --git a/stepmania/src/StepMania.dsp b/stepmania/src/StepMania.dsp index 562bcbd3f2..530b7adcd7 100644 --- a/stepmania/src/StepMania.dsp +++ b/stepmania/src/StepMania.dsp @@ -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 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 +IntDir=.\Debug +TargetDir=\stepmania\stepmania +TargetName=default +SOURCE="$(InputPath)" PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp \ /Fo$(IntDir)\ 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 # SUBTRACT CPP /Fr # 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 \ /Fo$(IntDir)\ 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 # 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 # Begin Source File diff --git a/stepmania/src/StepMania.vcproj b/stepmania/src/StepMania.vcproj index a79b8d3ab8..dfe5afb974 100644 --- a/stepmania/src/StepMania.vcproj +++ b/stepmania/src/StepMania.vcproj @@ -1001,6 +1001,12 @@ cl /Zl /nologo /c verstub.cpp /Fo"$(IntDir)"\ + + + + +#include + +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& vDevicesOut ) +{ + vDevicesOut.clear(); + + int i = 2; // skip 'a:" and "b:" + const int MAX_DRIVES = sizeof(m_dwLastLogicalDrives)*8; + for( ; 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 + */ diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriver_Windows.h b/stepmania/src/arch/MemoryCard/MemoryCardDriver_Windows.h new file mode 100644 index 0000000000..17c017611f --- /dev/null +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriver_Windows.h @@ -0,0 +1,25 @@ +#ifndef MEMORY_CARD_DRIVER_WINDOWS_H +#define MEMORY_CARD_DRIVER_WINDOWS_H 1 + +#include "MemoryCardDriver.h" +#include + +class MemoryCardDriver_Windows : public MemoryCardDriver +{ +public: + MemoryCardDriver_Windows(); + virtual ~MemoryCardDriver_Windows(); + virtual bool StorageDevicesChanged(); + virtual void GetStorageDevices( vector& 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 + */ diff --git a/stepmania/src/arch/arch.cpp b/stepmania/src/arch/arch.cpp index a8e7183a71..52b3f74caa 100644 --- a/stepmania/src/arch/arch.cpp +++ b/stepmania/src/arch/arch.cpp @@ -172,6 +172,8 @@ MemoryCardDriver *MakeMemoryCardDriver() #ifdef LINUX ret = new MemoryCardDriver_Linux; +#elif _WINDOWS + ret = new MemoryCardDriver_Windows; #endif if( !ret ) ret = new MemoryCardDriver_Null; diff --git a/stepmania/src/arch/arch_Win32.h b/stepmania/src/arch/arch_Win32.h index 06825dab34..bd131b5737 100644 --- a/stepmania/src/arch/arch_Win32.h +++ b/stepmania/src/arch/arch_Win32.h @@ -15,6 +15,8 @@ #include "Lights/LightsDriver_Win32Parallel.h" +#include "MemoryCard/MemoryCardDriver_Windows.h" + #undef SUPPORT_SDL_INPUT #endif