diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2008-06-29 09:50:20 +0000 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2008-06-29 09:50:20 +0000 |
commit | 788d01ef7f35a44a38d34278e91f77e132f89860 (patch) | |
tree | 5e88a8017972ba486b7cd8e7e54d54fc7ffa3dee | |
parent | 6f6fcfc3a8510d222981d856e81250561bcc5921 (diff) | |
download | rockbox-788d01ef7f35a44a38d34278e91f77e132f89860.tar.gz rockbox-788d01ef7f35a44a38d34278e91f77e132f89860.zip |
Add w32 mountpoint resolving based on disc number correctly this time.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17873 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | rbutil/rbutilqt/autodetection.cpp | 55 | ||||
-rw-r--r-- | rbutil/rbutilqt/utils.cpp | 38 | ||||
-rw-r--r-- | rbutil/rbutilqt/utils.h | 4 |
3 files changed, 44 insertions, 53 deletions
diff --git a/rbutil/rbutilqt/autodetection.cpp b/rbutil/rbutilqt/autodetection.cpp index 431cb0251e..7399907f15 100644 --- a/rbutil/rbutilqt/autodetection.cpp +++ b/rbutil/rbutilqt/autodetection.cpp | |||
@@ -39,8 +39,10 @@ | |||
39 | #include <tchar.h> | 39 | #include <tchar.h> |
40 | #include <windows.h> | 40 | #include <windows.h> |
41 | #include <setupapi.h> | 41 | #include <setupapi.h> |
42 | #include <winioctl.h> | ||
42 | #endif | 43 | #endif |
43 | #include "detect.h" | 44 | #include "detect.h" |
45 | #include "utils.h" | ||
44 | 46 | ||
45 | Autodetection::Autodetection(QObject* parent): QObject(parent) | 47 | Autodetection::Autodetection(QObject* parent): QObject(parent) |
46 | { | 48 | { |
@@ -157,14 +159,12 @@ bool Autodetection::detect() | |||
157 | if(n == 1) { | 159 | if(n == 1) { |
158 | qDebug() << "Ipod found:" << ipod.modelstr << "at" << ipod.diskname; | 160 | qDebug() << "Ipod found:" << ipod.modelstr << "at" << ipod.diskname; |
159 | m_device = ipod.targetname; | 161 | m_device = ipod.targetname; |
160 | #if !defined(Q_OS_WIN32) | ||
161 | m_mountpoint = resolveMountPoint(ipod.diskname); | 162 | m_mountpoint = resolveMountPoint(ipod.diskname); |
162 | #endif | ||
163 | #if defined(Q_OS_WIN32) | ||
164 | m_mountpoint = getMountpointByDevice(ipod.diskname); | ||
165 | #endif | ||
166 | return true; | 163 | return true; |
167 | } | 164 | } |
165 | else { | ||
166 | qDebug() << "ipodpatcher: no Ipod found." << n; | ||
167 | } | ||
168 | 168 | ||
169 | //try sansapatcher | 169 | //try sansapatcher |
170 | struct sansa_t sansa; | 170 | struct sansa_t sansa; |
@@ -172,14 +172,12 @@ bool Autodetection::detect() | |||
172 | if(n == 1) { | 172 | if(n == 1) { |
173 | qDebug() << "Sansa found:" << sansa.targetname << "at" << sansa.diskname; | 173 | qDebug() << "Sansa found:" << sansa.targetname << "at" << sansa.diskname; |
174 | m_device = QString("sansa%1").arg(sansa.targetname); | 174 | m_device = QString("sansa%1").arg(sansa.targetname); |
175 | #if !defined(Q_OS_WIN32) | ||
176 | m_mountpoint = resolveMountPoint(sansa.diskname); | 175 | m_mountpoint = resolveMountPoint(sansa.diskname); |
177 | #endif | ||
178 | #if defined(Q_OS_WIN32) | ||
179 | m_mountpoint = getMountpointByDevice(sansa.diskname); | ||
180 | #endif | ||
181 | return true; | 176 | return true; |
182 | } | 177 | } |
178 | else { | ||
179 | qDebug() << "sansapatcher: no Sansa found." << n; | ||
180 | } | ||
183 | 181 | ||
184 | if(m_mountpoint.isEmpty() && m_device.isEmpty() && m_errdev.isEmpty() && m_incompat.isEmpty()) | 182 | if(m_mountpoint.isEmpty() && m_device.isEmpty() && m_errdev.isEmpty() && m_incompat.isEmpty()) |
185 | return false; | 183 | return false; |
@@ -256,8 +254,43 @@ QString Autodetection::resolveMountPoint(QString device) | |||
256 | mntinf++; | 254 | mntinf++; |
257 | } | 255 | } |
258 | #endif | 256 | #endif |
259 | return QString(""); | ||
260 | 257 | ||
258 | #if defined(Q_OS_WIN32) | ||
259 | QString result; | ||
260 | unsigned int driveno = device.replace(QRegExp("^.*([0-9]+)"), "\\1").toInt(); | ||
261 | |||
262 | for(int letter = 'A'; letter <= 'Z'; letter++) { | ||
263 | DWORD written; | ||
264 | HANDLE h; | ||
265 | TCHAR uncpath[MAX_PATH]; | ||
266 | UCHAR buffer[0x400]; | ||
267 | PVOLUME_DISK_EXTENTS extents = (PVOLUME_DISK_EXTENTS)buffer; | ||
268 | |||
269 | _stprintf(uncpath, _TEXT("\\\\.\\%c:"), letter); | ||
270 | h = CreateFile(uncpath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, | ||
271 | NULL, OPEN_EXISTING, 0, NULL); | ||
272 | if(h == INVALID_HANDLE_VALUE) { | ||
273 | //qDebug() << "error getting extents for" << uncpath; | ||
274 | continue; | ||
275 | } | ||
276 | // get the extents | ||
277 | if(DeviceIoControl(h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, | ||
278 | NULL, 0, extents, sizeof(buffer), &written, NULL)) { | ||
279 | for(unsigned int a = 0; a < extents->NumberOfDiskExtents; a++) { | ||
280 | qDebug() << "Disk:" << extents->Extents[a].DiskNumber; | ||
281 | if(extents->Extents[a].DiskNumber == driveno) { | ||
282 | result = letter; | ||
283 | qDebug("drive found for volume %i: %c", driveno, letter); | ||
284 | break; | ||
285 | } | ||
286 | } | ||
287 | |||
288 | } | ||
289 | |||
290 | } | ||
291 | return result + ":/"; | ||
292 | #endif | ||
293 | return QString(""); | ||
261 | } | 294 | } |
262 | 295 | ||
263 | 296 | ||
diff --git a/rbutil/rbutilqt/utils.cpp b/rbutil/rbutilqt/utils.cpp index 3e3a5912b2..a6a80c6eef 100644 --- a/rbutil/rbutilqt/utils.cpp +++ b/rbutil/rbutilqt/utils.cpp | |||
@@ -99,41 +99,3 @@ QString resolvePathCase(QString path) | |||
99 | return realpath; | 99 | return realpath; |
100 | } | 100 | } |
101 | 101 | ||
102 | #if defined(Q_OS_WIN32) | ||
103 | QString getMountpointByDevice(int drive) | ||
104 | { | ||
105 | QString result; | ||
106 | for(int letter = 'A'; letter <= 'Z'; letter++) { | ||
107 | DWORD written; | ||
108 | HANDLE h; | ||
109 | TCHAR uncpath[MAX_PATH]; | ||
110 | UCHAR buffer[0x400]; | ||
111 | PVOLUME_DISK_EXTENTS extents = (PVOLUME_DISK_EXTENTS)buffer; | ||
112 | |||
113 | _stprintf(uncpath, _TEXT("\\\\.\\%c:"), letter); | ||
114 | h = CreateFile(uncpath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, | ||
115 | NULL, OPEN_EXISTING, 0, NULL); | ||
116 | if(h == INVALID_HANDLE_VALUE) { | ||
117 | qDebug() << "error getting extents for" << uncpath; | ||
118 | continue; | ||
119 | } | ||
120 | // get the extents | ||
121 | if(DeviceIoControl(h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, | ||
122 | NULL, 0, extents, sizeof(buffer), &written, NULL)) { | ||
123 | for(int a = 0; a < extents->NumberOfDiskExtents; a++) { | ||
124 | qDebug() << "Disk:" << extents->Extents[a].DiskNumber; | ||
125 | if(extents->Extents[a].DiskNumber == drive) { | ||
126 | result = letter; | ||
127 | qDebug("found: %c", letter); | ||
128 | break; | ||
129 | } | ||
130 | } | ||
131 | |||
132 | } | ||
133 | |||
134 | } | ||
135 | return result; | ||
136 | |||
137 | } | ||
138 | #endif | ||
139 | |||
diff --git a/rbutil/rbutilqt/utils.h b/rbutil/rbutilqt/utils.h index 904f5903bc..19cdca92c9 100644 --- a/rbutil/rbutilqt/utils.h +++ b/rbutil/rbutilqt/utils.h | |||
@@ -29,9 +29,5 @@ | |||
29 | bool recRmdir( const QString &dirName ); | 29 | bool recRmdir( const QString &dirName ); |
30 | QString resolvePathCase(QString path); | 30 | QString resolvePathCase(QString path); |
31 | 31 | ||
32 | #if defined(Q_OS_WIN32) | ||
33 | QString getMountpointByDevice(int drive); | ||
34 | #endif | ||
35 | |||
36 | #endif | 32 | #endif |
37 | 33 | ||