mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-04 02:41:19 +00:00
Merge pull request #2064 from sthalik/pr/win32-debug-parent-console
enable win32 debug console when launching from console
This commit is contained in:
commit
97aa6f58e3
@ -2,8 +2,42 @@
|
||||
|
||||
#include <components/crashcatcher/crashcatcher.hpp>
|
||||
|
||||
#ifdef _WIN32
|
||||
# undef WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace Debug
|
||||
{
|
||||
#ifdef _WIN32
|
||||
bool attachParentConsole()
|
||||
{
|
||||
if (GetConsoleWindow() != nullptr)
|
||||
return true;
|
||||
|
||||
if (AttachConsole(ATTACH_PARENT_PROCESS))
|
||||
{
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
std::cout.flush();
|
||||
std::cerr.flush();
|
||||
|
||||
// this looks dubious but is really the right way
|
||||
_wfreopen(L"CON", L"w", stdout);
|
||||
_wfreopen(L"CON", L"w", stderr);
|
||||
_wfreopen(L"CON", L"r", stdin);
|
||||
freopen("CON", "w", stdout);
|
||||
freopen("CON", "w", stderr);
|
||||
freopen("CON", "r", stdin);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::streamsize DebugOutputBase::write(const char *str, std::streamsize size)
|
||||
{
|
||||
// Skip debug level marker
|
||||
@ -52,6 +86,10 @@ namespace Debug
|
||||
|
||||
int wrapApplication(int (*innerApplication)(int argc, char *argv[]), int argc, char *argv[], const std::string& appName)
|
||||
{
|
||||
#if defined _WIN32
|
||||
(void)Debug::attachParentConsole();
|
||||
#endif
|
||||
|
||||
// Some objects used to redirect cout and cerr
|
||||
// Scope must be here, so this still works inside the catch block for logging exceptions
|
||||
std::streambuf* cout_rdbuf = std::cout.rdbuf ();
|
||||
|
@ -10,6 +10,12 @@
|
||||
|
||||
#include "debuglog.hpp"
|
||||
|
||||
#if defined _WIN32 && defined _DEBUG
|
||||
# undef WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace Debug
|
||||
{
|
||||
// ANSI colors for terminal
|
||||
@ -43,11 +49,11 @@ namespace Debug
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(_WIN32) && defined(_DEBUG)
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#endif // !WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
#ifdef _WIN32
|
||||
bool attachParentConsole();
|
||||
#endif
|
||||
|
||||
#if defined _WIN32 && defined _DEBUG
|
||||
class DebugOutput : public DebugOutputBase
|
||||
{
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user