Skip to content

Commit d96052c

Browse files
Fix #87 - updating improved
1 parent f3892dc commit d96052c

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

data/misc/update.cmd

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ mkdir "%InstallPath%"
2626
(robocopy "%UpdatePath%" "%InstallPath%" *.* /r:5 /w:2 /e /move >nul) & if %errorlevel% lss 8 set errorlevel=0
2727
if %errorlevel% neq 0 (
2828
:: Restore backup
29+
rmdir /S /Q "%InstallPath%"
2930
move /y "%PrevVersionBackupPath%" "%InstallPath%"
3031
set "ResultCode=20"
3132
set "ResultMsg=Failed to move an update to the installation directory"

src/Application.cpp

+16-6
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Application::Application(int& argc, char** argv)
108108
checkUpdateResults();
109109

110110
// TODO: if not disabled in settings / if time has come
111-
checkForUpdates();
111+
checkForUpdates(false);
112112
}
113113

114114
Application::~Application()
@@ -205,15 +205,15 @@ QString Application::getUpdatePath() const
205205
return QDir::temp().absoluteFilePath("CEEDUpdate");
206206
}
207207

208-
void Application::checkForUpdates()
208+
void Application::checkForUpdates(bool manual)
209209
{
210210
if (!Utils::isInternetConnected())
211211
{
212212
qCritical() << "No Internet connection, update check skipped";
213213
return;
214214
}
215215

216-
QUrl infoUrl = _settings->getQSettings()->value("updateInfoUrl", "https://api.github.com/repos/cegui/ceed-cpp/releases/latest").toUrl();
216+
const QUrl infoUrl = _settings->getQSettings()->value("updateInfoUrl", "https://api.github.com/repos/cegui/ceed-cpp/releases/latest").toUrl();
217217

218218
_mainWindow->setStatusMessage("Checking for updates...");
219219

@@ -223,7 +223,7 @@ void Application::checkForUpdates()
223223
onUpdateError(infoReply->url(), infoReply->errorString());
224224
});
225225

226-
QObject::connect(infoReply, &QNetworkReply::finished, [this, infoReply]()
226+
QObject::connect(infoReply, &QNetworkReply::finished, [this, infoReply, manual]()
227227
{
228228
// Already processed by QNetworkReply::errorOccurred handler
229229
if (infoReply->error() != QNetworkReply::NoError) return;
@@ -246,8 +246,11 @@ void Application::checkForUpdates()
246246
auto savedVersion = QVersionNumber::fromString(_settings->getQSettings()->value("update/version").toString());
247247
if (latestVersion.normalized() == savedVersion.normalized())
248248
{
249-
_mainWindow->setStatusMessage(tr("Auto-update to %1 is blocked because it failed before. "
250-
"Use Help->Check For Updates to try again.").arg(latestVersionStr));
249+
const QString msg = tr("Auto-update to %1 is blocked because it failed before. "
250+
"Use Help->Check For Updates to try again.").arg(latestVersionStr);
251+
_mainWindow->setStatusMessage(msg);
252+
if (manual)
253+
QMessageBox::warning(_mainWindow, tr("Auto-update blocked"), msg);
251254
return;
252255
}
253256
else
@@ -262,6 +265,13 @@ void Application::checkForUpdates()
262265
UpdateDialog dlg(currentVersion, latestVersion, releaseInfo);
263266
dlg.exec();
264267
}
268+
else
269+
{
270+
const QString msg = tr("CEED is already at the latest version: %1").arg(applicationVersion());
271+
_mainWindow->setStatusMessage("No update found");
272+
if (manual)
273+
QMessageBox::information(_mainWindow, tr("Already updated"), msg);
274+
}
265275
}
266276
catch (const std::exception& e)
267277
{

src/Application.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Application : public QApplication
3434
QString getDocumentationPath() const;
3535
QString getUpdatePath() const;
3636

37-
void checkForUpdates();
37+
void checkForUpdates(bool manual);
3838

3939
private:
4040

src/ui/MainWindow.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ void MainWindow::on_actionCheckForUpdates_triggered()
13771377
// Forced check for update removes a failed flag which prevents an auto-update
13781378
auto app = qobject_cast<Application*>(qApp);
13791379
app->getSettings()->getQSettings()->remove("update/failed");
1380-
app->checkForUpdates();
1380+
app->checkForUpdates(true);
13811381
}
13821382

13831383
void MainWindow::openNewEditor(EditorFactoryBase* factory)

0 commit comments

Comments
 (0)