Skip to content

Commit

Permalink
Fix SCIInstitute#2006 by adding try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
akenmorris committed Feb 15, 2023
1 parent 43efba5 commit 67a42e4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 44 deletions.
87 changes: 47 additions & 40 deletions Studio/Interface/UpdateChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,49 +57,56 @@ void UpdateChecker::run_update_check() {
void UpdateChecker::handleNetworkReply(QNetworkReply* reply) {
std::string response = QString(reply->readAll()).toStdString();

response = "<junk/>";

// get the json response
auto j = json::parse(response);

std::string platform = StudioUtils::get_platform_string().toStdString();

int major = j[platform]["major"].get<int>();
int minor = j[platform]["minor"].get<int>();
int patch = j[platform]["patch"].get<int>();
QString message = QString::fromStdString(j[platform]["message"].get<std::string>());

bool update_available = false;
if (major > SHAPEWORKS_MAJOR_VERSION) {
update_available = true;
} else if (major == SHAPEWORKS_MAJOR_VERSION && minor > SHAPEWORKS_MINOR_VERSION) {
update_available = true;
} else if (major == SHAPEWORKS_MAJOR_VERSION && minor == SHAPEWORKS_MINOR_VERSION &&
patch > SHAPEWORKS_PATCH_VERSION) {
update_available = true;
}
try {
auto j = json::parse(response);
std::string platform = StudioUtils::get_platform_string().toStdString();

int major = j[platform]["major"].get<int>();
int minor = j[platform]["minor"].get<int>();
int patch = j[platform]["patch"].get<int>();
QString message = QString::fromStdString(j[platform]["message"].get<std::string>());

bool update_available = false;
if (major > SHAPEWORKS_MAJOR_VERSION) {
update_available = true;
} else if (major == SHAPEWORKS_MAJOR_VERSION && minor > SHAPEWORKS_MINOR_VERSION) {
update_available = true;
} else if (major == SHAPEWORKS_MAJOR_VERSION && minor == SHAPEWORKS_MINOR_VERSION &&
patch > SHAPEWORKS_PATCH_VERSION) {
update_available = true;
}

if (update_available) {
auto url = QString("https://github.com/SCIInstitute/ShapeWorks/releases/latest");

auto title = QString("New version available");
setWindowTitle(title);
ui_->label->setTextFormat(Qt::RichText);
ui_->label->setOpenExternalLinks(true);
ui_->label->setTextInteractionFlags(Qt::TextBrowserInteraction);
ui_->label->setText(QString("A new version of ShapeWorks is available.<br><br>"
"To download the latest version, please visit:<br><br><a href=\"%1\">%1</a><br><br>" +
message)
.arg(url));

show();
raise();

} else {
if (manual_trigger_) {
// show a messagebox saying there is no update
auto title = QString("No update available");
auto info = QString("You are running the latest version of ShapeWorks.");
QMessageBox::information(nullptr, title, info, QMessageBox::Ok);
if (update_available) {
auto url = QString("https://github.com/SCIInstitute/ShapeWorks/releases/latest");

auto title = QString("New version available");
setWindowTitle(title);
ui_->label->setTextFormat(Qt::RichText);
ui_->label->setOpenExternalLinks(true);
ui_->label->setTextInteractionFlags(Qt::TextBrowserInteraction);
ui_->label->setText(QString("A new version of ShapeWorks is available.<br><br>"
"To download the latest version, please visit:<br><br><a href=\"%1\">%1</a><br><br>" +
message)
.arg(url));

show();
raise();

} else {
if (manual_trigger_) {
// show a messagebox saying there is no update
auto title = QString("No update available");
auto info = QString("You are running the latest version of ShapeWorks.");
QMessageBox::information(nullptr, title, info, QMessageBox::Ok);
}
}

} catch (json::exception& e) {
SW_LOG("Unable to check for updates: " + std::string(e.what()));
return;
}
}
} // namespace shapeworks
6 changes: 2 additions & 4 deletions Studio/Interface/UpdateChecker.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once

#include <Data/Preferences.h>

#include <QDialog>
#include <QNetworkAccessManager>

#include <Data/Preferences.h>

namespace Ui {
class UpdateChecker;
}
Expand All @@ -25,7 +25,6 @@ class UpdateChecker : public QDialog {
void run_auto_update_check();
void run_manual_update_check();


public Q_SLOTS:
void handleNetworkReply(QNetworkReply* reply);

Expand All @@ -38,7 +37,6 @@ class UpdateChecker : public QDialog {
Ui::UpdateChecker* ui_;

Preferences& prefs_;

};

} // namespace shapeworks

0 comments on commit 67a42e4

Please sign in to comment.