From 3405b046701e9c08972c1e622259164fc88ac487 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Mon, 5 Feb 2024 15:59:17 +0100 Subject: Use SDL2 to show a simple message box on error Replacing the various OS-specific ways implemented for macOS, Windows and Linux (based on xmessage). --- src/CMakeLists.txt | 1 - src/log.cpp | 18 ++---------------- src/log.h | 5 +++-- src/log.mm | 36 ------------------------------------ 4 files changed, 5 insertions(+), 55 deletions(-) delete mode 100644 src/log.mm diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 750c83bc..f2ba1221 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -623,7 +623,6 @@ ENDIF (WIN32) IF (APPLE) SET(SRCS ${SRCS} - log.mm SDLMain.h SDLMain.m ) diff --git a/src/log.cpp b/src/log.cpp index 1a37abae..47fe5e0f 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -21,18 +21,13 @@ #include "log.h" -#ifdef _WIN32 -#include -#elif __APPLE__ -void MacDialogBox(const std::string &error); -#endif +#include #include #include #include #include #include -#include Logger::Logger(): mLogToStandardOut(true) @@ -106,16 +101,7 @@ void Logger::log(const char *log_text, ...) void Logger::error(const std::string &error_text) { log("Error: %s", error_text.c_str()); -#ifdef _WIN32 - MessageBox(NULL, error_text.c_str(), "Error", MB_ICONERROR | MB_OK); -#elif defined __APPLE__ - MacDialogBox(error_text); -#elif defined __linux__ || __linux std::cerr << "Error: " << error_text << std::endl; - std::string msg="xmessage \"" + error_text + "\""; - system(msg.c_str()); -#else - std::cerr << "Error: " << error_text << std::endl; -#endif + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", error_text.c_str(), NULL); exit(1); } diff --git a/src/log.h b/src/log.h index ef1ebb0f..14a80b58 100644 --- a/src/log.h +++ b/src/log.h @@ -57,9 +57,10 @@ class Logger ; /** - * Log an error and quit. The error will pop-up on Windows and Mac, and - * will be printed to standard error everywhere else. + * Log an error and quit. The error will be printed to standard error + * and showm in a simple message box. */ + __attribute__((noreturn)) void error(const std::string &error_text); private: diff --git a/src/log.mm b/src/log.mm deleted file mode 100644 index ae241c59..00000000 --- a/src/log.mm +++ /dev/null @@ -1,36 +0,0 @@ -/* - * The Mana Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2012 The Mana Developers - * - * This file is part of The Mana Client. - * - * 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 2 of the License, or - * 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 . - */ - -#import -#include - -void MacDialogBox(const std::string &error) -{ - NSString *errorMessage = [NSString stringWithCString:error.c_str() - encoding:[NSString defaultCStringEncoding]]; - NSAlert *alert = [NSAlert alertWithMessageText:errorMessage - defaultButton:@"OK" - alternateButton:nil - otherButton:nil - informativeTextWithFormat:@""]; - - [alert runModal]; -} -- cgit v1.2.3-70-g09d2