rbutil: Fix autodetection messing up with multiple players.

When multiple players are connected, and at least one of them has a USB
ID that is shared between multiple targets the resulting list would be
off. Fix that by avoiding to modify a list while iterating over it,
that's usually not a good idea.

Change-Id: I0c1fc5e1a3264f269de2d71c3a7f2b82877636ba
This commit is contained in:
Dominik Riebeling 2020-12-05 19:01:03 +01:00
parent 82b53ebf54
commit 731c5db875

View file

@ -54,19 +54,24 @@ bool Autodetection::detect(void)
// hasn't been merged later. This indicates a problem during detection
// (ambiguous player but refining it failed). In this case create an entry
// for eacho of those so the user can select.
QList<struct Detected> detected;
for(int i = 0; i < m_detected.size(); ++i) {
int j = m_detected.at(i).usbdevices.size();
if(j > 0) {
struct Detected entry = m_detected.takeAt(i);
struct Detected entry = m_detected.at(i);
while(j--) {
struct Detected d;
d.device = entry.usbdevices.at(j);
d.mountpoint = entry.mountpoint;
d.status = PlayerAmbiguous;
m_detected.append(d);
detected.append(d);
}
}
else {
detected.append(m_detected.at(i));
}
}
m_detected = detected;
for(int i = 0; i < m_detected.size(); ++i) {
LOG_INFO() << "Detected player:" << m_detected.at(i).device
<< "at" << m_detected.at(i).mountpoint
@ -329,20 +334,12 @@ QString Autodetection::detectAjbrec(QString root)
switch(header[11]) {
case 2:
return "recorderv2";
break;
case 4:
return "fmrecorder";
break;
case 8:
return "ondiofm";
break;
case 16:
return "ondiosp";
break;
default:
break;
}