22
22
#include < QDesktopWidget>
23
23
#include < QScreen>
24
24
#include < QWSServer>
25
+ #include < QRegExp>
25
26
#include < QDebug>
26
27
27
- BootSelectionDialog::BootSelectionDialog (const QString &defaultPartition, QWidget *parent) :
28
+ BootSelectionDialog::BootSelectionDialog (const QString &drive, const QString & defaultPartition, QWidget *parent) :
28
29
QDialog(parent),
29
30
_countdown(11 ),
30
31
ui(new Ui::BootSelectionDialog)
@@ -39,14 +40,14 @@ BootSelectionDialog::BootSelectionDialog(const QString &defaultPartition, QWidge
39
40
dir.mkdir (" /settings" );
40
41
41
42
if (QProcess::execute (" mount -o remount,ro /settings" ) != 0
42
- && QProcess::execute (" mount -t ext4 -o ro " SETTINGS_PARTITION " /settings" ) != 0 )
43
+ && QProcess::execute (" mount -t ext4 -o ro " + partdev (drive, SETTINGS_PARTNR)+ " /settings" ) != 0 )
43
44
{
44
45
QMessageBox::critical (this , tr (" Cannot display boot menu" ), tr (" Error mounting settings partition" ));
45
46
return ;
46
47
}
47
48
48
- /* Also mount /dev/mmcblk0p1 as it may contain icons we need */
49
- if (QProcess::execute (" mount -t vfat -o ro /dev/mmcblk0p1 /mnt" ) != 0 )
49
+ /* Also mount recovery partition as it may contain icons we need */
50
+ if (QProcess::execute (" mount -t vfat -o ro " + partdev (drive, 1 )+ " /mnt" ) != 0 )
50
51
{
51
52
/* Not fatal if this fails */
52
53
}
@@ -105,12 +106,15 @@ BootSelectionDialog::BootSelectionDialog(const QString &defaultPartition, QWidge
105
106
ui->list ->installEventFilter (this );
106
107
107
108
// Select OS booted previously
108
- QByteArray partstr = " /dev/mmcblk0p" +QByteArray::number (partition);
109
+ QString partnrStr = QString::number (partition);
110
+ QRegExp partnrRx (" ([0-9]+)$" );
109
111
for (int i=0 ; i<ui->list ->count (); i++)
110
112
{
111
113
QVariantMap m = ui->list ->item (i)->data (Qt::UserRole).toMap ();
112
- if (m.value (" partitions" ).toList ().first () == partstr)
114
+ QString bootpart = m.value (" partitions" ).toList ().first ().toString ();
115
+ if (partnrRx.indexIn (bootpart) != -1 && partnrRx.cap (1 ) == partnrStr)
113
116
{
117
+ qDebug () << " Previous OS at" << bootpart;
114
118
ui->list ->setCurrentRow (i);
115
119
break ;
116
120
}
@@ -153,8 +157,13 @@ void BootSelectionDialog::accept()
153
157
QSettings settings (" /settings/noobs.conf" , QSettings::IniFormat, this );
154
158
QVariantMap m = item->data (Qt::UserRole).toMap ();
155
159
QByteArray partition = m.value (" partitions" ).toList ().first ().toByteArray ();
156
- partition.replace (" /dev/mmcblk0p" , " " );
157
- int partitionNr = partition.toInt ();
160
+ QRegExp partnrRx (" ([0-9]+)$" );
161
+ if (partnrRx.indexIn (partition) == -1 )
162
+ {
163
+ QMessageBox::critical (this , " noobs.conf corrupt" , " Not a valid partition: " +partition);
164
+ return ;
165
+ }
166
+ int partitionNr = partnrRx.cap (1 ).toInt ();
158
167
int oldpartitionNr = settings.value (" default_partition_to_boot" , 0 ).toInt ();
159
168
160
169
if (partitionNr != oldpartitionNr)
0 commit comments