1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Wenger
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
30 #if defined(Q_OS_WIN32)
35 #if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
36 #include <sys/statvfs.h>
39 // recursive function to delete a dir with files
40 bool recRmdir( const QString
&dirName
)
42 QString dirN
= dirName
;
44 // make list of entries in directory
45 QStringList list
= dir
.entryList(QDir::AllEntries
| QDir::NoDotAndDotDot
);
47 QString curItem
, lstAt
;
48 for(int i
= 0; i
< list
.size(); i
++){ // loop through all items of list
49 QString name
= list
.at(i
);
50 curItem
= dirN
+ "/" + name
;
51 fileInfo
.setFile(curItem
);
52 if(fileInfo
.isDir()) // is directory
53 recRmdir(curItem
); // call recRmdir() recursively for deleting subdirectory
55 QFile::remove(curItem
); // ok, delete file
58 return dir
.rmdir(dirN
); // delete empty dir and return if (now empty) dir-removing was successfull
62 //! @brief resolves the given path, ignoring case.
63 //! @param path absolute path to resolve.
64 //! @return returns exact casing of path, empty string if path not found.
65 QString
resolvePathCase(QString path
)
70 elems
= path
.split("/", QString::SkipEmptyParts
);
72 #if defined(Q_OS_WIN32)
73 // on windows we must make sure to start with the first entry (i.e. the
74 // drive letter) instead of a single / to make resolving work.
76 realpath
= elems
.at(0) + "/";
82 for(int i
= start
; i
< elems
.size(); i
++) {
84 = QDir(realpath
).entryList(QDir::AllEntries
|QDir::Hidden
|QDir::System
);
85 if(direlems
.contains(elems
.at(i
), Qt::CaseInsensitive
)) {
86 // need to filter using QRegExp as QStringList::filter(QString)
87 // matches any substring
88 QString expr
= QString("^" + elems
.at(i
) + "$");
89 QRegExp rx
= QRegExp(expr
, Qt::CaseInsensitive
);
90 QStringList a
= direlems
.filter(rx
);
94 if(!realpath
.endsWith("/"))
101 qDebug() << __func__
<< path
<< "->" << realpath
;
106 //! @brief figure the free disk space on a filesystem
107 //! @param path path on the filesystem to check
108 //! @return size in bytes
109 qulonglong
filesystemFree(QString path
)
112 #if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
113 // the usage of statfs() is deprecated by the LSB so use statvfs().
117 ret
= statvfs(qPrintable(path
), &fs
);
120 size
= fs
.f_bsize
* fs
.f_bavail
;
122 #if defined(Q_OS_WIN32)
124 ULARGE_INTEGER freeAvailBytes
;
126 ret
= GetDiskFreeSpaceExW((LPCTSTR
)path
.utf16(), &freeAvailBytes
, NULL
, NULL
);
128 size
= freeAvailBytes
.QuadPart
;
133 RockboxInfo::RockboxInfo(QString mountpoint
)
135 m_path
= mountpoint
+"/.rockbox/rockbox-info.txt";
138 bool RockboxInfo::open()
144 if(!file
.open(QIODevice::ReadOnly
| QIODevice::Text
))
147 // read file contents
148 while (!file
.atEnd())
150 QString line
= file
.readLine();
152 if(line
.contains("Version:"))
154 m_version
= line
.remove("Version:").trimmed();
156 else if(line
.contains("Target: "))
158 m_target
= line
.remove("Target: ").trimmed();
160 else if(line
.contains("Features:"))
162 m_features
= line
.remove("Features:").trimmed();
164 else if(line
.contains("Target id:"))
166 m_targetid
= line
.remove("Target id:").trimmed();