diff --git a/Win32/DaemonWin32.cpp b/Win32/DaemonWin32.cpp index 9fffe7fb..5524aff3 100644 --- a/Win32/DaemonWin32.cpp +++ b/Win32/DaemonWin32.cpp @@ -8,6 +8,7 @@ #ifdef _WIN32 #include "Win32/Win32Service.h" #ifdef WIN32_APP +#include #include "Win32/Win32App.h" #endif @@ -23,6 +24,11 @@ namespace util setlocale(LC_ALL, "Russian"); setlocale(LC_TIME, "C"); + i2p::log::SetThrowFunction ([](const std::string& s) + { + MessageBox(0, TEXT(s.c_str ()), TEXT("i2pd"), MB_ICONERROR | MB_TASKMODAL | MB_OK ); + }); + if (!Daemon_Singleton::init(argc, argv)) return false; diff --git a/libi2pd/Log.cpp b/libi2pd/Log.cpp index 7d77aaf8..65602674 100644 --- a/libi2pd/Log.cpp +++ b/libi2pd/Log.cpp @@ -236,5 +236,11 @@ namespace log { Log & Logger() { return logger; } + + static ThrowFunction g_ThrowFunction; + ThrowFunction GetThrowFunction () { return g_ThrowFunction; } + void SetThrowFunction (ThrowFunction f) { g_ThrowFunction = f; } + } // log } // i2p + diff --git a/libi2pd/Log.h b/libi2pd/Log.h index 88d5c4db..556654e2 100644 --- a/libi2pd/Log.h +++ b/libi2pd/Log.h @@ -17,16 +17,13 @@ #include #include #include +#include #include "Queue.h" #ifndef _WIN32 #include #endif -#ifdef WIN32_APP -#include // TODO: move away to win32app -#endif - enum LogLevel { eLogNone = 0, @@ -155,6 +152,10 @@ namespace log { }; Log & Logger(); + + typedef std::function ThrowFunction; + ThrowFunction GetThrowFunction (); + void SetThrowFunction (ThrowFunction f); } // log } @@ -201,7 +202,6 @@ void LogPrint (LogLevel level, TArgs&&... args) noexcept log.Append(msg); } - /** * @brief Throw fatal error message with the list of arguments * @param args Array of message parts @@ -209,6 +209,8 @@ void LogPrint (LogLevel level, TArgs&&... args) noexcept template void ThrowFatal (TArgs&&... args) noexcept { + auto f = i2p::log::GetThrowFunction (); + if (!f) return; // fold message to single string std::stringstream ss(""); #if (__cplusplus >= 201703L) // C++ 17 or higher @@ -216,12 +218,7 @@ void ThrowFatal (TArgs&&... args) noexcept #else LogPrint (ss, std::forward(args)...); #endif - -#ifdef WIN32_APP - MessageBox(0, TEXT(ss.str ().c_str ()), TEXT("i2pd"), MB_ICONERROR | MB_TASKMODAL | MB_OK ); -#else - std::cout << ss.str (); -#endif + f (ss.str ()); } #endif // LOG_H__