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() { void Application::CheckForUpdates() {
Application::SetSubsystemStatus("UpdateCheck", Application::Status::Starting); Application::SetSubsystemStatus("UpdateCheck", Application::Status::Starting);
static bool FirstTime = true;
// checks current version against latest version // checks current version against latest version
std::regex VersionRegex { R"(\d+\.\d+\.\d+\n*)" }; std::regex VersionRegex { R"(\d+\.\d+\.\d+\n*)" };
for (const auto& url : GetBackendUrlsInOrder()) { for (const auto& url : GetBackendUrlsInOrder()) {
@ -109,22 +110,29 @@ void Application::CheckForUpdates() {
std::string RealVersionString = RemoteVersion.AsString(); 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)); 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 { } else {
beammp_info("Server up-to-date!"); if (FirstTime) {
beammp_info("Server up-to-date!");
}
} }
Application::SetSubsystemStatus("UpdateCheck", Application::Status::Good); Application::SetSubsystemStatus("UpdateCheck", Application::Status::Good);
break; break;
} else { } else {
beammp_debug("Failed to fetch version from: " + url); if (FirstTime) {
beammp_trace("got " + Response); beammp_debug("Failed to fetch version from: " + url);
auto Lock = Sentry.CreateExclusiveContext(); beammp_trace("got " + Response);
Sentry.SetContext("get-response", { { "response", Response } }); auto Lock = Sentry.CreateExclusiveContext();
Sentry.LogError("failed to get server version", _file_basename, _line); Sentry.SetContext("get-response", { { "response", Response } });
Application::SetSubsystemStatus("UpdateCheck", Application::Status::Bad); Sentry.LogError("failed to get server version", _file_basename, _line);
Application::SetSubsystemStatus("UpdateCheck", Application::Status::Bad);
}
} }
} }
if (Application::GetSubsystemStatuses().at("UpdateCheck") == Application::Status::Bad) { if (Application::GetSubsystemStatuses().at("UpdateCheck") == Application::Status::Bad) {
beammp_trace("Unable to fetch version info from backend."); if (FirstTime) {
beammp_warn("Unable to fetch version info from backend.");
}
} }
FirstTime = false;
} }
// thread name stuff // thread name stuff

View File

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