public override void DeviceInitialize(IDevice device) { base.DeviceInitialize(device); volume = device as IVolume; if (volume == null || !volume.IsMounted || (usb_device = volume.ResolveRootUsbDevice()) == null) { throw new InvalidDeviceException(); } ms_device = DeviceMapper.Map(this); try { if (ms_device.ShouldIgnoreDevice() || !ms_device.LoadDeviceConfiguration()) { ms_device = null; } } catch { ms_device = null; } if (!HasMediaCapabilities && ms_device == null) { throw new InvalidDeviceException(); } // Ignore iPods, except ones with .is_audio_player files if (MediaCapabilities != null && MediaCapabilities.IsType("ipod")) { if (ms_device != null && ms_device.HasIsAudioPlayerFile) { Log.Information( "Mass Storage Support Loading iPod", "The USB mass storage audio player support is loading an iPod because it has an .is_audio_player file. " + "If you aren't running Rockbox or don't know what you're doing, things might not behave as expected." ); } else { throw new InvalidDeviceException(); } } Name = ms_device == null ? volume.Name : ms_device.Name; mount_point = volume.MountPoint; Initialize(); if (ms_device != null) { ms_device.SourceInitialize(); } AddDapProperties(); // TODO differentiate between Audio Players and normal Disks, and include the size, eg "2GB Audio Player"? //GenericName = Catalog.GetString ("Audio Player"); }
public override void DeviceInitialize(IDevice device) { base.DeviceInitialize(device); if (MediaCapabilities == null || !MediaCapabilities.IsType("mtp")) { throw new InvalidDeviceException(); } // libmtp only allows us to have one MTP device active if (mtp_source != null) { Log.Information( Catalog.GetString("MTP Support Ignoring Device"), Catalog.GetString("Banshee's MTP audio player support can only handle one device at a time."), true ); throw new InvalidDeviceException(); } List <MtpDevice> devices = null; try { devices = MtpDevice.Detect(); } catch (TypeInitializationException e) { Log.Exception(e); Log.Error( Catalog.GetString("Error Initializing MTP Device Support"), Catalog.GetString("There was an error intializing MTP device support. See http://www.banshee-project.org/Guide/DAPs/MTP for more information."), true ); throw new InvalidDeviceException(); } catch (Exception e) { Log.Exception(e); //ShowGeneralExceptionDialog (e); throw new InvalidDeviceException(); } if (devices == null || devices.Count == 0) { Log.Error( Catalog.GetString("Error Finding MTP Device Support"), Catalog.GetString("An MTP device was detected, but Banshee was unable to load support for it."), true ); } else { string mtp_serial = devices[0].SerialNumber; if (!String.IsNullOrEmpty(mtp_serial)) { if (mtp_serial.Contains(device.Serial)) { mtp_device = devices[0]; mtp_source = this; } else if (device.Serial.Contains(mtp_serial.TrimStart('0'))) { // Special case for sony walkman players; BGO #543938 mtp_device = devices[0]; mtp_source = this; } } if (mtp_device == null) { Log.Information( Catalog.GetString("MTP Support Ignoring Device"), Catalog.GetString("Banshee's MTP audio player support can only handle one device at a time."), true ); } } if (mtp_device == null) { throw new InvalidDeviceException(); } Name = mtp_device.Name; Initialize(); List <string> mimetypes = new List <string> (); foreach (FileType format in mtp_device.GetFileTypes()) { if (format == FileType.JPEG) { supports_jpegs = true; } else { string mimetype = MtpDevice.GetMimeTypeFor(format); if (mimetype != null) { mimetypes.Add(mimetype); } } } AcceptableMimeTypes = mimetypes.ToArray(); AddDapProperty(Catalog.GetString("Serial number"), mtp_device.SerialNumber); AddDapProperty(Catalog.GetString("Version"), mtp_device.Version); try { AddDapProperty(Catalog.GetString("Battery level"), String.Format("{0:0%}", mtp_device.BatteryLevel / 100.0)); } catch (Exception e) { Log.Exception("Unable to get battery level from MTP device", e); } }