feat: remove existing mod when updating/redownloading it
Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
1709b47bb7
commit
dfab55112b
@ -27,6 +27,7 @@ ModDownloadTask::ModDownloadTask(ModPlatform::IndexedPack mod, ModPlatform::Inde
|
||||
{
|
||||
if (is_indexed) {
|
||||
m_update_task.reset(new LocalModUpdateTask(mods->indexDir(), m_mod, m_mod_version));
|
||||
connect(m_update_task.get(), &LocalModUpdateTask::hasOldMod, this, &ModDownloadTask::hasOldMod);
|
||||
|
||||
addTask(m_update_task);
|
||||
}
|
||||
@ -40,12 +41,13 @@ ModDownloadTask::ModDownloadTask(ModPlatform::IndexedPack mod, ModPlatform::Inde
|
||||
connect(m_filesNetJob.get(), &NetJob::failed, this, &ModDownloadTask::downloadFailed);
|
||||
|
||||
addTask(m_filesNetJob);
|
||||
|
||||
}
|
||||
|
||||
void ModDownloadTask::downloadSucceeded()
|
||||
{
|
||||
m_filesNetJob.reset();
|
||||
if (!std::get<0>(to_delete).isEmpty())
|
||||
mods->uninstallMod(std::get<1>(to_delete), true);
|
||||
}
|
||||
|
||||
void ModDownloadTask::downloadFailed(QString reason)
|
||||
@ -58,3 +60,10 @@ void ModDownloadTask::downloadProgressChanged(qint64 current, qint64 total)
|
||||
{
|
||||
emit progress(current, total);
|
||||
}
|
||||
|
||||
// This indirection is done so that we don't delete a mod before being sure it was
|
||||
// downloaded successfully!
|
||||
void ModDownloadTask::hasOldMod(QString name, QString filename)
|
||||
{
|
||||
to_delete = {name, filename};
|
||||
}
|
||||
|
@ -46,6 +46,11 @@ private:
|
||||
void downloadFailed(QString reason);
|
||||
|
||||
void downloadSucceeded();
|
||||
|
||||
std::tuple<QString, QString> to_delete {"", ""};
|
||||
|
||||
private slots:
|
||||
void hasOldMod(QString name, QString filename);
|
||||
};
|
||||
|
||||
|
||||
|
@ -183,9 +183,12 @@ auto Mod::details() const -> const ModDetails&
|
||||
auto Mod::name() const -> QString
|
||||
{
|
||||
auto d_name = details().name;
|
||||
if (!d_name.isEmpty()) {
|
||||
if (!d_name.isEmpty())
|
||||
return d_name;
|
||||
}
|
||||
|
||||
if (status() != ModStatus::NoMetadata)
|
||||
return metadata()->name;
|
||||
|
||||
return m_name;
|
||||
}
|
||||
|
||||
|
@ -356,6 +356,20 @@ bool ModFolderModel::installMod(const QString &filename)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ModFolderModel::uninstallMod(const QString& filename, bool preserve_metadata)
|
||||
{
|
||||
|
||||
for(auto mod : allMods()){
|
||||
if(mod.fileinfo().fileName() == filename){
|
||||
auto index_dir = indexDir();
|
||||
mod.destroy(index_dir, preserve_metadata);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ModFolderModel::setModStatus(const QModelIndexList& indexes, ModStatusAction enable)
|
||||
{
|
||||
if(interaction_disabled) {
|
||||
|
@ -118,6 +118,8 @@ public:
|
||||
*/
|
||||
bool installMod(const QString& filename);
|
||||
|
||||
bool uninstallMod(const QString& filename, bool preserve_metadata = false);
|
||||
|
||||
/// Deletes all the selected mods
|
||||
bool deleteMods(const QModelIndexList &indexes);
|
||||
|
||||
|
@ -44,6 +44,11 @@ void LocalModUpdateTask::executeTask()
|
||||
{
|
||||
setStatus(tr("Updating index for mod:\n%1").arg(m_mod.name));
|
||||
|
||||
auto old_metadata = Metadata::get(m_index_dir, m_mod.name);
|
||||
if (old_metadata.isValid()) {
|
||||
emit hasOldMod(old_metadata.name, old_metadata.filename);
|
||||
}
|
||||
|
||||
auto pw_mod = Metadata::create(m_index_dir, m_mod, m_mod_version);
|
||||
Metadata::update(m_index_dir, pw_mod);
|
||||
|
||||
|
@ -37,6 +37,9 @@ class LocalModUpdateTask : public Task {
|
||||
//! Entry point for tasks.
|
||||
void executeTask() override;
|
||||
|
||||
signals:
|
||||
void hasOldMod(QString name, QString filename);
|
||||
|
||||
private:
|
||||
QDir m_index_dir;
|
||||
ModPlatform::IndexedPack& m_mod;
|
||||
|
Loading…
Reference in New Issue
Block a user