Only rebuild the removable device list when it changes.
This commit is contained in:
@@ -8,6 +8,16 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <Carbon/Carbon.h>
|
#include <Carbon/Carbon.h>
|
||||||
|
|
||||||
|
MemoryCardDriverThreaded_OSX::MemoryCardDriverThreaded_OSX()
|
||||||
|
{
|
||||||
|
DarwinMCHelpers::Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
MemoryCardDriverThreaded_OSX::~MemoryCardDriverThreaded_OSX()
|
||||||
|
{
|
||||||
|
DarwinMCHelpers::Stop();
|
||||||
|
}
|
||||||
|
|
||||||
void MemoryCardDriverThreaded_OSX::Flush( UsbStorageDevice *pDevice )
|
void MemoryCardDriverThreaded_OSX::Flush( UsbStorageDevice *pDevice )
|
||||||
{
|
{
|
||||||
if( pDevice->iRefNum == -1 )
|
if( pDevice->iRefNum == -1 )
|
||||||
@@ -23,6 +33,11 @@ void MemoryCardDriverThreaded_OSX::Flush( UsbStorageDevice *pDevice )
|
|||||||
LOG->Warn( "Failed to flush the memory card." );
|
LOG->Warn( "Failed to flush the memory card." );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MemoryCardDriverThreaded_OSX::USBStorageDevicesChanged()
|
||||||
|
{
|
||||||
|
return DarwinMCHelpers::DevicesChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void MemoryCardDriverThreaded_OSX::GetUSBStorageDevices( vector<UsbStorageDevice>& vDevicesOut )
|
void MemoryCardDriverThreaded_OSX::GetUSBStorageDevices( vector<UsbStorageDevice>& vDevicesOut )
|
||||||
{
|
{
|
||||||
LOG->Trace( "GetUSBStorageDevices." );
|
LOG->Trace( "GetUSBStorageDevices." );
|
||||||
|
|||||||
@@ -6,11 +6,14 @@
|
|||||||
class MemoryCardDriverThreaded_OSX : public MemoryCardDriver
|
class MemoryCardDriverThreaded_OSX : public MemoryCardDriver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
MemoryCardDriverThreaded_OSX();
|
||||||
|
~MemoryCardDriverThreaded_OSX();
|
||||||
bool Mount( UsbStorageDevice *pDevice ) { return true; }
|
bool Mount( UsbStorageDevice *pDevice ) { return true; }
|
||||||
void Unmount( UsbStorageDevice *pDevice ) { }
|
void Unmount( UsbStorageDevice *pDevice ) { }
|
||||||
void Flush( UsbStorageDevice *pDevice );
|
void Flush( UsbStorageDevice *pDevice );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool USBStorageDevicesChanged();
|
||||||
void GetUSBStorageDevices( vector<UsbStorageDevice>& vStorageDevicesOut );
|
void GetUSBStorageDevices( vector<UsbStorageDevice>& vStorageDevicesOut );
|
||||||
bool TestWrite( UsbStorageDevice *pDevice );
|
bool TestWrite( UsbStorageDevice *pDevice );
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,10 @@
|
|||||||
|
|
||||||
namespace DarwinMCHelpers
|
namespace DarwinMCHelpers
|
||||||
{
|
{
|
||||||
void GetRemovableDevicePaths( vector<CString> vDevicePaths );
|
void Start();
|
||||||
|
void Stop();
|
||||||
|
bool DevicesChanged();
|
||||||
|
void GetRemovableDevicePaths( vector<CString>& vDevicePaths );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,19 +1,72 @@
|
|||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "DarwinMCHelpers.h"
|
#include "DarwinMCHelpers.h"
|
||||||
|
#include "RageThreads.h"
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
void DarwinMCHelpers::GetRemovableDevicePaths( vector<CString> vDevicePaths )
|
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];
|
||||||
|
|
||||||
|
[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];
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
|
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
|
||||||
NSArray *paths = [ws mountedRemovableMedia];
|
NSArray *paths = [ws mountedRemovableMedia];
|
||||||
NSEnumerator *i = [paths objectEnumerator];
|
NSEnumerator *i = [paths objectEnumerator];
|
||||||
NSString *path;
|
NSString *path;
|
||||||
|
|
||||||
|
vDevicePaths.clear();
|
||||||
while( (path = [i nextObject]) )
|
while( (path = [i nextObject]) )
|
||||||
vDevicePaths.push_back( [path UTF8String] );
|
vDevicePaths.push_back( [path UTF8String] );
|
||||||
[pool release];
|
[pool release];
|
||||||
|
g_bChange = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user