2022-04-01 09:36:33 +02:00
|
|
|
// MassBuilderSaveTool
|
2023-09-02 18:30:29 +02:00
|
|
|
// Copyright (C) 2021-2023 Guillaume Jacquemin
|
2022-04-01 09:36:33 +02:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#include <Corrade/Utility/Format.h>
|
|
|
|
|
2022-11-21 09:49:01 +01:00
|
|
|
#include <SDL_events.h>
|
|
|
|
|
2022-11-22 10:34:25 +01:00
|
|
|
#include "../Logger/Logger.h"
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
#include "Application.h"
|
|
|
|
|
|
|
|
namespace mbst {
|
2022-04-01 09:36:33 +02:00
|
|
|
|
2022-12-03 16:49:39 +01:00
|
|
|
void
|
2023-11-29 12:33:26 +01:00
|
|
|
Application::updateCheckEvent(SDL_Event& event) {
|
2022-04-01 09:36:33 +02:00
|
|
|
_updateThread.join();
|
|
|
|
|
2023-10-29 11:32:17 +01:00
|
|
|
switch(static_cast<UpdateChecker::Result>(event.user.code)) {
|
|
|
|
case UpdateChecker::Success:
|
|
|
|
_checkerMutex.lock();
|
|
|
|
if(_checker->updateAvailable()) {
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
_queue.addToast(Toast::Type::Warning,
|
|
|
|
"Your version is out of date and thus unsupported.\nCheck the settings for more information."_s, 5s);
|
2022-04-01 09:36:33 +02:00
|
|
|
}
|
2023-10-29 11:32:17 +01:00
|
|
|
else {
|
|
|
|
if(_checker->version() == current_version || (current_version > _checker->version() && current_version.prerelease)) {
|
|
|
|
_queue.addToast(Toast::Type::Success, "The application is already up to date."_s);
|
|
|
|
}
|
|
|
|
else if(_checker->version() > current_version && !current_version.prerelease) {
|
|
|
|
_queue.addToast(Toast::Type::Warning,
|
|
|
|
"Your version is more recent than the latest one in the repo. How???"_s);
|
|
|
|
}
|
2022-04-01 09:36:33 +02:00
|
|
|
}
|
2023-10-29 11:32:17 +01:00
|
|
|
_checkerMutex.unlock();
|
|
|
|
break;
|
|
|
|
case UpdateChecker::HttpError:
|
|
|
|
_checkerMutex.lock();
|
|
|
|
_queue.addToast(Toast::Type::Error, _checker->error());
|
|
|
|
LOG_ERROR(_checker->error());
|
|
|
|
_checkerMutex.unlock();
|
|
|
|
break;
|
|
|
|
case UpdateChecker::CurlInitFailed:
|
|
|
|
_queue.addToast(Toast::Type::Error, "Couldn't initialise libcurl. Update check aborted."_s);
|
|
|
|
LOG_ERROR("Couldn't initialise libcurl. Update check aborted.");
|
|
|
|
break;
|
|
|
|
case UpdateChecker::CurlError:
|
2022-04-01 09:36:33 +02:00
|
|
|
{
|
2023-10-29 11:32:17 +01:00
|
|
|
using namespace std::chrono_literals;
|
|
|
|
_checkerMutex.lock();
|
|
|
|
_queue.addToast(Toast::Type::Error, _checker->error(), 10s);
|
|
|
|
LOG_ERROR(_checker->error());
|
|
|
|
_checkerMutex.unlock();
|
2022-04-01 09:36:33 +02:00
|
|
|
}
|
2023-10-29 11:32:17 +01:00
|
|
|
break;
|
|
|
|
case UpdateChecker::CurlTimeout:
|
|
|
|
_queue.addToast(Toast::Type::Error, "The request timed out."_s);
|
|
|
|
LOG_ERROR("The request timed out.");
|
|
|
|
break;
|
2022-04-01 09:36:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-03 16:49:39 +01:00
|
|
|
void
|
2023-11-29 12:33:26 +01:00
|
|
|
Application::checkForUpdates() {
|
2022-04-01 09:36:33 +02:00
|
|
|
SDL_Event event;
|
|
|
|
SDL_zero(event);
|
|
|
|
event.type = _updateEventId;
|
|
|
|
|
2023-10-29 11:32:17 +01:00
|
|
|
_checkerMutex.lock();
|
2022-04-01 09:36:33 +02:00
|
|
|
|
2023-10-29 11:32:17 +01:00
|
|
|
if(!_checker) {
|
|
|
|
_checker.emplace();
|
|
|
|
}
|
2022-04-01 09:36:33 +02:00
|
|
|
|
2023-10-29 11:32:17 +01:00
|
|
|
event.user.code = _checker->check();
|
2022-04-01 09:36:33 +02:00
|
|
|
|
2023-10-29 11:32:17 +01:00
|
|
|
_checkerMutex.unlock();
|
2022-04-01 09:36:33 +02:00
|
|
|
|
|
|
|
SDL_PushEvent(&event);
|
|
|
|
}
|
2023-11-29 12:33:26 +01:00
|
|
|
|
|
|
|
}
|