Application::CheckForUpdates: only print status the first time

This commit is contained in:
Lion Kortlepel 2022-04-28 13:32:38 +02:00
parent 668cc496b6
commit 5ded713b4b
No known key found for this signature in database
GPG Key ID: 4322FF2B4C71259B
2 changed files with 16 additions and 9 deletions

View File

@ -97,6 +97,7 @@ void Application::SetSubsystemStatus(const std::string& Subsystem, Status status
void Application::CheckForUpdates() {
Application::SetSubsystemStatus("UpdateCheck", Application::Status::Starting);
static bool FirstTime = true;
// checks current version against latest version
std::regex VersionRegex { R"(\d+\.\d+\.\d+\n*)" };
for (const auto& url : GetBackendUrlsInOrder()) {
@ -109,11 +110,14 @@ void Application::CheckForUpdates() {
std::string RealVersionString = RemoteVersion.AsString();
beammp_warn(std::string(ANSI_YELLOW_BOLD) + "NEW VERSION IS OUT! Please update to the new version (v" + RealVersionString + ") of the BeamMP-Server! Download it here: https://beammp.com/! For a guide on how to update, visit: https://wiki.beammp.com/en/home/server-maintenance#updating-the-server" + std::string(ANSI_RESET));
} else {
if (FirstTime) {
beammp_info("Server up-to-date!");
}
}
Application::SetSubsystemStatus("UpdateCheck", Application::Status::Good);
break;
} else {
if (FirstTime) {
beammp_debug("Failed to fetch version from: " + url);
beammp_trace("got " + Response);
auto Lock = Sentry.CreateExclusiveContext();
@ -122,9 +126,13 @@ void Application::CheckForUpdates() {
Application::SetSubsystemStatus("UpdateCheck", Application::Status::Bad);
}
}
if (Application::GetSubsystemStatuses().at("UpdateCheck") == Application::Status::Bad) {
beammp_trace("Unable to fetch version info from backend.");
}
if (Application::GetSubsystemStatuses().at("UpdateCheck") == Application::Status::Bad) {
if (FirstTime) {
beammp_warn("Unable to fetch version info from backend.");
}
}
FirstTime = false;
}
// thread name stuff

View File

@ -111,7 +111,6 @@ void TConsole::StartLoggingToFile() {
// sanitize the string by removing all ANSI control codes (like color, etc)
std::string Sanitized;
Sanitized.reserve(ToWrite.size());
EscState state;
for (size_t i = 0; i < ToWrite.size(); ++i) {
if (i + 1 < ToWrite.size()
&& ToWrite[i] == 0x1b) { // starts ANSI escape sequence