// MassBuilderSaveTool // Copyright (C) 2021-2024 Guillaume Jacquemin // // 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 . #include #include #include "../Logger/Logger.h" #include "Application.h" namespace mbst { void Application::updateCheckEvent(SDL_Event& event) { _updateThread.join(); switch(static_cast(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); } 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); } } _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: { using namespace std::chrono_literals; _checkerMutex.lock(); _queue.addToast(Toast::Type::Error, _checker->error(), 10s); LOG_ERROR(_checker->error()); _checkerMutex.unlock(); } break; case UpdateChecker::CurlTimeout: _queue.addToast(Toast::Type::Error, "The request timed out."_s); LOG_ERROR("The request timed out."); break; } } void Application::checkForUpdates() { SDL_Event event; SDL_zero(event); event.type = _updateEventId; _checkerMutex.lock(); if(!_checker) { _checker.emplace(); } event.user.code = _checker->check(); _checkerMutex.unlock(); SDL_PushEvent(&event); } }