Skip to content

Commit

Permalink
update check failed mods
Browse files Browse the repository at this point in the history
  • Loading branch information
kaniol-lck committed Jan 21, 2022
1 parent eb0df91 commit 604d9a0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/local/localmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ LocalMod::LocalMod(LocalModPath *parent, LocalModFile *file) :
{
connect(this, &LocalMod::tagsEditted, path_, &LocalModPath::writeToFile);
connect(this, &LocalMod::modCacheUpdated, path_, &LocalModPath::writeToFile);
connect(updateChecker_, &CheckSheet::started, this, &LocalMod::checkUpdateStarted);
connect(updateChecker_, &CheckSheet::finished, this, &LocalMod::checkUpdateFinished);
connect(updateChecker_, &CheckSheet::finished, this, &LocalMod::updateReady);
addSubTagable(path_);
if(file) setModFile(file);
Expand Down
6 changes: 2 additions & 4 deletions src/local/localmod.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,11 @@ public slots:
void modrinthUpdateReady(bool success = true);

//update
// void checkUpdatesStarted();
// void checkCancelled();
void checkUpdateStarted();
void checkUpdateFinished(bool success);
void updateReady();

void checkCurseforgeStarted();
void checkCurseforgeUpdateStarted();
void checkModrinthStarted();
void checkModrinthUpdateStarted();

void updateStarted();
Expand Down
2 changes: 1 addition & 1 deletion src/local/localmodpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ void LocalModPath::checkModUpdates() // force = true by default
if(modMap_.isEmpty() || updateChecker_.isWaiting()) return;
updateChecker_.start();
for(auto &&mod : modList()){
updateChecker_.add(mod->updateChecker(), &CheckSheet::started, &CheckSheet::finished);
updateChecker_.add(mod, &LocalMod::checkUpdateStarted, &LocalMod::checkUpdateFinished);
mod->checkUpdates();
}
updateChecker_.done();
Expand Down
13 changes: 11 additions & 2 deletions src/ui/local/localmodbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,17 @@ void LocalModBrowser::onCheckUpdatesFinished(bool success)
onUpdatableCountChanged();
updateStatusText();
qDebug() << success << modPath_->updateChecker()->failedCount();
if(!success)
QMessageBox::information(this, tr("Update Checking Incompleted"), tr("%1 mods failed checking update because of network.").arg(modPath_->updateChecker()->failedCount()));
if(!success) {
auto &&failedObjects = modPath_->updateChecker()->failedObjects();
QStringList stringlist;
for(auto &&object : failedObjects){
if(auto mod = qobject_cast<const LocalMod *>(object))
stringlist << "<li>" + mod->displayName() + "</li>";
}
QMessageBox::information(this, tr("Update Checking Incompleted"), tr("%1 mods failed checking update because of network: <ul>%2</ul>")
.arg(modPath_->updateChecker()->failedCount())
.arg(stringlist.join("")));
}
}

void LocalModBrowser::onUpdatableCountChanged()
Expand Down
2 changes: 0 additions & 2 deletions src/ui/local/localmoditemwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ LocalModItemWidget::LocalModItemWidget(QWidget *parent, LocalMod *mod) :

connect(mod_, &LocalMod::updateReady, this, &LocalModItemWidget::updateReady);

connect(mod_, &LocalMod::checkCurseforgeStarted, this, &LocalModItemWidget::startCheckCurseforge);
connect(mod_, &LocalMod::curseforgeReady, this, &LocalModItemWidget::curseforgeReady);
connect(mod_, &LocalMod::checkCurseforgeUpdateStarted, this, &LocalModItemWidget::startCheckCurseforgeUpdate);

connect(mod_, &LocalMod::checkModrinthStarted, this, &LocalModItemWidget::startCheckModrinth);
connect(mod_, &LocalMod::modrinthReady, this, &LocalModItemWidget::modrinthReady);
connect(mod_, &LocalMod::checkModrinthUpdateStarted, this, &LocalModItemWidget::startCheckModrinthUpdate);

Expand Down
11 changes: 6 additions & 5 deletions src/util/checksheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <QMap>
#include <QObject>
#include <QDebug>

class CheckSheet : public QObject
{
Expand All @@ -14,12 +15,12 @@ class CheckSheet : public QObject
void done();

template <typename Func1, typename Func2>
void add(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 startSignal, Func2 finishSignal)
void add(const typename QtPrivate::FunctionPointer<Func1>::Object *object, Func1 startSignal, Func2 finishSignal)
{
startConnections_ << connect(sender, startSignal, this, [=]{
objects_.insert(sender, { false, false });
finishConnections_ << connect(sender, finishSignal, [=](bool success){
objects_[sender] = { true, success };
startConnections_ << connect(object, startSignal, this, [=]{
objects_.insert(object, { false, false });
finishConnections_ << connect(object, finishSignal, [=](bool success){
objects_[object] = { true, success };
if(isAdding_) return;
emit progress(finishedCount(), objects_.count());
if(allFinished()){
Expand Down

0 comments on commit 604d9a0

Please sign in to comment.