[fixed] [JIRA MP1-2469] - DetectDrive method obsolete ? (1 Viewer)

azzuro

Test Group
  • Team MediaPortal
  • May 10, 2007
    9,984
    5,663
    France - IDF
    Home Country
    France France
    • Thread starter
    • Moderator
    • #51
    @Deda : have you time for enhance your child ?
     

    Deda

    Lead Dev MP1 Videos
  • Premium Supporter
  • March 18, 2009
    2,423
    2,385
    Zagreb
    Home Country
    Croatia Croatia
    I've added Eject function for USB HDD to branch (dunno if it really works as right now I don't have any here to test).

    Concerning USB CD/DVD plug/unplug, this is a killer and I will not do anything there because things are complicated and changes must be made in RemovableDriveHelper.cs and separate detection of device/volume add/remove and I don't wont to touch anything there because it's not just simple code, but digging into system API and dlls. You will have to find someone more experienced here.
     

    azzuro

    Test Group
  • Team MediaPortal
  • May 10, 2007
    9,984
    5,663
    France - IDF
    Home Country
    France France
    • Thread starter
    • Moderator
    • #53
    You will have to find someone more experienced here.
    the original thread, was for support USB HDD in MP List without need to tweaks/tricks config !

    the missing feature was, do not have "eject function", if now we have ( and working) is good for this mantis.

    i understand the complexity for change code,
    you can have 1 week of work, for make this change, why ? for only have USB optical drive displayed in list ! because actually MP already ask, if you want play media !!! when is inserted

    when i return to home, i test your change !!! if is good, maybe @elliottmc can replanned to 1.4
    Deda, thank for your implication & for rework. if one Dev want to rework completly this code, you'r Welcome !!!
     

    Deda

    Lead Dev MP1 Videos
  • Premium Supporter
  • March 18, 2009
    2,423
    2,385
    Zagreb
    Home Country
    Croatia Croatia
    USB optical drive is not in the list because when you plug it, it is detected as optical drive (drive type 5) and code sends message for autoplay (volume mount). There is no existing method to check whether it is new device and is it USB so MP just assume that disk is inserted into drive and same method reacts on inserting CD/DVD disk into existing drive so we do not know if is device plugged in or media inserted.
     

    azzuro

    Test Group
  • Team MediaPortal
  • May 10, 2007
    9,984
    5,663
    France - IDF
    Home Country
    France France
    • Thread starter
    • Moderator
    • #55

    elliottmc

    Retired Team Member
  • Premium Supporter
  • August 7, 2005
    14,927
    6,061
    Cardiff, UK
    Home Country
    United Kingdom United Kingdom
    @azzuro - I appreciate your enthusiasm for this, but it is clear that this will take a little while to get right.

    There is no benefit in rushing this to get it into 1.4.0. If you need it so badly, it is pretty easy to make your own build with this included. Slow things down and take the time to explain the problems fully.
     

    Deda

    Lead Dev MP1 Videos
  • Premium Supporter
  • March 18, 2009
    2,423
    2,385
    Zagreb
    Home Country
    Croatia Croatia
    There is no existing method to check whether it is new device and is it USB so MP just assume that disk is inserted into drive and same method reacts on inserting CD/DVD disk into existing drive so we do not know if is device plugged in or media inserted.
    is wrong !!!
    look my post https://forum.team-mediaportal.com/...ive-method-obsolete.113317/page-5#post-988186
    MP detect insertion of CD !

    Code:
    private static bool DeviceNew(DEV_BROADCAST_VOLUME volumeInformation)
    	{
    	  char volumeLetter = GetVolumeLetter(volumeInformation.UnitMask);
    	  string path = (volumeLetter + @":").ToUpperInvariant();
    	  string driveName = Utils.GetDriveName(path);
     
    	  _volumeInsertTime = DateTime.Now;
    	  TimeSpan tsMount = DateTime.Now - _mountTime;
    	  TimeSpan tsExamineCD = DateTime.Now - _examineCDTime;
    	  TimeSpan tsVolumeRemoval = DateTime.Now - _volumeRemovalTime;
     
    	  if (Utils.IsRemovable(path) || Utils.IsHD(path))
    	  {
    		Log.Debug("Detected new device: {0}", volumeLetter);
    		GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_ADD_REMOVABLE_DRIVE, 0, 0, 0, 0, 0, 0);
    		msg.Label = path;
    		msg.Label2 = String.Format("({0}) {1}", path, driveName);
    		GUIGraphicsContext.SendMessage(msg);
    		return true;
    	  }
    	  else if (Utils.IsDVD(path))
    	  {
    		// AnyDVD is causing media removed & inserted events when waking up from S3/S4
    		// We need to filter out those as it could trigger false autoplay event
    		if (tsExamineCD.TotalMilliseconds < _volumeRemovalDelay
    		  || (tsVolumeRemoval.TotalMilliseconds < _volumeRemovalDelay || tsMount.TotalMilliseconds < _volumeRemovalDelay))
    		{
    		  Log.Debug("Ignoring volume inserted event - drive {0} - timespan mount {1} s",
    			volumeLetter, tsMount.TotalMilliseconds / 1000);
    		  Log.Debug("  _volumeRemovalDelay = {0}", _volumeRemovalDelay);
    		  return false;
    		}
     
    		Log.Debug("Detected new optical media: {0}", volumeLetter);
    		GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_VOLUME_INSERTED, 0, 0, 0, 0, 0, 0);
    		msg.Label = path;
    		GUIGraphicsContext.SendMessage(msg);
    		return true;
    	  }
    	  return false;
    	}

    Now you se why :), method is the same for everything, it is just divided with drive type so when drive type is HD (USB HD is reported by Windows as Fixed Disk) or thumb (Removable) MP reacts as new device is attached, in case of optical drives it just autoplay it. Similar method is for remove. So in case if we use for all part for HDD/Removable MP will be confused and will try to add drive which could exist and autoplay of disks will not work.

    So in your case, when you plugged in USB CD you got message "Detected new optical media: {0}", volumeLetter" and MP try to autoplay it but as nothing is inside nothing happens (Check if we want to autoplay media type: UNKNOWN).
    When you put disk inside, the same method is executed but autoplay starts in this case beacuse audio disc is inside.

    Problem here is that the same method reacts on plugged in device and media insertion.
     
    Last edited:

    azzuro

    Test Group
  • Team MediaPortal
  • May 10, 2007
    9,984
    5,663
    France - IDF
    Home Country
    France France
    • Thread starter
    • Moderator
    • #60
    @Deda : for you ( not for your use :p ) is needed to have the big change ?
    My question is : How many users, use USB Optical drive as portable ???
    if is occasionnaly, we can skip this change, and leave what is done !
     

    Users who are viewing this thread

    Top Bottom