summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-12-26 03:20:41 +0100
committerPetr Mrázek <peterix@gmail.com>2015-12-26 03:20:41 +0100
commit7670d72bd9c8bb2adcecd2d04413a2abb9ac174f (patch)
treef02b7cc15ba8ca54f3c404ba542db2cffc841c4c
parentc64a7940c1c99f6691d0fdd45910a09808e40d97 (diff)
downloadMultiMC-7670d72bd9c8bb2adcecd2d04413a2abb9ac174f.tar
MultiMC-7670d72bd9c8bb2adcecd2d04413a2abb9ac174f.tar.gz
MultiMC-7670d72bd9c8bb2adcecd2d04413a2abb9ac174f.tar.lz
MultiMC-7670d72bd9c8bb2adcecd2d04413a2abb9ac174f.tar.xz
MultiMC-7670d72bd9c8bb2adcecd2d04413a2abb9ac174f.zip
GH-1178 sanitize mod paths while installing folder mods
-rw-r--r--application/pages/LegacyJarModPage.cpp2
-rw-r--r--application/pages/ModFolderPage.cpp2
-rw-r--r--logic/minecraft/ModList.cpp19
-rw-r--r--logic/minecraft/ModList.h2
4 files changed, 15 insertions, 10 deletions
diff --git a/application/pages/LegacyJarModPage.cpp b/application/pages/LegacyJarModPage.cpp
index 5d397978..2ff6b6de 100644
--- a/application/pages/LegacyJarModPage.cpp
+++ b/application/pages/LegacyJarModPage.cpp
@@ -105,7 +105,7 @@ void LegacyJarModPage::on_addJarBtn_clicked()
m_jarmods->stopWatching();
for (auto filename : list)
{
- m_jarmods->installMod(QFileInfo(filename));
+ m_jarmods->installMod(filename);
}
m_jarmods->startWatching();
}
diff --git a/application/pages/ModFolderPage.cpp b/application/pages/ModFolderPage.cpp
index e3ece5a6..6791a59e 100644
--- a/application/pages/ModFolderPage.cpp
+++ b/application/pages/ModFolderPage.cpp
@@ -142,7 +142,7 @@ void ModFolderPage::on_addModBtn_clicked()
m_mods->stopWatching();
for (auto filename : list)
{
- m_mods->installMod(QFileInfo(filename));
+ m_mods->installMod(filename);
}
m_mods->startWatching();
}
diff --git a/logic/minecraft/ModList.cpp b/logic/minecraft/ModList.cpp
index a1640d2e..d9ed4886 100644
--- a/logic/minecraft/ModList.cpp
+++ b/logic/minecraft/ModList.cpp
@@ -235,13 +235,18 @@ bool ModList::isValid()
return m_dir.exists() && m_dir.isReadable();
}
-bool ModList::installMod(const QFileInfo &filename, int index)
+bool ModList::installMod(const QString &filename, int index)
{
- if (!filename.exists() || !filename.isReadable() || index < 0)
+ // NOTE: fix for GH-1178: remove trailing slash to avoid issues with using the empty result of QFileInfo::fileName
+ QFileInfo fileinfo(FS::NormalizePath(filename));
+
+ qDebug() << "installing: " << fileinfo.absoluteFilePath();
+
+ if (!fileinfo.exists() || !fileinfo.isReadable() || index < 0)
{
return false;
}
- Mod m(filename);
+ Mod m(fileinfo);
if (!m.valid())
return false;
@@ -270,8 +275,8 @@ bool ModList::installMod(const QFileInfo &filename, int index)
return false;
if (type == Mod::MOD_SINGLEFILE || type == Mod::MOD_ZIPFILE || type == Mod::MOD_LITEMOD)
{
- QString newpath = FS::PathCombine(m_dir.path(), filename.fileName());
- if (!QFile::copy(filename.filePath(), newpath))
+ QString newpath = FS::PathCombine(m_dir.path(), fileinfo.fileName());
+ if (!QFile::copy(fileinfo.filePath(), newpath))
return false;
m.repath(newpath);
beginInsertRows(QModelIndex(), index, index);
@@ -284,8 +289,8 @@ bool ModList::installMod(const QFileInfo &filename, int index)
else if (type == Mod::MOD_FOLDER)
{
- QString from = filename.filePath();
- QString to = FS::PathCombine(m_dir.path(), filename.fileName());
+ QString from = fileinfo.filePath();
+ QString to = FS::PathCombine(m_dir.path(), fileinfo.fileName());
if (!FS::copy(from, to)())
return false;
m.repath(to);
diff --git a/logic/minecraft/ModList.h b/logic/minecraft/ModList.h
index 823854ed..05ada8ee 100644
--- a/logic/minecraft/ModList.h
+++ b/logic/minecraft/ModList.h
@@ -77,7 +77,7 @@ public:
/**
* Adds the given mod to the list at the given index - if the list supports custom ordering
*/
- virtual bool installMod(const QFileInfo &filename, int index = 0);
+ virtual bool installMod(const QString & filename, int index = 0);
/// Deletes the mod at the given index.
virtual bool deleteMod(int index);