summaryrefslogtreecommitdiffstats
path: root/depends
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-10-28 20:55:12 +0100
committerPetr Mrázek <peterix@gmail.com>2013-10-28 20:55:12 +0100
commit6ecb833dbf4c4930c8354dcce7967ad44c16c217 (patch)
tree268120b4b8f7716b6468a655909e1db210dfe3dc /depends
parent923347729557eed76e4f7e9f6f5f1a79216de0a4 (diff)
downloadMultiMC-6ecb833dbf4c4930c8354dcce7967ad44c16c217.tar
MultiMC-6ecb833dbf4c4930c8354dcce7967ad44c16c217.tar.gz
MultiMC-6ecb833dbf4c4930c8354dcce7967ad44c16c217.tar.lz
MultiMC-6ecb833dbf4c4930c8354dcce7967ad44c16c217.tar.xz
MultiMC-6ecb833dbf4c4930c8354dcce7967ad44c16c217.zip
Fix problem with instance list not using the instance folder path
Diffstat (limited to 'depends')
-rw-r--r--depends/util/include/pathutils.h10
-rw-r--r--depends/util/src/pathutils.cpp24
2 files changed, 34 insertions, 0 deletions
diff --git a/depends/util/include/pathutils.h b/depends/util/include/pathutils.h
index cea3a39a..c892c115 100644
--- a/depends/util/include/pathutils.h
+++ b/depends/util/include/pathutils.h
@@ -25,6 +25,16 @@ LIBUTIL_EXPORT QString PathCombine(QString path1, QString path2, QString path3);
LIBUTIL_EXPORT QString AbsolutePath(QString path);
+/**
+ * Normalize path
+ *
+ * Any paths inside the current directory will be normalized to relative paths (to current)
+ * Other paths will be made absolute
+ *
+ * Returns false if the path logic somehow filed (and normalizedPath in invalid)
+ */
+QString NormalizePath(QString path);
+
LIBUTIL_EXPORT QString RemoveInvalidFilenameChars(QString string, QChar replaceWith = '-');
LIBUTIL_EXPORT QString DirNameFromString(QString string, QString inDir = ".");
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)