summaryrefslogtreecommitdiffstats
path: root/libutil/src/pathutils.cpp
diff options
context:
space:
mode:
authorAndrew <forkk@forkk.net>2013-04-22 17:15:18 -0500
committerAndrew <forkk@forkk.net>2013-04-22 17:15:18 -0500
commit1626fa013c86dc9f30254f57b3518211f6d0c65a (patch)
tree7f5a1b09916f55587c282ff7ffb51d792ceefd08 /libutil/src/pathutils.cpp
parentff3078b3a652316eef760386f665d152cbeb8db9 (diff)
downloadMultiMC-1626fa013c86dc9f30254f57b3518211f6d0c65a.tar
MultiMC-1626fa013c86dc9f30254f57b3518211f6d0c65a.tar.gz
MultiMC-1626fa013c86dc9f30254f57b3518211f6d0c65a.tar.lz
MultiMC-1626fa013c86dc9f30254f57b3518211f6d0c65a.tar.xz
MultiMC-1626fa013c86dc9f30254f57b3518211f6d0c65a.zip
Implement instance creation.
Diffstat (limited to 'libutil/src/pathutils.cpp')
-rw-r--r--libutil/src/pathutils.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/libutil/src/pathutils.cpp b/libutil/src/pathutils.cpp
index 8e91bf31..7ba7397c 100644
--- a/libutil/src/pathutils.cpp
+++ b/libutil/src/pathutils.cpp
@@ -35,3 +35,33 @@ QString AbsolutePath(QString path)
{
return QFileInfo(path).absolutePath();
}
+
+QString badFilenameChars = "\"\\/?<>:*|!";
+
+QString RemoveInvalidFilenameChars(QString string, QChar replaceWith)
+{
+ for (int i = 0; i < string.length(); i++)
+ {
+ if (badFilenameChars.contains(string[i]))
+ {
+ string[i] = replaceWith;
+ }
+ }
+ return string;
+}
+
+QString DirNameFromString(QString string, QString inDir)
+{
+ int num = 0;
+ QString dirName = RemoveInvalidFilenameChars(string, '-');
+ while (QFileInfo(PathCombine(inDir, dirName)).exists())
+ {
+ num++;
+ dirName = RemoveInvalidFilenameChars(dirName, '-') + QString::number(num);
+
+ // If it's over 9000
+ if (num > 9000)
+ return "";
+ }
+ return dirName;
+}