From e1b67eeda088d59b94db40c59b0eb35b5e44a998 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 8 Nov 2015 12:49:19 +0000 Subject: [PATCH] improve command line version information and add headless check --- src/cmdline.c | 40 +++++++++++++++++++++++++++++++--------- src/input.c | 4 ++++ src/openrct2.c | 24 ++++++++++++++++++++++++ src/openrct2.h | 1 + src/title.c | 20 +++++--------------- 5 files changed, 65 insertions(+), 24 deletions(-) diff --git a/src/cmdline.c b/src/cmdline.c index 49f8c4adaa..9f7a45427d 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -53,6 +53,7 @@ int gNetworkStartPort = NETWORK_DEFAULT_PORT; #endif // DISABLE_NETWORK static void print_launch_information(); +static void print_version(); static int cmdline_call_action(const char **argv, int argc); static const char *const usage[] = { @@ -92,7 +93,7 @@ int cmdline_run(const char **argv, int argc) argc = argparse_parse(&argparse, argc, argv); if (version) { - print_launch_information(); + print_version(); return 0; } @@ -120,34 +121,55 @@ int cmdline_run(const char **argv, int argc) if (argc != 0) { gExitCode = cmdline_call_action(argv, argc); - if (gExitCode != 0) + if (gExitCode != 0) { return 0; + } } - print_launch_information(); + // Headless mode requires a park to open + if (gOpenRCT2Headless) { + if (str_is_null_or_empty(gOpenRCT2StartupActionPath)) { + printf("You must specify a park to open in headless mode.\n"); + gExitCode = -1; + return 0; + } + } + + if (verbose) { + print_launch_information(); + } return 1; } static void print_launch_information() { - char buffer[32]; + char buffer[256]; time_t timer; tm_t* tmInfo; - // Print version information - printf("Starting %s v%s\n", OPENRCT2_NAME, OPENRCT2_VERSION); - printf(" %s (%s)\n", OPENRCT2_PLATFORM, OPENRCT2_ARCHITECTURE); - printf(" %s\n\n", OPENRCT2_TIMESTAMP); + // Print name and version information + openrct2_write_full_version_info(buffer, sizeof(buffer)); + printf("%s\n", buffer); + printf("%s (%s)\n", OPENRCT2_PLATFORM, OPENRCT2_ARCHITECTURE); + printf("@ %s\n\n", OPENRCT2_TIMESTAMP); // Print current time time(&timer); tmInfo = localtime(&timer); strftime(buffer, sizeof(buffer), "%Y/%m/%d %H:%M:%S", tmInfo); - printf("Time: %s\n", buffer); + printf("VERBOSE: time is %s\n", buffer); // TODO Print other potential information (e.g. user, hardware) } +static void print_version() +{ + char buffer[256]; + openrct2_write_full_version_info(buffer, sizeof(buffer)); + printf("%s\n", buffer); + printf("%s (%s)\n", OPENRCT2_PLATFORM, OPENRCT2_ARCHITECTURE); +} + static int cmdline_for_intro(const char **argv, int argc) { gOpenRCT2StartupAction = STARTUP_ACTION_INTRO; diff --git a/src/input.c b/src/input.c index cee459a73f..b8752736b9 100644 --- a/src/input.c +++ b/src/input.c @@ -1292,6 +1292,10 @@ void title_handle_keyboard_input() rct_window *w; int key; + if (gOpenRCT2Headless) { + return; + } + if (!gConsoleOpen) { // Handle modifier keys and key scrolling RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) = 0; diff --git a/src/openrct2.c b/src/openrct2.c index 60254b563c..483f0533f2 100644 --- a/src/openrct2.c +++ b/src/openrct2.c @@ -76,6 +76,30 @@ static bool openrct2_setup_rct2_segment(); static bool openrct2_release_rct2_segment(); static void openrct2_setup_rct2_hooks(); +void openrct2_write_full_version_info(utf8 *buffer, size_t bufferSize) +{ + utf8 *ch = buffer; + + // Name and version + strcpy(ch, OPENRCT2_NAME); + strcat(buffer, ", v"); + strcat(buffer, OPENRCT2_VERSION); + + // Build information + if (!str_is_null_or_empty(OPENRCT2_BRANCH)) { + sprintf(strchr(buffer, 0), "-%s", OPENRCT2_BRANCH); + } + if (!str_is_null_or_empty(OPENRCT2_BUILD_NUMBER)) { + sprintf(strchr(buffer, 0), " build %s", OPENRCT2_BUILD_NUMBER); + } + if (!str_is_null_or_empty(OPENRCT2_COMMIT_SHA1_SHORT)) { + sprintf(strchr(buffer, 0), " (%s)", OPENRCT2_COMMIT_SHA1_SHORT); + } + if (!str_is_null_or_empty(OPENRCT2_BUILD_SERVER)) { + sprintf(strchr(buffer, 0), " provided by %s", OPENRCT2_BUILD_SERVER); + } +} + static void openrct2_copy_files_over(const utf8 *originalDirectory, const utf8 *newDirectory, const utf8 *extension) { utf8 *ch, filter[MAX_PATH], oldPath[MAX_PATH], newPath[MAX_PATH]; diff --git a/src/openrct2.h b/src/openrct2.h index 73fe12f0e8..4642985872 100644 --- a/src/openrct2.h +++ b/src/openrct2.h @@ -37,6 +37,7 @@ extern utf8 gCustomUserDataPath[MAX_PATH]; extern bool gOpenRCT2Headless; extern bool gOpenRCT2ShowChangelog; +void openrct2_write_full_version_info(utf8 *buffer, size_t bufferSize); bool openrct2_initialise(); void openrct2_launch(); void openrct2_dispose(); diff --git a/src/title.c b/src/title.c index 87bf86ca92..56bb9e1265 100644 --- a/src/title.c +++ b/src/title.c @@ -460,30 +460,20 @@ static void title_update_showcase() void DrawOpenRCT2(int x, int y) { - char buffer[256]; + utf8 buffer[256]; rct_drawpixelinfo *dpi = RCT2_ADDRESS(RCT2_ADDRESS_SCREEN_DPI, rct_drawpixelinfo); // Draw background gfx_fill_rect_inset(dpi, x, y, x + 128, y + 20, 0x80 | 12, 0x8); - // Format text (name and version) - char *ch = buffer;; + // Write format codes + utf8 *ch = buffer; ch = utf8_write_codepoint(ch, FORMAT_MEDIUMFONT); ch = utf8_write_codepoint(ch, FORMAT_OUTLINE); ch = utf8_write_codepoint(ch, FORMAT_WHITE); - strcpy(ch, OPENRCT2_NAME); - strcat(buffer, ", v"); - strcat(buffer, OPENRCT2_VERSION); - // sprintf(buffer, "%c%c%c%s, v%s", FORMAT_MEDIUMFONT, FORMAT_OUTLINE, FORMAT_WHITE, OPENRCT2_NAME, OPENRCT2_VERSION); - if (!str_is_null_or_empty(OPENRCT2_BRANCH)) - sprintf(strchr(buffer, 0), "-%s", OPENRCT2_BRANCH); - if (!str_is_null_or_empty(OPENRCT2_BUILD_NUMBER)) - sprintf(strchr(buffer, 0), " build %s", OPENRCT2_BUILD_NUMBER); - if (!str_is_null_or_empty(OPENRCT2_COMMIT_SHA1_SHORT)) - sprintf(strchr(buffer, 0), " (%s)", OPENRCT2_COMMIT_SHA1_SHORT); - if (!str_is_null_or_empty(OPENRCT2_BUILD_SERVER)) - sprintf(strchr(buffer, 0), " provided by %s", OPENRCT2_BUILD_SERVER); + // Write name and version information + openrct2_write_full_version_info(ch, sizeof(buffer) - (ch - buffer)); // Draw Text gfx_draw_string(dpi, buffer, 0, x + 5, y + 5);