diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriver.h b/stepmania/src/arch/MemoryCard/MemoryCardDriver.h index 92e153b75e..bf025f49f1 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriver.h +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriver.h @@ -11,6 +11,7 @@ struct UsbStorageDevice iBus = -1; iPort = -1; iLevel = -1; + iRefNum = -1; sDevice = ""; sSerial = ""; // be different than a card with no serial sOsMountDir = ""; @@ -27,6 +28,7 @@ struct UsbStorageDevice int iBus; int iPort; int iLevel; + int iRefNum; CString sSerial; CString sDevice; CString sOsMountDir; // WITHOUT trailing slash diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_OSX.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_OSX.cpp new file mode 100644 index 0000000000..5f7cead58c --- /dev/null +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_OSX.cpp @@ -0,0 +1,98 @@ +#include "global.h" +#include "MemoryCardDriverThreaded_OSX.h" +#include "archutils/Darwin/DarwinMCHelpers.h" +#include "Foreach.h" +#include "RageUtil.h" +#include "RageLog.h" + +#include +#include + +void MemoryCardDriverThreaded_OSX::Flush( UsbStorageDevice *pDevice ) +{ + if( pDevice->iRefNum == -1 ) + return; + + ParamBlockRec pb; + + memset( &pb, 0, sizeof(pb) ); + pb.volumeParam.ioNamePtr = NULL; + pb.volumeParam.ioVRefNum = pDevice->iRefNum; + + if( PBFlushVolSync(&pb) != noErr ) + LOG->Warn( "Failed to flush the memory card." ); +} + +void MemoryCardDriverThreaded_OSX::GetUSBStorageDevices( vector& vDevicesOut ) +{ + LOG->Trace( "GetUSBStorageDevices." ); + vector vDevicePaths; + + DarwinMCHelpers::GetRemovableDevicePaths( vDevicePaths ); + FOREACH( CString, vDevicePaths, i ) + { + vDevicesOut.push_back( UsbStorageDevice() ); + + const CString& path = *i; + UsbStorageDevice& usbd = vDevicesOut.back(); + + LOG->Trace( "Found memory card at path: %s.", path.c_str() ); + usbd.SetOsMountDir( path ); + + // Find volume size. + XVolumeParam param; + Str255 name; // A pascal string. + const CString& base = Basename(path); + + memset( ¶m, 0, sizeof(param) ); + name[0] = min( base.length(), size_t(255) ); + strncpy( (char *)&name[1], base, name[0] ); + param.ioNamePtr = name; + param.ioVolIndex = -1; // Use ioNamePtr to find the volume. + + if( PBXGetVolInfoSync(¶m) == noErr ) + { + usbd.iVolumeSizeMB = param.ioVTotalBytes >> 20; + usbd.iRefNum = param.ioVRefNum; + } + else + { + usbd.SetError( "Failed to get volume info." ); + } + } +} + +bool MemoryCardDriverThreaded_OSX::TestWrite( UsbStorageDevice *pDevice ) +{ + if( access(pDevice->sOsMountDir, W_OK) ) + { + pDevice->SetError( "Write test failed." ); + return false; + } + return true; +} + +/* + * (c) 2005 Steve Checkoway + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_OSX.h b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_OSX.h new file mode 100644 index 0000000000..8b6991b812 --- /dev/null +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_OSX.h @@ -0,0 +1,49 @@ +#ifndef MEMORY_CARD_DRIVER_THREADED_OSX +#define MEMORY_CARD_DRIVER_THREADED_OSX + +#include "MemoryCardDriver.h" + +class MemoryCardDriverThreaded_OSX : public MemoryCardDriver +{ +public: + bool Mount( UsbStorageDevice *pDevice ) { return true; } + void Unmount( UsbStorageDevice *pDevice ) { } + void Flush( UsbStorageDevice *pDevice ); + +protected: + void GetUSBStorageDevices( vector& vStorageDevicesOut ); + bool TestWrite( UsbStorageDevice *pDevice ); +}; + +#ifdef ARCH_MEMORY_CARD_DRIVER +#error "More than one MemoryCardDriver selected!" +#endif +#define ARCH_MEMORY_CARD_DRIVER MemoryCardDriverThreaded_OSX + + +#endif + +/* + * (c) 2005 Steve Checkoway + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ diff --git a/stepmania/src/archutils/Darwin/DarwinMCHelpers.h b/stepmania/src/archutils/Darwin/DarwinMCHelpers.h new file mode 100644 index 0000000000..fca7f103a4 --- /dev/null +++ b/stepmania/src/archutils/Darwin/DarwinMCHelpers.h @@ -0,0 +1,34 @@ +#ifndef DARWIN_MC_HELPERS +#define DARWIN_MC_HELPERS + +namespace DarwinMCHelpers +{ + void GetRemovableDevicePaths( vector vDevicePaths ); +} + +#endif + +/* + * (c) 2005 Steve Checkoway + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */