From 34282be5af510f5e0985c06234040262304b2471 Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 12 Feb 2016 16:04:18 +0100 Subject: [PATCH 1/2] Changed: Reuse NLMISC::formatErrorMessage instead of native FormatMessage --HG-- branch : develop --- code/nel/src/misc/common.cpp | 22 +++++++++------------- code/nel/src/misc/mutex.cpp | 4 ---- code/nel/src/misc/path.cpp | 16 +++------------- code/nel/src/misc/system_utils.cpp | 16 +--------------- 4 files changed, 13 insertions(+), 45 deletions(-) diff --git a/code/nel/src/misc/common.cpp b/code/nel/src/misc/common.cpp index 6ec0261f6..41a11976f 100644 --- a/code/nel/src/misc/common.cpp +++ b/code/nel/src/misc/common.cpp @@ -685,10 +685,7 @@ bool killProgram(uint32 pid) /*#elif defined(NL_OS_WINDOWS) // it doesn't work because pid != handle and i don't know how to kill a pid or know the real handle of another service (not -1) int res = TerminateProcess((HANDLE)pid, 888); - 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("Failed to kill '%d' err %d: '%s'", pid, GetLastError (), lpMsgBuf); - LocalFree(lpMsgBuf); return res != 0; */ #else @@ -758,11 +755,12 @@ bool launchProgram(const std::string &programName, const std::string &arguments, } else { - 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); if (log) - nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), GetLastError(), lpMsgBuf); - LocalFree(lpMsgBuf); + { + sint lastError = getLastError(); + nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), lastError, formatErrorMessage(lastError).c_str()); + } + CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); } @@ -920,13 +918,11 @@ sint launchProgramAndWaitForResult(const std::string &programName, const std::st } else { - 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); - if (log) - nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), GetLastError(), lpMsgBuf); - - LocalFree(lpMsgBuf); + { + sint lastError = getLastError(); + nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), lastError, formatErrorMessage(lastError).c_str()); + } CloseHandle(pi.hProcess); CloseHandle(pi.hThread); diff --git a/code/nel/src/misc/mutex.cpp b/code/nel/src/misc/mutex.cpp index af0e850ab..098bce795 100644 --- a/code/nel/src/misc/mutex.cpp +++ b/code/nel/src/misc/mutex.cpp @@ -81,11 +81,7 @@ inline void LeaveMutex( void *handle ) { if (ReleaseMutex(handle) == 0) { - //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 );*/ nlerror ("error while releasing the mutex (0x%x %d), %p", GetLastError(), GetLastError(), handle); - //LocalFree( lpMsgBuf ); } } diff --git a/code/nel/src/misc/path.cpp b/code/nel/src/misc/path.cpp index 077bc18be..41477db32 100644 --- a/code/nel/src/misc/path.cpp +++ b/code/nel/src/misc/path.cpp @@ -2358,23 +2358,13 @@ static bool CopyMoveFile(const std::string &dest, const std::string &src, bool c #ifdef NL_OS_WINDOWS if (MoveFile(ssrc.c_str(), sdest.c_str()) == 0) { - LPVOID lpMsgBuf; - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR) &lpMsgBuf, - 0, - NULL ); + sint lastError = NLMISC::getLastError(); nlwarning ("PATH: CopyMoveFile error: can't link/move '%s' into '%s', error %u (%s)", ssrc.c_str(), sdest.c_str(), - GetLastError(), - lpMsgBuf); + lastError, + NLMISC::formatErrorMessage(lastError).c_str()); - LocalFree(lpMsgBuf); return false; } #else diff --git a/code/nel/src/misc/system_utils.cpp b/code/nel/src/misc/system_utils.cpp index 2746c3f39..3997f75ab 100644 --- a/code/nel/src/misc/system_utils.cpp +++ b/code/nel/src/misc/system_utils.cpp @@ -411,21 +411,7 @@ typedef HRESULT (WINAPI* LPCREATEDXGIFACTORY)(REFIID, void**); static std::string FormatError(HRESULT hr) { - std::string res; - - LPTSTR errorText = NULL; - - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&errorText, 0, NULL); - - if (errorText) - { - res = NLMISC::toString("%s (0x%x)", errorText, hr); - LocalFree(errorText); - errorText = NULL; - } - - return res; + return NLMISC::toString("%s (0x%x)", formatErrorMessage(hr).c_str(), hr); } struct SAdapter From 7ed708eae8ec411737f5653306052faa81765b6a Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 12 Feb 2016 16:04:55 +0100 Subject: [PATCH 2/2] Fixed: Display an error if unable to find database.cfg --HG-- branch : develop --- code/nel/tools/3d/mesh_utils/mesh_utils.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/code/nel/tools/3d/mesh_utils/mesh_utils.cpp b/code/nel/tools/3d/mesh_utils/mesh_utils.cpp index 2ea3800a7..b8d70660e 100644 --- a/code/nel/tools/3d/mesh_utils/mesh_utils.cpp +++ b/code/nel/tools/3d/mesh_utils/mesh_utils.cpp @@ -292,7 +292,12 @@ int exportScene(const CMeshUtilsSettings &settings) context.ToolLogger.writeDepend(NLMISC::BUILD, "*", NLMISC::CPath::standardizePath(context.Settings.SourceFilePath, false).c_str()); // Base input file // Apply database configuration - CDatabaseConfig::init(settings.SourceFilePath); + if (!CDatabaseConfig::init(settings.SourceFilePath)) + { + tlerror(context.ToolLogger, context.Settings.SourceFilePath.c_str(), "Unable to find database.cfg in input path or any of its parents."); + return EXIT_FAILURE; + } + CDatabaseConfig::initTextureSearchDirectories(); Assimp::Importer importer;