summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/base/utils.cpp
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2008-10-12 19:21:58 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2008-10-12 19:21:58 +0000
commitf958717d43420655519ae079ef0d35aa912411b2 (patch)
treedf0dbb774dc3619e2b53c944c6928724092dc171 /rbutil/rbutilqt/base/utils.cpp
parent3d30029883e7e2a862bceede967d95d0bfbd93bb (diff)
Separate basic functionality from GUI parts by moving it into a separate folder. Some files still need to get cleaned up prior moving them too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18788 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/rbutilqt/base/utils.cpp')
-rw-r--r--rbutil/rbutilqt/base/utils.cpp101
1 files changed, 101 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/base/utils.cpp b/rbutil/rbutilqt/base/utils.cpp
new file mode 100644
index 0000000000..a6a80c6eef
--- /dev/null
+++ b/rbutil/rbutilqt/base/utils.cpp
@@ -0,0 +1,101 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Copyright (C) 2007 by Dominik Wenger
+ * $Id$
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "utils.h"
+#ifdef UNICODE
+#define _UNICODE
+#endif
+
+#include <QtCore>
+#include <QDebug>
+#include <cstdlib>
+#include <stdio.h>
+
+#if defined(Q_OS_WIN32)
+#include <windows.h>
+#include <tchar.h>
+#include <winioctl.h>
+#endif
+
+// recursive function to delete a dir with files
+bool recRmdir( const QString &dirName )
+{
+ QString dirN = dirName;
+ QDir dir(dirN);
+ // make list of entries in directory
+ QStringList list = dir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot);
+ QFileInfo fileInfo;
+ QString curItem, lstAt;
+ for(int i = 0; i < list.size(); i++){ // loop through all items of list
+ QString name = list.at(i);
+ curItem = dirN + "/" + name;
+ fileInfo.setFile(curItem);
+ if(fileInfo.isDir()) // is directory
+ recRmdir(curItem); // call recRmdir() recursively for deleting subdirectory
+ else // is file
+ QFile::remove(curItem); // ok, delete file
+ }
+ dir.cdUp();
+ return dir.rmdir(dirN); // delete empty dir and return if (now empty) dir-removing was successfull
+}
+
+
+//! @brief resolves the given path, ignoring case.
+//! @param path absolute path to resolve.
+//! @return returns exact casing of path, empty string if path not found.
+QString resolvePathCase(QString path)
+{
+ QStringList elems;
+ QString realpath;
+
+ elems = path.split("/", QString::SkipEmptyParts);
+ int start;
+#if defined(Q_OS_WIN32)
+ // on windows we must make sure to start with the first entry (i.e. the
+ // drive letter) instead of a single / to make resolving work.
+ start = 1;
+ realpath = elems.at(0) + "/";
+#else
+ start = 0;
+ realpath = "/";
+#endif
+
+ for(int i = start; i < elems.size(); i++) {
+ QStringList direlems
+ = QDir(realpath).entryList(QDir::AllEntries|QDir::Hidden|QDir::System);
+ if(direlems.contains(elems.at(i), Qt::CaseInsensitive)) {
+ // need to filter using QRegExp as QStringList::filter(QString)
+ // matches any substring
+ QString expr = QString("^" + elems.at(i) + "$");
+ QRegExp rx = QRegExp(expr, Qt::CaseInsensitive);
+ QStringList a = direlems.filter(rx);
+
+ if(a.size() != 1)
+ return QString("");
+ if(!realpath.endsWith("/"))
+ realpath += "/";
+ realpath += a.at(0);
+ }
+ else
+ return QString("");
+ }
+ qDebug() << __func__ << path << "->" << realpath;
+ return realpath;
+}
+