GH-1178 sanitize mod paths while installing folder mods
This commit is contained in:
parent
c64a7940c1
commit
7670d72bd9
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user