From e7b13768ec7709cf8bc9a321974ae03c6b6d2d67 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Sat, 15 Jun 2024 16:59:54 +0800 Subject: [PATCH] fix: rename function. update console function - Update implementation of EnsureColorfulConsole. - previous implementation will exit if one of the process to stdout and stderr failed. so if it exit at the process of stdout, the process of stderr will not be run. - current implementation will always do process for both of stdout and stderr. the return value will be false if any process of them are failed. - rename GetModuleName to GetModuleFileName and disable annoy Windows macro GetModuleFileName in WinImportSuffix.hpp. --- src/ConsoleHelper.cpp | 7 ++++--- src/ExceptionHelper.cpp | 2 +- src/WinFctHelper.cpp | 2 +- src/WinFctHelper.hpp | 2 +- src/WinImportSuffix.hpp | 1 + 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ConsoleHelper.cpp b/src/ConsoleHelper.cpp index a6ba727..550856e 100644 --- a/src/ConsoleHelper.cpp +++ b/src/ConsoleHelper.cpp @@ -163,9 +163,10 @@ namespace YYCC::ConsoleHelper { bool EnableColorfulConsole() { #if YYCC_OS == YYCC_OS_WINDOWS - if (!RawEnableColorfulConsole(stdout)) return false; - if (!RawEnableColorfulConsole(stderr)) return false; - return true; + bool ret = true; + ret &= RawEnableColorfulConsole(stdout); + ret &= RawEnableColorfulConsole(stderr); + return ret; #else diff --git a/src/ExceptionHelper.cpp b/src/ExceptionHelper.cpp index 51deb72..a565c07 100644 --- a/src/ExceptionHelper.cpp +++ b/src/ExceptionHelper.cpp @@ -223,7 +223,7 @@ namespace YYCC::ExceptionHelper { std::string module_name_raw; DWORD64 module_base; if (module_base = SymGetModuleBase64(process, frame.AddrPC.Offset)) { - if (WinFctHelper::GetModuleName((HINSTANCE)module_base, module_name_raw)) { + if (WinFctHelper::GetModuleFileName((HINSTANCE)module_base, module_name_raw)) { module_name = module_name_raw.c_str(); } } diff --git a/src/WinFctHelper.cpp b/src/WinFctHelper.cpp index cc7e9eb..834fa8d 100644 --- a/src/WinFctHelper.cpp +++ b/src/WinFctHelper.cpp @@ -43,7 +43,7 @@ namespace YYCC::WinFctHelper { return YYCC::EncodingHelper::WcharToUTF8(wpath.c_str(), ret); } - bool GetModuleName(HINSTANCE hModule, std::string& ret) { + bool GetModuleFileName(HINSTANCE hModule, std::string& ret) { // create wchar buffer for receiving the temp path. std::wstring wpath(MAX_PATH + 1u, L'\0'); DWORD copied_size; diff --git a/src/WinFctHelper.hpp b/src/WinFctHelper.hpp index 05263ec..ad6652f 100644 --- a/src/WinFctHelper.hpp +++ b/src/WinFctHelper.hpp @@ -48,7 +48,7 @@ namespace YYCC::WinFctHelper { * The variable receiving UTF8 encoded file name of given module. * @return True if success, otherwise false. */ - bool GetModuleName(HINSTANCE hModule, std::string& ret); + bool GetModuleFileName(HINSTANCE hModule, std::string& ret); } #endif diff --git a/src/WinImportSuffix.hpp b/src/WinImportSuffix.hpp index af2c6d2..5c36920 100644 --- a/src/WinImportSuffix.hpp +++ b/src/WinImportSuffix.hpp @@ -15,5 +15,6 @@ #undef GetClassName #undef LoadImage #undef GetTempPath +#undef GetModuleFileName #endif \ No newline at end of file