Browse Source

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

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

38
engine/platform/win32/con_win.c

@ -29,7 +29,10 @@ WIN32 CONSOLE
typedef struct typedef struct
{ {
char title[64]; string title;
string previousTitle;
UINT previousCodePage;
UINT previousOutputCodePage;
HWND hWnd; HWND hWnd;
HANDLE hInput; HANDLE hInput;
HANDLE hOutput; HANDLE hOutput;
@ -45,6 +48,7 @@ typedef struct
string lineBuffer[COMMAND_HISTORY]; string lineBuffer[COMMAND_HISTORY];
qboolean inputEnabled; qboolean inputEnabled;
qboolean consoleVisible; qboolean consoleVisible;
qboolean attached;
// log stuff // log stuff
qboolean log_active; qboolean log_active;
@ -129,7 +133,7 @@ static void Wcon_PrintInternal( const char *msg, int length )
void Wcon_ShowConsole( qboolean show ) 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; return;
s_wcd.consoleVisible = show; s_wcd.consoleVisible = show;
@ -482,6 +486,7 @@ void Wcon_WinPrint( const char *pMsg )
Wcon_PrintInternal( s_wcd.consoleText, s_wcd.consoleTextLen ); Wcon_PrintInternal( s_wcd.consoleText, s_wcd.consoleTextLen );
} }
if( !s_wcd.attached )
Wcon_UpdateStatusLine(); Wcon_UpdateStatusLine();
} }
@ -509,7 +514,16 @@ void Wcon_CreateConsole( void )
s_wcd.log_active = true; // always make log s_wcd.log_active = true; // always make log
} }
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(); AllocConsole();
}
SetConsoleTitle( s_wcd.title ); SetConsoleTitle( s_wcd.title );
SetConsoleCP( CP_UTF8 ); SetConsoleCP( CP_UTF8 );
SetConsoleOutputCP( CP_UTF8 ); SetConsoleOutputCP( CP_UTF8 );
@ -525,6 +539,8 @@ void Wcon_CreateConsole( void )
return; return;
} }
if( !s_wcd.attached )
{
SetWindowPos( s_wcd.hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION | SWP_SHOWWINDOW ); SetWindowPos( s_wcd.hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION | SWP_SHOWWINDOW );
// show console if needed // show console if needed
@ -542,6 +558,7 @@ void Wcon_CreateConsole( void )
s_wcd.consoleVisible = false; s_wcd.consoleVisible = false;
ShowWindow( s_wcd.hWnd, SW_HIDE ); ShowWindow( s_wcd.hWnd, SW_HIDE );
} }
}
} }
/* /*
@ -573,11 +590,22 @@ void Wcon_DestroyConsole( void )
Sys_CloseLog(); Sys_CloseLog();
if( !s_wcd.attached )
{
if( s_wcd.hWnd ) if( s_wcd.hWnd )
{ {
ShowWindow( s_wcd.hWnd, SW_HIDE ); ShowWindow( s_wcd.hWnd, SW_HIDE );
s_wcd.hWnd = 0; s_wcd.hWnd = 0;
} }
}
else
{
// 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(); FreeConsole();
@ -595,8 +623,8 @@ returned input text
*/ */
char *Wcon_Input( void ) char *Wcon_Input( void )
{ {
int i; DWORD i;
int eventsCount; DWORD eventsCount;
static INPUT_RECORD events[1024]; static INPUT_RECORD events[1024];
if( !s_wcd.inputEnabled ) if( !s_wcd.inputEnabled )
@ -642,7 +670,7 @@ set server status string in console
*/ */
void Wcon_SetStatus( const char *pStatus ) void Wcon_SetStatus( const char *pStatus )
{ {
if( host.type != HOST_DEDICATED ) if( host.type != HOST_DEDICATED || s_wcd.attached )
return; return;
Q_strncpy( s_wcd.statusLine, pStatus, sizeof( s_wcd.statusLine ) - 1 ); Q_strncpy( s_wcd.statusLine, pStatus, sizeof( s_wcd.statusLine ) - 1 );

Loading…
Cancel
Save