feat: remove existing mod when updating/redownloading it
Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user