Browse Source

engine: platform: win32: enabled attaching to existing console instead of creating new

pull/2/head
SNMetamorph 1 year ago committed by Alibek Omarov
parent
commit
b2ea8c9d18
  1. 78
      engine/platform/win32/con_win.c

78
engine/platform/win32/con_win.c

@ -29,7 +29,10 @@ WIN32 CONSOLE @@ -29,7 +29,10 @@ WIN32 CONSOLE
typedef struct
{
char title[64];
string title;
string previousTitle;
UINT previousCodePage;
UINT previousOutputCodePage;
HWND hWnd;
HANDLE hInput;
HANDLE hOutput;
@ -45,6 +48,7 @@ typedef struct @@ -45,6 +48,7 @@ typedef struct
string lineBuffer[COMMAND_HISTORY];
qboolean inputEnabled;
qboolean consoleVisible;
qboolean attached;
// log stuff
qboolean log_active;
@ -129,7 +133,7 @@ static void Wcon_PrintInternal( const char *msg, int length ) @@ -129,7 +133,7 @@ static void Wcon_PrintInternal( const char *msg, int length )
void Wcon_ShowConsole( qboolean show )
{
if( !s_wcd.hWnd || show == s_wcd.consoleVisible )
if( !s_wcd.hWnd || show == s_wcd.consoleVisible || s_wcd.attached )
return;
s_wcd.consoleVisible = show;
@ -482,7 +486,8 @@ void Wcon_WinPrint( const char *pMsg ) @@ -482,7 +486,8 @@ void Wcon_WinPrint( const char *pMsg )
Wcon_PrintInternal( s_wcd.consoleText, s_wcd.consoleTextLen );
}
Wcon_UpdateStatusLine();
if( !s_wcd.attached )
Wcon_UpdateStatusLine();
}
/*
@ -509,7 +514,16 @@ void Wcon_CreateConsole( void ) @@ -509,7 +514,16 @@ void Wcon_CreateConsole( void )
s_wcd.log_active = true; // always make log
}
AllocConsole();
s_wcd.attached = ( AttachConsole( ATTACH_PARENT_PROCESS ) != 0 );
if( s_wcd.attached ) {
GetConsoleTitle( &s_wcd.previousTitle, sizeof( s_wcd.previousTitle ));
s_wcd.previousCodePage = GetConsoleCP();
s_wcd.previousOutputCodePage = GetConsoleOutputCP();
}
else {
AllocConsole();
}
SetConsoleTitle( s_wcd.title );
SetConsoleCP( CP_UTF8 );
SetConsoleOutputCP( CP_UTF8 );
@ -525,22 +539,25 @@ void Wcon_CreateConsole( void ) @@ -525,22 +539,25 @@ void Wcon_CreateConsole( void )
return;
}
SetWindowPos( s_wcd.hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION | SWP_SHOWWINDOW );
if( !s_wcd.attached )
{
SetWindowPos( s_wcd.hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION | SWP_SHOWWINDOW );
// show console if needed
if( host.con_showalways )
{
// make console visible
ShowWindow( s_wcd.hWnd, SW_SHOWDEFAULT );
UpdateWindow( s_wcd.hWnd );
SetForegroundWindow( s_wcd.hWnd );
SetFocus( s_wcd.hWnd );
s_wcd.consoleVisible = true;
}
else
{
s_wcd.consoleVisible = false;
ShowWindow( s_wcd.hWnd, SW_HIDE );
// show console if needed
if( host.con_showalways )
{
// make console visible
ShowWindow( s_wcd.hWnd, SW_SHOWDEFAULT );
UpdateWindow( s_wcd.hWnd );
SetForegroundWindow( s_wcd.hWnd );
SetFocus( s_wcd.hWnd );
s_wcd.consoleVisible = true;
}
else
{
s_wcd.consoleVisible = false;
ShowWindow( s_wcd.hWnd, SW_HIDE );
}
}
}
@ -573,10 +590,21 @@ void Wcon_DestroyConsole( void ) @@ -573,10 +590,21 @@ void Wcon_DestroyConsole( void )
Sys_CloseLog();
if( s_wcd.hWnd )
if( !s_wcd.attached )
{
if( s_wcd.hWnd )
{
ShowWindow( s_wcd.hWnd, SW_HIDE );
s_wcd.hWnd = 0;
}
}
else
{
ShowWindow( s_wcd.hWnd, SW_HIDE );
s_wcd.hWnd = 0;
// reverts title & code page for console window that was before starting Xash3D
SetConsoleCP( s_wcd.previousCodePage );
SetConsoleOutputCP( s_wcd.previousOutputCodePage );
SetConsoleTitle( &s_wcd.previousTitle );
Con_Printf( "Press Enter to continue...\n" );
}
FreeConsole();
@ -595,8 +623,8 @@ returned input text @@ -595,8 +623,8 @@ returned input text
*/
char *Wcon_Input( void )
{
int i;
int eventsCount;
DWORD i;
DWORD eventsCount;
static INPUT_RECORD events[1024];
if( !s_wcd.inputEnabled )
@ -642,7 +670,7 @@ set server status string in console @@ -642,7 +670,7 @@ set server status string in console
*/
void Wcon_SetStatus( const char *pStatus )
{
if( host.type != HOST_DEDICATED )
if( host.type != HOST_DEDICATED || s_wcd.attached )
return;
Q_strncpy( s_wcd.statusLine, pStatus, sizeof( s_wcd.statusLine ) - 1 );

Loading…
Cancel
Save