diff options
Diffstat (limited to 'rbutil/rbutilqt/autodetection.cpp')
-rw-r--r-- | rbutil/rbutilqt/autodetection.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/autodetection.cpp b/rbutil/rbutilqt/autodetection.cpp new file mode 100644 index 0000000000..3f7814282d --- /dev/null +++ b/rbutil/rbutilqt/autodetection.cpp | |||
@@ -0,0 +1,99 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2007 by Dominik Wenger | ||
10 | * $Id: autodetection.cpp 14027 2007-07-27 17:42:49Z domonoky $ | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "autodetection.h" | ||
21 | |||
22 | Autodetection::Autodetection(QObject* parent): QObject(parent) | ||
23 | { | ||
24 | |||
25 | } | ||
26 | |||
27 | bool Autodetection::detect() | ||
28 | { | ||
29 | m_device = ""; | ||
30 | m_mountpoint = ""; | ||
31 | |||
32 | // Try detection via rockbox.info | ||
33 | QStringList mountpoints = getMountpoints(); | ||
34 | |||
35 | for(int i=0; i< mountpoints.size();i++) | ||
36 | { | ||
37 | QDir dir(mountpoints.at(i)); | ||
38 | if(dir.exists()) | ||
39 | { | ||
40 | QFile file(mountpoints.at(i) + "/.rockbox/rockbox-info.txt"); | ||
41 | if(file.exists()) | ||
42 | { | ||
43 | file.open(QIODevice::ReadOnly | QIODevice::Text); | ||
44 | QString line = file.readLine(); | ||
45 | if(line.startsWith("Target: ")) | ||
46 | { | ||
47 | line.remove("Target: "); | ||
48 | m_device = line; | ||
49 | m_mountpoint = mountpoints.at(i); | ||
50 | return true; | ||
51 | } | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | |||
56 | //try ipodpatcher | ||
57 | |||
58 | |||
59 | //try sansapatcher | ||
60 | |||
61 | return false; | ||
62 | } | ||
63 | |||
64 | |||
65 | QStringList Autodetection::getMountpoints() | ||
66 | { | ||
67 | #ifdef Q_OS_WIN32 | ||
68 | QStringList tempList; | ||
69 | QFileInfoList list = QDir::drives(); | ||
70 | for(int i=0; i<list.size();i++) | ||
71 | { | ||
72 | tempList << list.at(i).absolutePath(); | ||
73 | } | ||
74 | return tempList; | ||
75 | |||
76 | #elif Q_OS_MACX | ||
77 | QDir dir("/Volumes"); | ||
78 | return dir.entryList(); | ||
79 | #elif Q_OS_LINUX | ||
80 | QStringList tempList; | ||
81 | |||
82 | FILE *fp = fopen( "/proc/mounts", "r" ); | ||
83 | if( !fp ) return tempList; | ||
84 | char *dev, *dir; | ||
85 | while( fscanf( fp, "%as %as %*s %*s %*s %*s", &dev, &dir ) != EOF ) | ||
86 | { | ||
87 | tempList << dir; | ||
88 | free( dev ); | ||
89 | free( dir ); | ||
90 | } | ||
91 | fclose( fp ); | ||
92 | |||
93 | return tempList; | ||
94 | #else | ||
95 | #error Unknown Plattform | ||
96 | #endif | ||
97 | } | ||
98 | |||
99 | |||