Do memory card stuff (more) correctly.

This commit is contained in:
Steve Checkoway
2006-01-08 00:23:33 +00:00
parent f842f51a22
commit 3608694a18
5 changed files with 219 additions and 182 deletions
@@ -793,8 +793,6 @@
AACF47B20949A24F0011B9F3 /* Selector_MemoryCardDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = AACF47B10949A24F0011B9F3 /* Selector_MemoryCardDriver.h */; };
AACF47B9094A497F0011B9F3 /* MemoryCardDriverThreaded_OSX.h in Headers */ = {isa = PBXBuildFile; fileRef = AACF47B7094A497F0011B9F3 /* MemoryCardDriverThreaded_OSX.h */; };
AACF47BA094A497F0011B9F3 /* MemoryCardDriverThreaded_OSX.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AACF47B8094A497F0011B9F3 /* MemoryCardDriverThreaded_OSX.cpp */; };
AACF47EF094A6E290011B9F3 /* DarwinMCHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = AACF47ED094A6E290011B9F3 /* DarwinMCHelpers.h */; };
AACF47F0094A6E290011B9F3 /* DarwinMCHelpers.mm in Sources */ = {isa = PBXBuildFile; fileRef = AACF47EE094A6E290011B9F3 /* DarwinMCHelpers.mm */; };
AACFBE2808E7D793005087FC /* ActorSound.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AACFBE2608E7D793005087FC /* ActorSound.cpp */; };
AACFBE2908E7D793005087FC /* ActorSound.h in Headers */ = {isa = PBXBuildFile; fileRef = AACFBE2708E7D793005087FC /* ActorSound.h */; };
AACFBE3A08E7D832005087FC /* InputEventPlus.h in Headers */ = {isa = PBXBuildFile; fileRef = AACFBE3908E7D832005087FC /* InputEventPlus.h */; };
@@ -824,7 +822,6 @@
AADBA563062007BA005D4FC2 /* arch_platform.h in Headers */ = {isa = PBXBuildFile; fileRef = AADBA562062007BA005D4FC2 /* arch_platform.h */; };
AADD1CC5095C233F0088C9DF /* LocalizedString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AADD1CC2095C233E0088C9DF /* LocalizedString.cpp */; };
AADD1CC6095C233F0088C9DF /* LocalizedString.h in Headers */ = {isa = PBXBuildFile; fileRef = AADD1CC3095C233F0088C9DF /* LocalizedString.h */; };
AADD1CC7095C233F0088C9DF /* LocalizedStringLua.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AADD1CC4095C233F0088C9DF /* LocalizedStringLua.cpp */; };
AAE66F740657634D002E3AD9 /* CryptMD5.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AAE66F650657634D002E3AD9 /* CryptMD5.cpp */; };
AAE66F750657634D002E3AD9 /* CryptMD5.h in Headers */ = {isa = PBXBuildFile; fileRef = AAE66F660657634D002E3AD9 /* CryptMD5.h */; };
AAE66F790657634D002E3AD9 /* CryptRand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AAE66F6A0657634D002E3AD9 /* CryptRand.cpp */; };
@@ -879,7 +876,6 @@
AAFAB5CE08890B5200767BF7 /* GameLoop.h in Headers */ = {isa = PBXBuildFile; fileRef = AAFAB5CC08890B5200767BF7 /* GameLoop.h */; };
AAFBEED1094D7FCB000029DE /* SpecialFiles.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AAFBEECF094D7FCB000029DE /* SpecialFiles.cpp */; };
AAFBEED2094D7FCB000029DE /* SpecialFiles.h in Headers */ = {isa = PBXBuildFile; fileRef = AAFBEED0094D7FCB000029DE /* SpecialFiles.h */; };
AAFBEEE2094D8042000029DE /* RageUtilLua.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AAFBEEE1094D8042000029DE /* RageUtilLua.cpp */; };
AAFBEEEB094D807E000029DE /* ScreenOptionsManageEditSteps.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AAFBEEE5094D807E000029DE /* ScreenOptionsManageEditSteps.cpp */; };
AAFBEEEC094D807E000029DE /* ScreenOptionsManageEditSteps.h in Headers */ = {isa = PBXBuildFile; fileRef = AAFBEEE6094D807E000029DE /* ScreenOptionsManageEditSteps.h */; };
AAFBEEED094D807E000029DE /* ScreenOptionsMemoryCard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AAFBEEE7094D807E000029DE /* ScreenOptionsMemoryCard.cpp */; };
@@ -1754,8 +1750,6 @@
AACF47B10949A24F0011B9F3 /* Selector_MemoryCardDriver.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Selector_MemoryCardDriver.h; sourceTree = "<group>"; };
AACF47B7094A497F0011B9F3 /* MemoryCardDriverThreaded_OSX.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryCardDriverThreaded_OSX.h; sourceTree = "<group>"; };
AACF47B8094A497F0011B9F3 /* MemoryCardDriverThreaded_OSX.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MemoryCardDriverThreaded_OSX.cpp; sourceTree = "<group>"; };
AACF47ED094A6E290011B9F3 /* DarwinMCHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DarwinMCHelpers.h; sourceTree = "<group>"; };
AACF47EE094A6E290011B9F3 /* DarwinMCHelpers.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DarwinMCHelpers.mm; sourceTree = "<group>"; };
AACFBE2608E7D793005087FC /* ActorSound.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ActorSound.cpp; path = ../src/ActorSound.cpp; sourceTree = "<group>"; };
AACFBE2708E7D793005087FC /* ActorSound.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ActorSound.h; path = ../src/ActorSound.h; sourceTree = "<group>"; };
AACFBE3908E7D832005087FC /* InputEventPlus.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = InputEventPlus.h; path = ../src/InputEventPlus.h; sourceTree = "<group>"; };
@@ -1808,7 +1802,6 @@
AADBE369053DA38C00D02EE9 /* Bookkeeper.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp; fileEncoding = 30; name = Bookkeeper.h; path = ../src/Bookkeeper.h; sourceTree = "<group>"; tabWidth = 4; usesTabs = 1; };
AADD1CC2095C233E0088C9DF /* LocalizedString.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = LocalizedString.cpp; path = ../src/LocalizedString.cpp; sourceTree = "<group>"; };
AADD1CC3095C233F0088C9DF /* LocalizedString.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = LocalizedString.h; path = ../src/LocalizedString.h; sourceTree = "<group>"; };
AADD1CC4095C233F0088C9DF /* LocalizedStringLua.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = LocalizedStringLua.cpp; path = ../src/LocalizedStringLua.cpp; sourceTree = "<group>"; };
AAE443EB04B0F9F600D02EE9 /* CombinedLifeMeterTug.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp; fileEncoding = 30; indentWidth = 4; name = CombinedLifeMeterTug.cpp; path = ../src/CombinedLifeMeterTug.cpp; sourceTree = "<group>"; tabWidth = 4; usesTabs = 1; };
AAE443EC04B0F9F600D02EE9 /* CombinedLifeMeterTug.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp; fileEncoding = 30; indentWidth = 4; name = CombinedLifeMeterTug.h; path = ../src/CombinedLifeMeterTug.h; sourceTree = "<group>"; tabWidth = 4; usesTabs = 1; };
AAE443F304B0FEB700D02EE9 /* ScoreKeeperRave.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp; fileEncoding = 30; indentWidth = 4; name = ScoreKeeperRave.cpp; path = ../src/ScoreKeeperRave.cpp; sourceTree = "<group>"; tabWidth = 4; usesTabs = 1; };
@@ -1895,7 +1888,6 @@
AAFAB5CC08890B5200767BF7 /* GameLoop.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = GameLoop.h; sourceTree = "<group>"; };
AAFBEECF094D7FCB000029DE /* SpecialFiles.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SpecialFiles.cpp; sourceTree = "<group>"; };
AAFBEED0094D7FCB000029DE /* SpecialFiles.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SpecialFiles.h; sourceTree = "<group>"; };
AAFBEEE1094D8042000029DE /* RageUtilLua.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = RageUtilLua.cpp; path = ../src/RageUtilLua.cpp; sourceTree = "<group>"; };
AAFBEEE5094D807E000029DE /* ScreenOptionsManageEditSteps.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ScreenOptionsManageEditSteps.cpp; path = ../src/ScreenOptionsManageEditSteps.cpp; sourceTree = "<group>"; };
AAFBEEE6094D807E000029DE /* ScreenOptionsManageEditSteps.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ScreenOptionsManageEditSteps.h; path = ../src/ScreenOptionsManageEditSteps.h; sourceTree = "<group>"; };
AAFBEEE7094D807E000029DE /* ScreenOptionsMemoryCard.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ScreenOptionsMemoryCard.cpp; path = ../src/ScreenOptionsMemoryCard.cpp; sourceTree = "<group>"; };
@@ -2591,7 +2583,6 @@
AAF580A804B3E2DC00D02EE9 /* RageUtil_FileDB.h */,
AACA592D07B5E23400763545 /* RageUtil_WorkerThread.cpp */,
AACA592E07B5E23400763545 /* RageUtil_WorkerThread.h */,
AAFBEEE1094D8042000029DE /* RageUtilLua.cpp */,
AA6EFDC004770AEA005F316C /* SDL_utils.cpp */,
AA6EFDC104770AEA005F316C /* SDL_utils.h */,
);
@@ -2662,7 +2653,6 @@
AA2FB638091212AF000FD574 /* LifeMeter.cpp */,
AADD1CC2095C233E0088C9DF /* LocalizedString.cpp */,
AADD1CC3095C233F0088C9DF /* LocalizedString.h */,
AADD1CC4095C233F0088C9DF /* LocalizedStringLua.cpp */,
AACFBE6108E7DBA8005087FC /* LuaExpressionTransform.cpp */,
AACFBE6208E7DBA8005087FC /* LuaExpressionTransform.h */,
AAEA090605E23DF900D38622 /* LuaFunctions.h */,
@@ -3123,8 +3113,6 @@
AA4B5CC40573AD81005FB5DB /* wchar.cpp */,
AA2FB62909120FC5000FD574 /* PreferredLanguage.m */,
AAA130C60914ACB600497146 /* WindowHelper.m */,
AACF47ED094A6E290011B9F3 /* DarwinMCHelpers.h */,
AACF47EE094A6E290011B9F3 /* DarwinMCHelpers.mm */,
);
path = Darwin;
sourceTree = "<group>";
@@ -3619,7 +3607,6 @@
AAA372D70909934500141131 /* MovieTexture_Theora.h in Headers */,
AACF47B20949A24F0011B9F3 /* Selector_MemoryCardDriver.h in Headers */,
AACF47B9094A497F0011B9F3 /* MemoryCardDriverThreaded_OSX.h in Headers */,
AACF47EF094A6E290011B9F3 /* DarwinMCHelpers.h in Headers */,
AAFBEED2094D7FCB000029DE /* SpecialFiles.h in Headers */,
AAFBEEEC094D807E000029DE /* ScreenOptionsManageEditSteps.h in Headers */,
AAFBEEEE094D807E000029DE /* ScreenOptionsMemoryCard.h in Headers */,
@@ -4185,9 +4172,7 @@
AA2FB639091212B0000FD574 /* LifeMeter.cpp in Sources */,
AAA130C70914ACB600497146 /* WindowHelper.m in Sources */,
AACF47BA094A497F0011B9F3 /* MemoryCardDriverThreaded_OSX.cpp in Sources */,
AACF47F0094A6E290011B9F3 /* DarwinMCHelpers.mm in Sources */,
AAFBEED1094D7FCB000029DE /* SpecialFiles.cpp in Sources */,
AAFBEEE2094D8042000029DE /* RageUtilLua.cpp in Sources */,
AAFBEEEB094D807E000029DE /* ScreenOptionsManageEditSteps.cpp in Sources */,
AAFBEEED094D807E000029DE /* ScreenOptionsMemoryCard.cpp in Sources */,
AAFBEEEF094D807E000029DE /* ScreenServiceAction.cpp in Sources */,
@@ -4195,7 +4180,6 @@
AA0732900954381800F396C5 /* XmlFileUtil.cpp in Sources */,
AAD5219C095513DA00073D86 /* XmlFile.cpp in Sources */,
AADD1CC5095C233F0088C9DF /* LocalizedString.cpp in Sources */,
AADD1CC7095C233F0088C9DF /* LocalizedStringLua.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1,21 +1,46 @@
#include "global.h"
#include "MemoryCardDriverThreaded_OSX.h"
#include "archutils/Darwin/DarwinMCHelpers.h"
#include "Foreach.h"
#include "RageUtil.h"
#include "RageLog.h"
#include <unistd.h>
#include <Carbon/Carbon.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/storage/IOMedia.h>
#include <IOKit/usb/USBSpec.h>
#include <IOKit/usb/IOUSBLib.h>
#include <sys/param.h>
#include <sys/ucred.h>
#include <sys/mount.h>
#include <paths.h>
#include <unistd.h>
MemoryCardDriverThreaded_OSX::MemoryCardDriverThreaded_OSX()
OSStatus MemoryCardDriverThreaded_OSX::VolumeChanged( EventHandlerCallRef ref, EventRef event, void *p )
{
DarwinMCHelpers::Start();
MemoryCardDriverThreaded_OSX *This = (MemoryCardDriverThreaded_OSX *)p;
LockMut( This->m_ChangedLock );
This->m_bChanged = true;
return eventNotHandledErr; // let others do something
}
MemoryCardDriverThreaded_OSX::MemoryCardDriverThreaded_OSX() : m_ChangedLock( "MC changed lock" )
{
m_bChanged = true;
m_HandlerUPP = NewEventHandlerUPP( VolumeChanged );
EventTypeSpec types[] = { { kEventClassVolume, kEventVolumeMounted },
{ kEventClassVolume, kEventVolumeUnmounted } };
UInt32 numTypes = sizeof(types)/sizeof(types[0]);
OSStatus ret = InstallApplicationEventHandler( m_HandlerUPP, numTypes, types, this, &m_Handler );
ASSERT( ret == noErr );
}
MemoryCardDriverThreaded_OSX::~MemoryCardDriverThreaded_OSX()
{
DarwinMCHelpers::Stop();
RemoveEventHandler( m_Handler );
DisposeEventHandlerUPP( m_HandlerUPP );
}
void MemoryCardDriverThreaded_OSX::Unmount( UsbStorageDevice *pDevice )
@@ -35,46 +60,186 @@ void MemoryCardDriverThreaded_OSX::Unmount( UsbStorageDevice *pDevice )
bool MemoryCardDriverThreaded_OSX::USBStorageDevicesChanged()
{
return DarwinMCHelpers::DevicesChanged();
LockMut( m_ChangedLock );
return m_bChanged;
}
static int GetIntProperty( io_registry_entry_t entry, CFStringRef key )
{
CFTypeRef t = IORegistryEntryCreateCFProperty( entry, key, NULL, 0 );
if( !t )
return -1;
if( CFGetTypeID( t ) != CFNumberGetTypeID() )
{
CFRelease( t );
return -1;
}
int num;
if( !CFNumberGetValue(CFNumberRef(t), kCFNumberIntType, &num) )
num = -1;
CFRelease( t );
return num;
}
static CString GetStringProperty( io_registry_entry_t entry, CFStringRef key )
{
CFTypeRef t = IORegistryEntryCreateCFProperty( entry, key, NULL, 0 );
if( !t )
return CString();
if( CFGetTypeID( t ) != CFStringGetTypeID() )
{
CFRelease( t );
return CString();
}
CFStringRef s = CFStringRef( t );
CString ret;
const size_t len = CFStringGetMaximumSizeForEncoding( CFStringGetLength(s), kCFStringEncodingUTF8 );
char *buf = new char[len + 1];
if( CFStringGetCString( s, buf, len + 1, kCFStringEncodingUTF8 ) )
ret = buf;
delete[] buf;
CFRelease( t );
return ret;
}
void MemoryCardDriverThreaded_OSX::GetUSBStorageDevices( vector<UsbStorageDevice>& vDevicesOut )
{
LOG->Trace( "GetUSBStorageDevices." );
vector<CString> vDevicePaths;
LockMut( m_ChangedLock );
// First, get all device paths
struct statfs *fs;
int num = getfsstat( NULL, 0, MNT_NOWAIT );
DarwinMCHelpers::GetRemovableDevicePaths( vDevicePaths );
FOREACH( CString, vDevicePaths, i )
fs = new struct statfs[num];
num = getfsstat( fs, num * sizeof(struct statfs), MNT_NOWAIT );
ASSERT( num != -1 );
for( int i = 0; i < num; ++i )
{
vDevicesOut.push_back( UsbStorageDevice() );
if( strncmp(fs[i].f_mntfromname, _PATH_DEV, strlen(_PATH_DEV)) )
continue;
const CString& path = *i;
UsbStorageDevice& usbd = vDevicesOut.back();
const CString& sDevicePath = fs[i].f_mntfromname;
const CString& sDisk = Basename( sDevicePath ); // disk#[[s#] ...]
LOG->Trace( "Found memory card at path: %s.", path.c_str() );
usbd.SetOsMountDir( path );
// Now that we have the disk name, look up the IOServices associated with it.
CFMutableDictionaryRef dict;
// Find volume size.
XVolumeParam param;
Str255 name; // A pascal string.
const CString& base = Basename(path);
if( !(dict = IOBSDNameMatching(kIOMasterPortDefault, 0, sDisk)) )
continue;
memset( &param, 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.
// Look for certain properties: Leaf, Ejectable, Writable.
CFDictionarySetValue( dict, CFSTR(kIOMediaLeafKey), kCFBooleanTrue );
CFDictionarySetValue( dict, CFSTR(kIOMediaEjectableKey), kCFBooleanTrue );
CFDictionarySetValue( dict, CFSTR(kIOMediaWritableKey), kCFBooleanTrue );
if( PBXGetVolInfoSync(&param) == noErr )
// Get the matching iterator. As always, this consumes a reference to dict.
io_iterator_t iter;
kern_return_t ret = IOServiceGetMatchingServices( kIOMasterPortDefault, dict, &iter );
if( ret != KERN_SUCCESS || iter == 0 )
continue;
// I'm not quite sure what it means to have two services with this device.
// Iterate over them all. If one contains what we want, stop.
io_registry_entry_t entry; // This is the same as an io_object_t.
while( (entry = IOIteratorNext(iter)) )
{
usbd.iVolumeSizeMB = param.ioVTotalBytes >> 20;
usbd.iRefNum = param.ioVRefNum;
}
else
{
usbd.SetError( "Failed to get volume info." );
// Get the path in the IOService plane.
io_string_t path; // Some c string.
ret = IORegistryEntryGetPath( entry, kIOServicePlane, path );
IOObjectRelease( entry );
if( ret != KERN_SUCCESS )
{
// XXX maybe I should just walk back myself.
LOG->Warn( "Device \"%s\" (%s) has an IORegistry path that is too long.",
fs[i].f_mntfromname, fs[i].f_mntonname );
continue;
}
const CString& sRegistryPath = path;
CString::size_type pos = sRegistryPath.rfind( "/IOUSBMassStorageClass" );
if( pos == CString::npos )
continue; // Probably not a USB device.
// The path does not start with / so pos - 1 >= 0.
pos = sRegistryPath.rfind( '/', pos - 1 );
if( pos == CString::npos )
continue; // Something is horribly wrong at this point.
path[pos] = '\0';
io_registry_entry_t device = IORegistryEntryFromPath( kIOMasterPortDefault, path );
// MACH_PORT_NULL?
if( device == MACH_PORT_NULL )
{
LOG->Warn( "Couldn't create IORegistry entry from: %s", path );
continue;
}
// At this point, it is pretty safe to say that we've found a USB device.
vDevicesOut.push_back( UsbStorageDevice() );
UsbStorageDevice& usbd = vDevicesOut.back();
LOG->Trace( "Found memory card at path: %s.", fs[i].f_mntonname );
usbd.SetOsMountDir( fs[i].f_mntonname );
// Find volume reference number for flushing.
XVolumeParam param;
Str255 name; // A pascal string.
const CString& base = Basename( fs[i].f_mntonname );
memset( &param, 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.
/* At this point, we have 3 methods available to get the volume size.
* we can use:
* param.ioVTotalBytes,
* IORegistryEntryCreateCFProperty( entry, CFSTR(kIOMediaSizeKey), NULL, 0 ),
* or fs[i].f_blocks * fs[i].f_bsize, however, we released entry already. */
if( PBXGetVolInfoSync(&param) == noErr )
{
usbd.iRefNum = param.ioVRefNum;
usbd.iVolumeSizeMB = param.ioVTotalBytes >> 20;
}
else
{
/* We could fall back on one of the other methods but if we can't
* get the volume info then something is wrong so give up. */
usbd.SetError( "Failed to get volume info." );
IOObjectRelease( device );
break;
}
// Now we can get some more information from the registry tree.
usbd.iBus = GetIntProperty( device, CFSTR("USB Address") );
usbd.iPort = GetIntProperty( device, CFSTR("PortNum") );
// usbd.iLevel ?
usbd.sSerial = GetStringProperty( device, CFSTR("USB Serial Number") );
usbd.sDevice = fs[i].f_mntfromname;
usbd.idVendor = GetIntProperty( device, CFSTR(kUSBVendorID) );
usbd.idProduct = GetIntProperty( device, CFSTR(kUSBProductID) );
usbd.sVendor = GetStringProperty( device, CFSTR("USB Vendor Name") );
usbd.sProduct = GetStringProperty( device, CFSTR("USB Product Name") );
IOObjectRelease( device );
break; // We found what we wanted
}
IOObjectRelease( iter );
}
m_bChanged = false;
}
bool MemoryCardDriverThreaded_OSX::TestWrite( UsbStorageDevice *pDevice )
@@ -88,7 +253,7 @@ bool MemoryCardDriverThreaded_OSX::TestWrite( UsbStorageDevice *pDevice )
}
/*
* (c) 2005 Steve Checkoway
* (c) 2005-2006 Steve Checkoway
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -2,6 +2,17 @@
#define MEMORY_CARD_DRIVER_THREADED_OSX
#include "MemoryCardDriver.h"
#include "RageThreads.h"
// I can't include <Carbon/Carbon.h> because Style conflicts.
typedef struct OpaqueEventHandlerRef *EventHandlerRef;
typedef struct OpaqueEventHandlerCallRef *EventHandlerCallRef;
typedef struct OpaqueEventRef *EventRef;
typedef long int OSStatus;
typedef OSStatus (*EventHandlerProcPtr)( EventHandlerCallRef inHandlerCallRef,
EventRef inEvent, void * inUserData );
typedef EventHandlerProcPtr EventHandlerUPP;
class MemoryCardDriverThreaded_OSX : public MemoryCardDriver
{
@@ -15,10 +26,18 @@ protected:
bool USBStorageDevicesChanged();
void GetUSBStorageDevices( vector<UsbStorageDevice>& vStorageDevicesOut );
bool TestWrite( UsbStorageDevice *pDevice );
private:
static OSStatus VolumeChanged( EventHandlerCallRef ref, EventRef event, void *p );
bool m_bChanged;
RageMutex m_ChangedLock;
EventHandlerUPP m_HandlerUPP;
EventHandlerRef m_Handler;
};
#ifdef ARCH_MEMORY_CARD_DRIVER
#error "More than one MemoryCardDriver selected!"
#error "More than one MemoryCardDriver selected."
#endif
#define ARCH_MEMORY_CARD_DRIVER MemoryCardDriverThreaded_OSX
@@ -26,7 +45,7 @@ protected:
#endif
/*
* (c) 2005 Steve Checkoway
* (c) 2005-2006 Steve Checkoway
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -1,37 +0,0 @@
#ifndef DARWIN_MC_HELPERS
#define DARWIN_MC_HELPERS
namespace DarwinMCHelpers
{
void Start();
void Stop();
bool DevicesChanged();
void GetRemovableDevicePaths( vector<CString>& 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.
*/
@@ -1,94 +0,0 @@
#include "global.h"
#include "DarwinMCHelpers.h"
#include "RageThreads.h"
#import <Cocoa/Cocoa.h>
static bool g_bChange;
static RageMutex g_Lock( "USB devices changed lock" );
@interface MemoryCardHelper : NSObject
- (void) devicesChanged:(NSNotification *)notification;
@end
@implementation MemoryCardHelper
- (void) devicesChanged:(NSNotification *)notification
{
LockMut(g_Lock);
g_bChange = true;
}
@end
static MemoryCardHelper *g_MCH = nil;
void DarwinMCHelpers::Start()
{
ASSERT( g_MCH == nil );
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSNotificationCenter *nc = [[NSWorkspace sharedWorkspace] notificationCenter];
g_bChange = true;
g_MCH = [[MemoryCardHelper alloc] init];
[nc addObserver:g_MCH selector:@selector(devicesChanged:)
name:@"NSWorkspaceDidMountNotification" object:nil];
[nc addObserver:g_MCH selector:@selector(devicesChanged:)
name:@"NSWorkspaceDidUnmountNotification" object:nil];
[pool release];
}
void DarwinMCHelpers::Stop()
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSNotificationCenter *nc = [[NSWorkspace sharedWorkspace] notificationCenter];
[nc removeObserver:g_MCH];
[g_MCH release];
g_MCH = nil;
[pool release];
}
bool DarwinMCHelpers::DevicesChanged()
{
LockMut( g_Lock );
return g_bChange;
}
void DarwinMCHelpers::GetRemovableDevicePaths( vector<CString>& vDevicePaths )
{
LockMut( g_Lock );
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
NSArray *paths = [ws mountedRemovableMedia];
NSEnumerator *i = [paths objectEnumerator];
NSString *path;
while( (path = [i nextObject]) )
vDevicePaths.push_back( [path UTF8String] );
[pool release];
g_bChange = false;
}
/*
* (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.
*/