NOISSUE Prepare mod install for possible move

This commit is contained in:
janrupf
2019-06-19 17:54:39 +02:00
committed by Petr Mrázek
parent ce12f1a734
commit cec5f7332e
3 changed files with 6 additions and 8 deletions

View File

@@ -97,7 +97,7 @@ bool SimpleModList::isValid()
} }
// FIXME: this does not take disabled mod (with extra .disable extension) into account... // 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, bool move)
{ {
// 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
auto originalPath = FS::NormalizePath(filename); auto originalPath = FS::NormalizePath(filename);
@@ -143,7 +143,7 @@ bool SimpleModList::installMod(const QString &filename)
} }
qDebug() << newpath << "has been deleted."; qDebug() << newpath << "has been deleted.";
} }
if (!QFile::copy(fileinfo.filePath(), newpath)) if (move ? !QFile::rename(fileinfo.filePath(), newpath) : !QFile::copy(fileinfo.filePath(), newpath))
{ {
qWarning() << "Copy from" << originalPath << "to" << newpath << "has failed."; qWarning() << "Copy from" << originalPath << "to" << newpath << "has failed.";
// FIXME: report error in a user-visible way // FIXME: report error in a user-visible way
@@ -163,7 +163,7 @@ bool SimpleModList::installMod(const QString &filename)
return false; return false;
} }
if (!FS::copy(from, newpath)()) if (move ? !QDir().rename(from, newpath) : !FS::copy(from, newpath)())
{ {
qWarning() << "Copy of folder from" << originalPath << "to" << newpath << "has (potentially partially) failed."; qWarning() << "Copy of folder from" << originalPath << "to" << newpath << "has (potentially partially) failed.";
return false; return false;
@@ -307,7 +307,6 @@ QVariant SimpleModList::headerData(int section, Qt::Orientation orientation, int
default: default:
return QVariant(); return QVariant();
} }
return QVariant();
} }
Qt::ItemFlags SimpleModList::flags(const QModelIndex &index) const Qt::ItemFlags SimpleModList::flags(const QModelIndex &index) const
@@ -357,9 +356,8 @@ bool SimpleModList::dropMimeData(const QMimeData* data, Qt::DropAction action, i
{ {
continue; continue;
} }
// TODO: implement not only copy, but also move
// FIXME: handle errors here // FIXME: handle errors here
installMod(url.toLocalFile()); installMod(url.toLocalFile(), action == Qt::DropAction::MoveAction);
} }
return true; return true;
} }

View File

@@ -83,7 +83,7 @@ public:
/** /**
* Adds the given mod to the list at the given index - if the list supports custom ordering * Adds the given mod to the list at the given index - if the list supports custom ordering
*/ */
bool installMod(const QString& filename); bool installMod(const QString& filename, bool move);
/// Deletes all the selected mods /// Deletes all the selected mods
virtual bool deleteMods(const QModelIndexList &indexes); virtual bool deleteMods(const QModelIndexList &indexes);

View File

@@ -163,7 +163,7 @@ void ModFolderPage::on_addModBtn_clicked()
{ {
for (auto filename : list) for (auto filename : list)
{ {
m_mods->installMod(filename); m_mods->installMod(filename, false);
} }
} }
} }