summaryrefslogtreecommitdiffstats
path: root/depends/util/src/pathutils.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-10-30 00:56:43 +0100
committerPetr Mrázek <peterix@gmail.com>2013-10-30 00:56:43 +0100
commitf941119fbd89b5677a2895eee3232fa76389b4b5 (patch)
tree7d761d3c8189c06dda83e3fa88f281a24ab46e4b /depends/util/src/pathutils.cpp
parentc46292c9b1c153f2d17554690e90db1c8efe4d23 (diff)
parent44823324f9f489adf957a459bac5dd4d0693e85e (diff)
downloadMultiMC-f941119fbd89b5677a2895eee3232fa76389b4b5.tar
MultiMC-f941119fbd89b5677a2895eee3232fa76389b4b5.tar.gz
MultiMC-f941119fbd89b5677a2895eee3232fa76389b4b5.tar.lz
MultiMC-f941119fbd89b5677a2895eee3232fa76389b4b5.tar.xz
MultiMC-f941119fbd89b5677a2895eee3232fa76389b4b5.zip
Merge branch 'develop'
Diffstat (limited to 'depends/util/src/pathutils.cpp')
-rw-r--r--depends/util/src/pathutils.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/depends/util/src/pathutils.cpp b/depends/util/src/pathutils.cpp
index 4c24fa5d..590ac89d 100644
--- a/depends/util/src/pathutils.cpp
+++ b/depends/util/src/pathutils.cpp
@@ -39,6 +39,30 @@ QString AbsolutePath(QString path)
return QFileInfo(path).absolutePath();
}
+/**
+ * Normalize path
+ *
+ * Any paths inside the current directory will be normalized to relative paths (to current)
+ * Other paths will be made absolute
+ */
+QString NormalizePath(QString path)
+{
+ QDir a = QDir::currentPath();
+ QString currentAbsolute = a.absolutePath();
+
+ QDir b(path);
+ QString newAbsolute = b.absolutePath();
+
+ if (newAbsolute.startsWith(currentAbsolute))
+ {
+ return a.relativeFilePath(newAbsolute);
+ }
+ else
+ {
+ return newAbsolute;
+ }
+}
+
QString badFilenameChars = "\"\\/?<>:*|!";
QString RemoveInvalidFilenameChars(QString string, QChar replaceWith)