Skip to content

Commit

Permalink
[QoL] Improve client version check (#1053)
Browse files Browse the repository at this point in the history
* Improve version check

* Add informative warning

* Fix the most critical issue that AO2 has ever encountered

An ugly header include

* Increase verbosity and visibility

* TUH
  • Loading branch information
Salanto authored Oct 31, 2024
1 parent 7f17c0b commit b3c0e78
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/lobby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
#include "widgets/server_editor_dialog.h"

#include <QImageReader>
#include <QMessageBox>
#include <QUiLoader>
#include <QVersionNumber>
#include <qnamespace.h>

Lobby::Lobby(AOApplication *p_ao_app, NetworkManager *p_net_manager)
: QMainWindow{}
Expand Down Expand Up @@ -101,9 +104,8 @@ void Lobby::reset_selection()

void Lobby::loadUI()
{
this->setWindowTitle(tr("Attorney Online %1").arg(QApplication::applicationVersion()));
this->setWindowIcon(QIcon(":/logo.png"));
this->setWindowFlags((this->windowFlags() | Qt::CustomizeWindowHint));
setWindowIcon(QIcon(":/logo.png"));
setWindowFlags((windowFlags() | Qt::CustomizeWindowHint));

QUiLoader l_loader(this);
QFile l_uiFile(Options::getInstance().getUIAsset(DEFAULT_UI));
Expand Down Expand Up @@ -558,11 +560,16 @@ void Lobby::get_motd()
void Lobby::check_for_updates()
{
net_manager->request_document(MSDocumentType::ClientVersion, [this](QString version) {
const QString current_version = ao_app->get_version_string();
if (!version.isEmpty() && version != current_version)
QVersionNumber current_version = QVersionNumber::fromString(ao_app->get_version_string());
QVersionNumber master_version = QVersionNumber::fromString(version);

if (current_version < master_version)
{
ui_game_version_lbl->setText(tr("Version: %1 (!)").arg(current_version));
ui_game_version_lbl->setToolTip(tr("New version available: %1").arg(version));
ui_game_version_lbl->setText(tr("Version: %1 [OUTDATED]").arg(current_version.toString()));
setWindowTitle(tr("[Your client is outdated]"));
const QString download_url = QString("https://github.com/AttorneyOnline/AO2-Client/releases/latest").replace(QRegularExpression("\\b(https?://\\S+\\.\\S+)\\b"), "<a href='\\1'>\\1</a>");
const QString message = QString("Your client is outdated!<br>Your Version: %1<br>Current Version: %2<br>Download the latest version at<br>%3").arg(current_version.toString(), master_version.toString(), download_url);
QMessageBox::warning(this, "Your client is outdated!", message);
}
});
}
Expand Down

0 comments on commit b3c0e78

Please sign in to comment.