mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-25 10:20:54 +00:00
Some practical improvements for the report handling
--HG-- branch : develop
This commit is contained in:
parent
163abf31b8
commit
29f42ed5ab
6 changed files with 30 additions and 11 deletions
|
@ -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).
|
/// 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
|
/// 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)
|
/// This function kills a program using his pid (on unix, it uses the kill() POSIX function)
|
||||||
bool killProgram(uint32 pid);
|
bool killProgram(uint32 pid);
|
||||||
|
|
|
@ -77,6 +77,10 @@ public:
|
||||||
|
|
||||||
/// Get desktop current color depth without using UDriver.
|
/// Get desktop current color depth without using UDriver.
|
||||||
static uint getCurrentColorDepth();
|
static uint getCurrentColorDepth();
|
||||||
|
|
||||||
|
/// Detect whether the current process is a windowed application. Return true if definitely yes, false if unknown
|
||||||
|
static bool detectWindowedApplication();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // NLMISC
|
} // NLMISC
|
||||||
|
|
|
@ -667,7 +667,7 @@ bool abortProgram(uint32 pid)
|
||||||
#endif
|
#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
|
#ifdef NL_OS_WINDOWS
|
||||||
|
@ -719,7 +719,8 @@ bool launchProgram (const std::string &programName, const std::string &arguments
|
||||||
{
|
{
|
||||||
LPVOID lpMsgBuf;
|
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);
|
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);
|
LocalFree(lpMsgBuf);
|
||||||
CloseHandle( pi.hProcess );
|
CloseHandle( pi.hProcess );
|
||||||
CloseHandle( pi.hThread );
|
CloseHandle( pi.hThread );
|
||||||
|
@ -776,6 +777,7 @@ bool launchProgram (const std::string &programName, const std::string &arguments
|
||||||
if (status == -1)
|
if (status == -1)
|
||||||
{
|
{
|
||||||
char *err = strerror (errno);
|
char *err = strerror (errno);
|
||||||
|
if (log)
|
||||||
nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), errno, err);
|
nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), errno, err);
|
||||||
}
|
}
|
||||||
else if (status == 0)
|
else if (status == 0)
|
||||||
|
@ -796,6 +798,7 @@ bool launchProgram (const std::string &programName, const std::string &arguments
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
if (log)
|
||||||
nlwarning ("LAUNCH: launchProgram() not implemented");
|
nlwarning ("LAUNCH: launchProgram() not implemented");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
#include "nel/misc/path.h"
|
#include "nel/misc/path.h"
|
||||||
#include "nel/misc/variable.h"
|
#include "nel/misc/variable.h"
|
||||||
#include "nel/misc/system_info.h"
|
#include "nel/misc/system_info.h"
|
||||||
|
#include "nel/misc/system_utils.h"
|
||||||
|
|
||||||
#define NL_NO_DEBUG_FILES 1
|
#define NL_NO_DEBUG_FILES 1
|
||||||
|
|
||||||
|
@ -1223,10 +1224,8 @@ void createDebug (const char *logPath, bool logInFile, bool eraseLastLog)
|
||||||
#endif // LOG_IN_FILE
|
#endif // LOG_IN_FILE
|
||||||
DefaultMemDisplayer = new CMemDisplayer ("DEFAULT_MD");
|
DefaultMemDisplayer = new CMemDisplayer ("DEFAULT_MD");
|
||||||
|
|
||||||
#ifdef NL_OS_WINDOWS
|
if (NLMISC::CSystemUtils::detectWindowedApplication())
|
||||||
if (GetConsoleWindow() == NULL)
|
|
||||||
INelContext::getInstance().setWindowedApplication(true);
|
INelContext::getInstance().setWindowedApplication(true);
|
||||||
#endif
|
|
||||||
|
|
||||||
initDebug2(logInFile);
|
initDebug2(logInFile);
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "nel/misc/report.h"
|
#include "nel/misc/report.h"
|
||||||
#include "nel/misc/path.h"
|
#include "nel/misc/path.h"
|
||||||
#include "nel/misc/file.h"
|
#include "nel/misc/file.h"
|
||||||
|
#include "nel/misc/system_utils.h"
|
||||||
|
|
||||||
#ifdef DEBUG_NEW
|
#ifdef DEBUG_NEW
|
||||||
#define new DEBUG_NEW
|
#define new DEBUG_NEW
|
||||||
|
@ -102,8 +103,9 @@ TReportResult report(const std::string &title, const std::string &subject, const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (INelContext::isContextInitialised()
|
if (((INelContext::isContextInitialised()
|
||||||
&& INelContext::getInstance().isWindowedApplication()
|
&& INelContext::getInstance().isWindowedApplication())
|
||||||
|
|| CSystemUtils::detectWindowedApplication())
|
||||||
&& CFile::isExists(NL_CRASH_REPORT_TOOL))
|
&& CFile::isExists(NL_CRASH_REPORT_TOOL))
|
||||||
{
|
{
|
||||||
std::stringstream params;
|
std::stringstream params;
|
||||||
|
@ -151,7 +153,8 @@ TReportResult report(const std::string &title, const std::string &subject, const
|
||||||
}
|
}
|
||||||
else
|
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;
|
return defaultResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -355,4 +355,14 @@ uint CSystemUtils::getCurrentColorDepth()
|
||||||
return depth;
|
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
|
} // NLMISC
|
||||||
|
|
Loading…
Reference in a new issue