mirror of
https://github.com/OpenRCT2/OpenRCT2.git
synced 2025-01-22 10:21:57 -05:00
Add --console switch for Windows
Windows subsystem does not work like console subsystem which makes it almost impossible to obtain `stdout` until the application has finished. This adds a `--console` switch to make the game either attach to an existing console or show a new one and redirect the C streams to it.
This commit is contained in:
parent
667dd526e9
commit
7611b04ad1
4 changed files with 38 additions and 23 deletions
|
@ -30,10 +30,26 @@ extern "C"
|
|||
#include "../network/network.h"
|
||||
#include "CommandLine.hpp"
|
||||
|
||||
#ifdef USE_BREAKPAD
|
||||
#define IMPLIES_SILENT_BREAKPAD ", implies --silent-breakpad"
|
||||
#else
|
||||
#define IMPLIES_SILENT_BREAKPAD
|
||||
#endif // USE_BREAKPAD
|
||||
|
||||
#if defined(__WINDOWS__) && !defined(DEBUG)
|
||||
#define __PROVIDE_CONSOLE__ 1
|
||||
#endif // defined(__WINDOWS__) && !defined(DEBUG)
|
||||
|
||||
#ifndef DISABLE_NETWORK
|
||||
int gNetworkStart = NETWORK_MODE_NONE;
|
||||
char gNetworkStartHost[128];
|
||||
int gNetworkStartPort = NETWORK_DEFAULT_PORT;
|
||||
|
||||
static uint32 _port = 0;
|
||||
#endif
|
||||
|
||||
#ifdef __PROVIDE_CONSOLE__
|
||||
static bool _provideConsole;
|
||||
#endif
|
||||
|
||||
static bool _help = false;
|
||||
|
@ -43,21 +59,12 @@ static bool _all = false;
|
|||
static bool _about = false;
|
||||
static bool _verbose = false;
|
||||
static bool _headless = false;
|
||||
#ifndef DISABLE_NETWORK
|
||||
static uint32 _port = 0;
|
||||
#endif
|
||||
static utf8 * _password = nullptr;
|
||||
static utf8 * _userDataPath = nullptr;
|
||||
static utf8 * _openrctDataPath = nullptr;
|
||||
static utf8 * _rct2DataPath = nullptr;
|
||||
static bool _silentBreakpad = false;
|
||||
|
||||
#ifdef USE_BREAKPAD
|
||||
#define IMPLIES_SILENT_BREAKPAD ", implies --silent-breakpad"
|
||||
#else
|
||||
#define IMPLIES_SILENT_BREAKPAD
|
||||
#endif // USE_BREAKPAD
|
||||
|
||||
static const CommandLineOptionDefinition StandardOptions[]
|
||||
{
|
||||
{ CMDLINE_TYPE_SWITCH, &_help, 'h', "help", "show this help message and exit" },
|
||||
|
@ -67,6 +74,9 @@ static const CommandLineOptionDefinition StandardOptions[]
|
|||
{ CMDLINE_TYPE_SWITCH, &_about, NAC, "about", "show information about " OPENRCT2_NAME },
|
||||
{ CMDLINE_TYPE_SWITCH, &_verbose, NAC, "verbose", "log verbose messages" },
|
||||
{ CMDLINE_TYPE_SWITCH, &_headless, NAC, "headless", "run " OPENRCT2_NAME " headless" IMPLIES_SILENT_BREAKPAD },
|
||||
#ifdef __PROVIDE_CONSOLE__
|
||||
{ CMDLINE_TYPE_SWITCH, &_provideConsole, NAC, "console", "creates a new or attaches to an existing console window for standard output" },
|
||||
#endif
|
||||
#ifndef DISABLE_NETWORK
|
||||
{ CMDLINE_TYPE_INTEGER, &_port, NAC, "port", "port to use for hosting or joining a server" },
|
||||
#endif
|
||||
|
@ -144,6 +154,13 @@ exitcode_t CommandLine::HandleCommandDefault()
|
|||
{
|
||||
exitcode_t result = EXITCODE_CONTINUE;
|
||||
|
||||
#ifdef __PROVIDE_CONSOLE__
|
||||
if (_provideConsole)
|
||||
{
|
||||
platform_windows_open_console();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (_about)
|
||||
{
|
||||
PrintAbout();
|
||||
|
|
|
@ -661,17 +661,3 @@ static void openrct2_setup_rct2_hooks()
|
|||
{
|
||||
// None for now
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1900)
|
||||
/**
|
||||
* Temporary fix for libraries not compiled with VS2015
|
||||
*/
|
||||
FILE **__iob_func()
|
||||
{
|
||||
static FILE* streams[3];
|
||||
streams[0] = stdin;
|
||||
streams[1] = stdout;
|
||||
streams[2] = stderr;
|
||||
return streams;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -203,6 +203,7 @@ datetime64 platform_get_datetime_now_utc();
|
|||
#include <windows.h>
|
||||
#undef GetMessage
|
||||
|
||||
void platform_windows_open_console();
|
||||
int windows_get_registry_install_info(rct2_install_info *installInfo, char *source, char *font, uint8 charset);
|
||||
HWND windows_get_window_handle();
|
||||
void platform_setup_file_associations();
|
||||
|
|
|
@ -143,6 +143,17 @@ __declspec(dllexport) int StartOpenRCT(HINSTANCE hInstance, HINSTANCE hPrevInsta
|
|||
|
||||
#endif // NO_RCT2
|
||||
|
||||
void platform_windows_open_console()
|
||||
{
|
||||
if (!AttachConsole(ATTACH_PARENT_PROCESS)) {
|
||||
AllocConsole();
|
||||
}
|
||||
|
||||
freopen("CONIN$", "r", stdin);
|
||||
freopen("CONOUT$", "w", stdout);
|
||||
freopen("CONOUT$", "w", stderr);
|
||||
}
|
||||
|
||||
utf8 **windows_get_command_line_args(int *outNumArgs)
|
||||
{
|
||||
int argc;
|
||||
|
|
Loading…
Reference in a new issue