From 29f42ed5abad64515560dbffe1782eb2a6cc5ffa Mon Sep 17 00:00:00 2001 From: kaetemi Date: Fri, 6 Mar 2015 21:07:12 +0100 Subject: [PATCH] Some practical improvements for the report handling --HG-- branch : develop --- code/nel/include/nel/misc/common.h | 2 +- code/nel/include/nel/misc/system_utils.h | 4 ++++ code/nel/src/misc/common.cpp | 11 +++++++---- code/nel/src/misc/debug.cpp | 5 ++--- code/nel/src/misc/report.cpp | 9 ++++++--- code/nel/src/misc/system_utils.cpp | 10 ++++++++++ 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/code/nel/include/nel/misc/common.h b/code/nel/include/nel/misc/common.h index 26458a540..c2a40cc0f 100644 --- a/code/nel/include/nel/misc/common.h +++ b/code/nel/include/nel/misc/common.h @@ -347,7 +347,7 @@ std::string formatThousands(const std::string& s); /// This function executes a program in the background and returns instantly (used for example to launch services in AES). /// The program will be launched in the current directory -bool launchProgram (const std::string &programName, const std::string &arguments); +bool launchProgram (const std::string &programName, const std::string &arguments, bool log = true); /// This function kills a program using his pid (on unix, it uses the kill() POSIX function) bool killProgram(uint32 pid); diff --git a/code/nel/include/nel/misc/system_utils.h b/code/nel/include/nel/misc/system_utils.h index 9b3c5a971..78fd011c6 100644 --- a/code/nel/include/nel/misc/system_utils.h +++ b/code/nel/include/nel/misc/system_utils.h @@ -77,6 +77,10 @@ public: /// Get desktop current color depth without using UDriver. static uint getCurrentColorDepth(); + + /// Detect whether the current process is a windowed application. Return true if definitely yes, false if unknown + static bool detectWindowedApplication(); + }; } // NLMISC diff --git a/code/nel/src/misc/common.cpp b/code/nel/src/misc/common.cpp index 671879f2e..8183430f1 100644 --- a/code/nel/src/misc/common.cpp +++ b/code/nel/src/misc/common.cpp @@ -667,7 +667,7 @@ bool abortProgram(uint32 pid) #endif } -bool launchProgram (const std::string &programName, const std::string &arguments) +bool launchProgram(const std::string &programName, const std::string &arguments, bool log) { #ifdef NL_OS_WINDOWS @@ -719,7 +719,8 @@ bool launchProgram (const std::string &programName, const std::string &arguments { LPVOID lpMsgBuf; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL); - nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), GetLastError (), lpMsgBuf); + if (log) + nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), GetLastError(), lpMsgBuf); LocalFree(lpMsgBuf); CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); @@ -776,7 +777,8 @@ bool launchProgram (const std::string &programName, const std::string &arguments if (status == -1) { char *err = strerror (errno); - nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), errno, err); + if (log) + nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), errno, err); } else if (status == 0) { @@ -796,7 +798,8 @@ bool launchProgram (const std::string &programName, const std::string &arguments return true; } #else - nlwarning ("LAUNCH: launchProgram() not implemented"); + if (log) + nlwarning ("LAUNCH: launchProgram() not implemented"); #endif return false; diff --git a/code/nel/src/misc/debug.cpp b/code/nel/src/misc/debug.cpp index 747d12129..798161a21 100644 --- a/code/nel/src/misc/debug.cpp +++ b/code/nel/src/misc/debug.cpp @@ -53,6 +53,7 @@ #include "nel/misc/path.h" #include "nel/misc/variable.h" #include "nel/misc/system_info.h" +#include "nel/misc/system_utils.h" #define NL_NO_DEBUG_FILES 1 @@ -1223,10 +1224,8 @@ void createDebug (const char *logPath, bool logInFile, bool eraseLastLog) #endif // LOG_IN_FILE DefaultMemDisplayer = new CMemDisplayer ("DEFAULT_MD"); -#ifdef NL_OS_WINDOWS - if (GetConsoleWindow() == NULL) + if (NLMISC::CSystemUtils::detectWindowedApplication()) INelContext::getInstance().setWindowedApplication(true); -#endif initDebug2(logInFile); diff --git a/code/nel/src/misc/report.cpp b/code/nel/src/misc/report.cpp index b388dfb31..ef3280ef5 100644 --- a/code/nel/src/misc/report.cpp +++ b/code/nel/src/misc/report.cpp @@ -25,6 +25,7 @@ #include "nel/misc/report.h" #include "nel/misc/path.h" #include "nel/misc/file.h" +#include "nel/misc/system_utils.h" #ifdef DEBUG_NEW #define new DEBUG_NEW @@ -102,8 +103,9 @@ TReportResult report(const std::string &title, const std::string &subject, const } } - if (INelContext::isContextInitialised() - && INelContext::getInstance().isWindowedApplication() + if (((INelContext::isContextInitialised() + && INelContext::getInstance().isWindowedApplication()) + || CSystemUtils::detectWindowedApplication()) && CFile::isExists(NL_CRASH_REPORT_TOOL)) { std::stringstream params; @@ -151,7 +153,8 @@ TReportResult report(const std::string &title, const std::string &subject, const } else { - NLMISC::launchProgram(NL_CRASH_REPORT_TOOL, paramsStr); // FIXME: Don't use this function, it uses logging, etc, so may loop infinitely! + NLMISC::launchProgram(NL_CRASH_REPORT_TOOL, paramsStr, + NL_DEBUG_REPORT ? INelContext::isContextInitialised() : false); // Only log if required, avoid infinite loop return defaultResult; } } diff --git a/code/nel/src/misc/system_utils.cpp b/code/nel/src/misc/system_utils.cpp index e298f941c..bb1111b88 100644 --- a/code/nel/src/misc/system_utils.cpp +++ b/code/nel/src/misc/system_utils.cpp @@ -355,4 +355,14 @@ uint CSystemUtils::getCurrentColorDepth() return depth; } +/// Detect whether the current process is a windowed application. Return true if definitely yes, false if unknown +bool CSystemUtils::detectWindowedApplication() +{ +#ifdef NL_OS_WINDOWS + if (GetConsoleWindow() == NULL) + return true; +#endif + return false; +} + } // NLMISC