diff options
Diffstat (limited to 'rbutil')
-rw-r--r-- | rbutil/rbutilqt/autodetection.cpp | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/rbutil/rbutilqt/autodetection.cpp b/rbutil/rbutilqt/autodetection.cpp index 2300a1bba1..a359b91afd 100644 --- a/rbutil/rbutilqt/autodetection.cpp +++ b/rbutil/rbutilqt/autodetection.cpp | |||
@@ -19,6 +19,11 @@ | |||
19 | 19 | ||
20 | #include "autodetection.h" | 20 | #include "autodetection.h" |
21 | 21 | ||
22 | #if defined(Q_OS_LINUX) | ||
23 | #include <stdio.h> | ||
24 | #include <mntent.h> | ||
25 | #endif | ||
26 | |||
22 | Autodetection::Autodetection(QObject* parent): QObject(parent) | 27 | Autodetection::Autodetection(QObject* parent): QObject(parent) |
23 | { | 28 | { |
24 | 29 | ||
@@ -45,6 +50,7 @@ bool Autodetection::detect() | |||
45 | if(!log.value("platform").toString().isEmpty()) { | 50 | if(!log.value("platform").toString().isEmpty()) { |
46 | m_device = log.value("platform").toString(); | 51 | m_device = log.value("platform").toString(); |
47 | m_mountpoint = mountpoints.at(i); | 52 | m_mountpoint = mountpoints.at(i); |
53 | qDebug() << "rbutil.log detected:" << m_device << m_mountpoint; | ||
48 | return true; | 54 | return true; |
49 | } | 55 | } |
50 | } | 56 | } |
@@ -58,14 +64,16 @@ bool Autodetection::detect() | |||
58 | if(line.startsWith("Target: ")) | 64 | if(line.startsWith("Target: ")) |
59 | { | 65 | { |
60 | line.remove("Target: "); | 66 | line.remove("Target: "); |
61 | m_device = line; | 67 | m_device = line.trimmed(); // trim whitespaces |
62 | m_mountpoint = mountpoints.at(i); | 68 | m_mountpoint = mountpoints.at(i); |
69 | qDebug() << "rockbox-info.txt detected:" << m_device << m_mountpoint; | ||
63 | return true; | 70 | return true; |
64 | } | 71 | } |
65 | } | 72 | } |
66 | } | 73 | } |
67 | 74 | ||
68 | } | 75 | } |
76 | |||
69 | int n; | 77 | int n; |
70 | 78 | ||
71 | //try ipodpatcher | 79 | //try ipodpatcher |
@@ -129,25 +137,21 @@ QStringList Autodetection::getMountpoints() | |||
129 | QString Autodetection::resolveMountPoint(QString device) | 137 | QString Autodetection::resolveMountPoint(QString device) |
130 | { | 138 | { |
131 | qDebug() << "Autodetection::resolveMountPoint(QString)" << device; | 139 | qDebug() << "Autodetection::resolveMountPoint(QString)" << device; |
140 | |||
132 | #if defined(Q_OS_LINUX) | 141 | #if defined(Q_OS_LINUX) |
133 | FILE *fp = fopen( "/proc/mounts", "r" ); | 142 | FILE *mn = setmntent("/etc/mtab", "r"); |
134 | if( !fp ) return QString(""); | 143 | if(!mn) |
135 | char *dev, *dir; | 144 | return QString(""); |
136 | while( fscanf( fp, "%as %as %*s %*s %*s %*s", &dev, &dir ) != EOF ) | 145 | |
137 | { | 146 | struct mntent *ent; |
138 | if( QString(dev).startsWith(device) ) | 147 | while((ent = getmntent(mn))) { |
139 | { | 148 | if(QString(ent->mnt_fsname).startsWith(device)) { |
140 | QString directory = dir; | 149 | endmntent(mn); |
141 | free( dev ); | 150 | return QString(ent->mnt_dir); |
142 | free( dir ); | ||
143 | fclose(fp); | ||
144 | return directory; | ||
145 | } | 151 | } |
146 | free( dev ); | ||
147 | free( dir ); | ||
148 | } | 152 | } |
149 | fclose( fp ); | 153 | endmntent(mn); |
150 | 154 | ||
151 | #endif | 155 | #endif |
152 | return QString(""); | 156 | return QString(""); |
153 | 157 | ||