diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-02-24 22:21:02 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-02-24 22:21:02 +0300 |
commit | 490a93a1d7a347ab586637bf9d8163e114285a02 (patch) | |
tree | cae315ef7502f6e9b4b55bd68bac66d5fb8e33ff /src/logger.cpp | |
parent | a5926417dad1f91966ccacfc5572369d309c59be (diff) | |
download | manaplus-490a93a1d7a347ab586637bf9d8163e114285a02.tar.gz manaplus-490a93a1d7a347ab586637bf9d8163e114285a02.tar.bz2 manaplus-490a93a1d7a347ab586637bf9d8163e114285a02.tar.xz manaplus-490a93a1d7a347ab586637bf9d8163e114285a02.zip |
Add safe error string reporting function.
Diffstat (limited to 'src/logger.cpp')
-rw-r--r-- | src/logger.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/logger.cpp b/src/logger.cpp index 8eba8fdb9..3c439136b 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -189,6 +189,34 @@ void Logger::log(const char *log_text, ...) delete [] buf; } +// here string must be safe for any usage +void Logger::safeError(const std::string &error_text) +{ + log("Error: %s", error_text.c_str()); +#ifdef WIN32 + MessageBox(nullptr, error_text.c_str(), "Error", MB_ICONERROR | MB_OK); +#elif defined __APPLE__ +// Str255 msg; +// CFStringRef error; +// error = CFStringCreateWithCString(nullptr, +// error_text.c_str(), +// kCFStringEncodingMacRoman); +// CFStringGetPascalString(error, msg, 255, kCFStringEncodingMacRoman); +// StandardAlert(kAlertStopAlert, +// (const unsigned char*)"\pError", +// (ConstStr255Param) msg, nullptr, nullptr); +#elif defined __linux__ || __linux + std::cerr << "Error: " << error_text << std::endl; + std::string msg = "xmessage \"" + error_text + "\""; + if (system(msg.c_str()) == -1) + std::cerr << "Error: " << error_text << std::endl; +#else + std::cerr << "Error: " << error_text << std::endl; +#endif + exit(1); +} + +// here string can be unsafe strings void Logger::error(const std::string &error_text) { log("Error: %s", error_text.c_str()); @@ -206,7 +234,7 @@ void Logger::error(const std::string &error_text) // (ConstStr255Param) msg, nullptr, nullptr); #elif defined __linux__ || __linux std::cerr << "Error: " << error_text << std::endl; - std::string msg = "xmessage \"Error happand. Please see log file for more information.\""; + std::string msg = "xmessage \"Error happend. Please see log file for more information.\""; if (system(msg.c_str()) == -1) std::cerr << "Error: " << error_text << std::endl; #else |