Files
itgmania212121/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp
T

161 lines
4.5 KiB
C++
Raw Normal View History

#include "global.h"
#include "MemoryCardDriverThreaded_Windows.h"
#include "RageUtil.h"
#include "RageFileManager.h"
#include "RageLog.h"
2004-04-23 04:17:02 +00:00
#include "Profile.h"
#include "PrefsManager.h"
const CString TEMP_MOUNT_POINT_INTERNAL = "@mctemp/";
const CString TEMP_MOUNT_POINT = "@mctemptimeout/";
2004-04-23 04:17:02 +00:00
MemoryCardDriverThreaded_Windows::MemoryCardDriverThreaded_Windows()
{
m_dwLastLogicalDrives = 0;
}
2004-07-17 20:38:59 +00:00
MemoryCardDriverThreaded_Windows::~MemoryCardDriverThreaded_Windows()
{
}
2005-02-05 23:56:23 +00:00
static bool TestReady( const CString &sDrive )
{
TCHAR szVolumeNameBuffer[MAX_PATH];
DWORD dwVolumeSerialNumber;
DWORD dwMaximumComponentLength;
DWORD lpFileSystemFlags;
TCHAR szFileSystemNameBuffer[MAX_PATH];
return !!GetVolumeInformation(
sDrive,
szVolumeNameBuffer,
sizeof(szVolumeNameBuffer),
&dwVolumeSerialNumber,
&dwMaximumComponentLength,
&lpFileSystemFlags,
szFileSystemNameBuffer,
sizeof(szFileSystemNameBuffer) );
}
2005-02-05 23:56:23 +00:00
static bool TestWrite( const CString &sDrive )
{
// Try to write a file.
CString sFile = sDrive + "temp";
FILE* fp = fopen( sFile, "w" );
if( fp == NULL )
return false;
fclose( fp );
remove( sFile );
return true;
}
void MemoryCardDriverThreaded_Windows::Reset()
{
m_dwLastLogicalDrives = 0;
}
bool MemoryCardDriverThreaded_Windows::DoOneUpdate( bool bMount, vector<UsbStorageDevice>& vStorageDevicesOut )
{
DWORD dwNewLogicalDrives = ::GetLogicalDrives();
2004-08-17 05:59:41 +00:00
if( dwNewLogicalDrives == m_dwLastLogicalDrives )
2004-08-09 05:01:24 +00:00
{
// no change from last update
2004-12-07 00:09:47 +00:00
return false;
2004-08-09 05:01:24 +00:00
}
2004-12-07 00:09:47 +00:00
m_dwLastLogicalDrives = dwNewLogicalDrives;
{
2004-08-17 05:59:41 +00:00
vector<UsbStorageDevice> vNewStorageDevices;
const int MAX_DRIVES = 26;
for( int i=2; i<MAX_DRIVES; i++ ) // skip 'a:" and "b:"
2004-05-03 00:34:54 +00:00
{
DWORD mask = (1 << i);
2005-01-27 04:45:20 +00:00
if( !(dwNewLogicalDrives & mask) )
continue; // drive letter is invalid
2005-01-27 04:45:20 +00:00
CString sDrive = ssprintf( "%c:\\", 'a'+i%26 );
2005-01-27 04:45:20 +00:00
LOG->Trace( "Found drive %s", sDrive.c_str() );
2005-01-27 04:45:20 +00:00
if( GetDriveType(sDrive) != DRIVE_REMOVABLE ) // is a removable drive
continue;
2005-01-27 04:45:20 +00:00
if( !TestReady(sDrive) )
continue;
2005-01-27 04:45:20 +00:00
UsbStorageDevice usbd;
usbd.SetOsMountDir( sDrive );
if( TestWrite(sDrive) )
usbd.m_State = UsbStorageDevice::STATE_READY;
else
usbd.SetError( "MountFailed" );
2005-01-27 04:45:20 +00:00
// read name
this->Mount( &usbd );
2005-01-27 04:45:20 +00:00
FILEMAN->Mount( "dir", usbd.sOsMountDir, TEMP_MOUNT_POINT_INTERNAL );
FILEMAN->Mount( "timeout", TEMP_MOUNT_POINT_INTERNAL, TEMP_MOUNT_POINT );
usbd.sName = Profile::FastLoadProfileNameFromMemoryCard( TEMP_MOUNT_POINT );
2005-01-27 04:45:20 +00:00
FILEMAN->Unmount( "timeout", TEMP_MOUNT_POINT_INTERNAL, TEMP_MOUNT_POINT );
FILEMAN->Unmount( "dir", usbd.sOsMountDir, TEMP_MOUNT_POINT_INTERNAL );
vNewStorageDevices.push_back( usbd );
2004-05-03 00:34:54 +00:00
}
2004-08-09 05:01:24 +00:00
CHECKPOINT;
vStorageDevicesOut = vNewStorageDevices;
2004-08-09 05:01:24 +00:00
CHECKPOINT;
}
return true;
}
bool MemoryCardDriverThreaded_Windows::Mount( UsbStorageDevice* pDevice )
{
// nothing to do here...
return true;
}
void MemoryCardDriverThreaded_Windows::Unmount( UsbStorageDevice* pDevice )
{
// nothing to do here...
}
void MemoryCardDriverThreaded_Windows::Flush( UsbStorageDevice* pDevice )
{
// Do we need anything here? I don't lose data if ejecting
// soon after a write. From the activity LED, it looks like
// Windows flushes automatically every ~2 seconds. -Chris
}
/*
2004-05-15 22:30:30 +00:00
* (c) 2003-2004 Chris Danford
* 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.
*/