NOISSUE fix up mod installation and add a lot of logging for it

This commit is contained in:
Petr Mrázek 2018-11-21 00:29:41 +01:00
parent a8e77f0ecc
commit 33a7cc1890
2 changed files with 44 additions and 27 deletions

View File

@ -96,62 +96,79 @@ bool SimpleModList::isValid()
return m_dir.exists() && m_dir.isReadable(); return m_dir.exists() && m_dir.isReadable();
} }
// FIXME: this does not take disabled mod (with extra .disable extension) into account...
bool SimpleModList::installMod(const QString &filename) bool SimpleModList::installMod(const QString &filename)
{ {
// NOTE: fix for GH-1178: remove trailing slash to avoid issues with using the empty result of QFileInfo::fileName // NOTE: fix for GH-1178: remove trailing slash to avoid issues with using the empty result of QFileInfo::fileName
QFileInfo fileinfo(FS::NormalizePath(filename)); auto originalPath = FS::NormalizePath(filename);
QFileInfo fileinfo(originalPath);
qDebug() << "installing: " << fileinfo.absoluteFilePath();
if (!fileinfo.exists() || !fileinfo.isReadable()) if (!fileinfo.exists() || !fileinfo.isReadable())
{ {
qWarning() << "Caught attempt to install non-existing file or file-like object:" << originalPath;
return false; return false;
} }
Mod m(fileinfo); qDebug() << "installing: " << fileinfo.absoluteFilePath();
if (!m.valid())
return false;
auto type = m.type(); Mod installedMod(fileinfo);
if (type == Mod::MOD_UNKNOWN) if (!installedMod.valid())
{
qDebug() << originalPath << "is not a valid mod. Ignoring it.";
return false; return false;
}
auto type = installedMod.type();
if (type == Mod::MOD_UNKNOWN)
{
qDebug() << "Cannot recognize mod type of" << originalPath << ", ignoring it.";
return false;
}
auto newpath = FS::NormalizePath(FS::PathCombine(m_dir.path(), fileinfo.fileName()));
if(originalPath == newpath)
{
qDebug() << "Overwriting the mod (" << originalPath << ") with itself makes no sense...";
return false;
}
if (type == Mod::MOD_SINGLEFILE || type == Mod::MOD_ZIPFILE || type == Mod::MOD_LITEMOD) if (type == Mod::MOD_SINGLEFILE || type == Mod::MOD_ZIPFILE || type == Mod::MOD_LITEMOD)
{ {
auto newpath = FS::PathCombine(m_dir.path(), fileinfo.fileName());
// if it's already there, rename it and disable it. if there was already an old thing, remove it.
if(QFile::exists(newpath)) if(QFile::exists(newpath))
{ {
auto olddisabledpath = newpath + "-old.disabled"; if(!QFile::remove(newpath))
if(QFile::exists(olddisabledpath))
{ {
if(!QFile::remove(olddisabledpath)) // FIXME: report error in a user-visible way
{ qWarning() << "Copy from" << originalPath << "to" << newpath << "has failed.";
// FIXME: report error correctly
return false;
}
}
if(!QFile::rename(newpath, olddisabledpath))
{
// FIXME: report error correctly
return false; return false;
} }
qDebug() << newpath << "has been deleted.";
} }
if (!QFile::copy(fileinfo.filePath(), newpath)) if (!QFile::copy(fileinfo.filePath(), newpath))
{ {
// FIXME: report error correctly qWarning() << "Copy from" << originalPath << "to" << newpath << "has failed.";
// FIXME: report error in a user-visible way
return false; return false;
} }
FS::updateTimestamp(newpath); FS::updateTimestamp(newpath);
m.repath(newpath); installedMod.repath(newpath);
update(); update();
return true; return true;
} }
else if (type == Mod::MOD_FOLDER) else if (type == Mod::MOD_FOLDER)
{ {
QString from = fileinfo.filePath(); QString from = fileinfo.filePath();
QString to = FS::PathCombine(m_dir.path(), fileinfo.fileName()); if(QFile::exists(newpath))
if (!FS::copy(from, to)()) {
qDebug() << "Ignoring folder " << from << ", it would merge with " << newpath;
return false; return false;
m.repath(to); }
if (!FS::copy(from, newpath)())
{
qWarning() << "Copy of folder from" << originalPath << "to" << newpath << "has (potentially partially) failed.";
return false;
}
installedMod.repath(newpath);
update(); update();
return true; return true;
} }

View File

@ -59,7 +59,7 @@ public:
{ {
return size(); return size();
} }
;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
virtual int columnCount(const QModelIndex &parent) const override; virtual int columnCount(const QModelIndex &parent) const override;