Commit 35e8ad40 authored by Colin Delacroix's avatar Colin Delacroix Committed by Felix Paul Kühne

macosx: fixed a thread-safety issue in the open panel code

VLC crashed when mounting multiple volumes at once
parent b0ea0942
...@@ -871,62 +871,53 @@ static VLCOpen *_o_sharedMainInstance = nil; ...@@ -871,62 +871,53 @@ static VLCOpen *_o_sharedMainInstance = nil;
return returnValue; return returnValue;
} }
- (void)showOpticalAtIndex: (NSNumber *)n_index - (void)showOpticalAtPath: (NSString *)o_opticalDevicePath
{ {
NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
if (!o_opticalDevices) char *diskType = [self getVolumeTypeFromMountPath:o_opticalDevicePath];
return;
if ([o_opticalDevices count] == 0)
return;
unsigned int index = [n_index intValue];
id o_currentOpticalDevice = [o_opticalDevices objectAtIndex: index];
char *diskType = [self getVolumeTypeFromMountPath:o_currentOpticalDevice];
if (diskType == kVLCMediaDVD || diskType == kVLCMediaVideoTSFolder) if (diskType == kVLCMediaDVD || diskType == kVLCMediaVideoTSFolder)
{ {
[o_disc_dvd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_currentOpticalDevice]]; [o_disc_dvd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_opticalDevicePath]];
[o_disc_dvdwomenus_lbl setStringValue: [o_disc_dvd_lbl stringValue]]; [o_disc_dvdwomenus_lbl setStringValue: [o_disc_dvd_lbl stringValue]];
NSString *pathToOpen; NSString *pathToOpen;
if (diskType == kVLCMediaVideoTSFolder) if (diskType == kVLCMediaVideoTSFolder)
pathToOpen = o_currentOpticalDevice; pathToOpen = o_opticalDevicePath;
else else
pathToOpen = [self getBSDNodeFromMountPath: o_currentOpticalDevice]; pathToOpen = [self getBSDNodeFromMountPath: o_opticalDevicePath];
if (!b_nodvdmenus) { if (!b_nodvdmenus) {
[self setMRL: [NSString stringWithFormat: @"dvdnav://%@", pathToOpen]]; [self setMRL: [NSString stringWithFormat: @"dvdnav://%@", pathToOpen]];
[self showOpticalMediaView: o_disc_dvd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_currentOpticalDevice]]; [self showOpticalMediaView: o_disc_dvd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
} else { } else {
[self setMRL: [NSString stringWithFormat: @"dvdread://%@#%i:%i-", pathToOpen, [o_disc_dvdwomenus_title intValue], [o_disc_dvdwomenus_chapter intValue]]]; [self setMRL: [NSString stringWithFormat: @"dvdread://%@#%i:%i-", pathToOpen, [o_disc_dvdwomenus_title intValue], [o_disc_dvdwomenus_chapter intValue]]];
[self showOpticalMediaView: o_disc_dvdwomenus_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_currentOpticalDevice]]; [self showOpticalMediaView: o_disc_dvdwomenus_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
} }
} }
else if (diskType == kVLCMediaAudioCD) else if (diskType == kVLCMediaAudioCD)
{ {
[o_disc_audiocd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_currentOpticalDevice]]; [o_disc_audiocd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
[o_disc_audiocd_trackcount_lbl setStringValue: [NSString stringWithFormat:_NS("%i tracks"), [[[NSFileManager defaultManager] subpathsOfDirectoryAtPath: o_currentOpticalDevice error:NULL] count] - 1]]; // minus .TOC.plist [o_disc_audiocd_trackcount_lbl setStringValue: [NSString stringWithFormat:_NS("%i tracks"), [[[NSFileManager defaultManager] subpathsOfDirectoryAtPath: o_opticalDevicePath error:NULL] count] - 1]]; // minus .TOC.plist
[self showOpticalMediaView: o_disc_audiocd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_currentOpticalDevice]]; [self showOpticalMediaView: o_disc_audiocd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
[self setMRL: [NSString stringWithFormat: @"cdda://%@", [self getBSDNodeFromMountPath: o_currentOpticalDevice]]]; [self setMRL: [NSString stringWithFormat: @"cdda://%@", [self getBSDNodeFromMountPath: o_opticalDevicePath]]];
} }
else if (diskType == kVLCMediaVCD) else if (diskType == kVLCMediaVCD)
{ {
[o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_currentOpticalDevice]]; [o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
[self showOpticalMediaView: o_disc_vcd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_currentOpticalDevice]]; [self showOpticalMediaView: o_disc_vcd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
[self setMRL: [NSString stringWithFormat: @"vcd://%@#%i:%i", [self getBSDNodeFromMountPath: o_currentOpticalDevice], [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]]; [self setMRL: [NSString stringWithFormat: @"vcd://%@#%i:%i", [self getBSDNodeFromMountPath: o_opticalDevicePath], [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
} }
else if (diskType == kVLCMediaSVCD) else if (diskType == kVLCMediaSVCD)
{ {
[o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_currentOpticalDevice]]; [o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
[self showOpticalMediaView: o_disc_vcd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_currentOpticalDevice]]; [self showOpticalMediaView: o_disc_vcd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
[self setMRL: [NSString stringWithFormat: @"vcd://%@@%i:%i", [self getBSDNodeFromMountPath: o_currentOpticalDevice], [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]]; [self setMRL: [NSString stringWithFormat: @"vcd://%@@%i:%i", [self getBSDNodeFromMountPath: o_opticalDevicePath], [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
} }
else if (diskType == kVLCMediaBD || diskType == kVLCMediaBDMVFolder) else if (diskType == kVLCMediaBD || diskType == kVLCMediaBDMVFolder)
{ {
[o_disc_bd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_currentOpticalDevice]]; [o_disc_bd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
[self showOpticalMediaView: o_disc_bd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_currentOpticalDevice]]; [self showOpticalMediaView: o_disc_bd_view withIcon: [[NSWorkspace sharedWorkspace] iconForFile: o_opticalDevicePath]];
[self setMRL: [NSString stringWithFormat: @"bluray://%@", o_currentOpticalDevice]]; [self setMRL: [NSString stringWithFormat: @"bluray://%@", o_opticalDevicePath]];
} }
else else
{ {
...@@ -937,13 +928,18 @@ static VLCOpen *_o_sharedMainInstance = nil; ...@@ -937,13 +928,18 @@ static VLCOpen *_o_sharedMainInstance = nil;
[o_pool release]; [o_pool release];
} }
- (void)showSelectedOpticalDisc
{
NSString *o_opticalDevicePath = [o_opticalDevices objectAtIndex:[o_disc_selector_pop indexOfSelectedItem]];
[NSThread detachNewThreadSelector:@selector(showOpticalAtPath:) toTarget:self withObject:o_opticalDevicePath];
}
- (void)scanOpticalMedia:(NSNotification *)o_notification - (void)scanOpticalMedia:(NSNotification *)o_notification
{ {
[o_opticalDevices removeAllObjects]; [o_opticalDevices removeAllObjects];
[o_disc_selector_pop removeAllItems]; [o_disc_selector_pop removeAllItems];
[o_opticalDevices addObjectsFromArray: [[NSWorkspace sharedWorkspace] mountedRemovableMedia]]; [o_opticalDevices addObjectsFromArray: [[NSWorkspace sharedWorkspace] mountedRemovableMedia]];
if ([o_specialMediaFolders count] > 0) [o_opticalDevices addObjectsFromArray: o_specialMediaFolders];
[o_opticalDevices addObjectsFromArray: o_specialMediaFolders];
if ([o_opticalDevices count] > 0) { if ([o_opticalDevices count] > 0) {
NSUInteger deviceCount = [o_opticalDevices count]; NSUInteger deviceCount = [o_opticalDevices count];
for (NSUInteger i = 0; i < deviceCount ; i++) for (NSUInteger i = 0; i < deviceCount ; i++)
...@@ -954,7 +950,7 @@ static VLCOpen *_o_sharedMainInstance = nil; ...@@ -954,7 +950,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
else else
[o_disc_selector_pop setHidden: NO]; [o_disc_selector_pop setHidden: NO];
[NSThread detachNewThreadSelector:@selector(showOpticalAtIndex:) toTarget:self withObject:[NSNumber numberWithInt:[o_disc_selector_pop indexOfSelectedItem]]]; [self showSelectedOpticalDisc];
} }
else else
{ {
...@@ -966,7 +962,7 @@ static VLCOpen *_o_sharedMainInstance = nil; ...@@ -966,7 +962,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
- (IBAction)discSelectorChanged:(id)sender - (IBAction)discSelectorChanged:(id)sender
{ {
[NSThread detachNewThreadSelector:@selector(showOpticalAtIndex:) toTarget:self withObject:[NSNumber numberWithInt:[o_disc_selector_pop indexOfSelectedItem]]]; [self showSelectedOpticalDisc];
} }
- (IBAction)openSpecialMediaFolder:(id)sender - (IBAction)openSpecialMediaFolder:(id)sender
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment