mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-23 23:04:36 +01:00
improve command line parsing
This commit is contained in:
@@ -22,15 +22,28 @@
|
||||
#ifdef _MSC_VER
|
||||
#include <time.h>
|
||||
#endif
|
||||
#include <argparse/argparse.h>
|
||||
#include "addresses.h"
|
||||
#include "cmdline.h"
|
||||
#include "openrct2.h"
|
||||
#include "platform/osinterface.h"
|
||||
|
||||
typedef struct tm tm_t;
|
||||
typedef struct argparse_option argparse_option_t;
|
||||
typedef struct argparse argparse_t;
|
||||
|
||||
int gExitCode = 0;
|
||||
|
||||
static void print_launch_information();
|
||||
|
||||
static const char *const usage[] = {
|
||||
"openrct2 <command> [options] [<args>]",
|
||||
"openrct2 <path> [options]",
|
||||
"openrct2 intro [options]",
|
||||
"openrct2 edit [path] [options]",
|
||||
NULL
|
||||
};
|
||||
|
||||
/**
|
||||
* A shared entry point to OpenRCT2. The command lines must be parsed before any further action is done. Invalid command lines
|
||||
* will then terminate before any initialisation has even been done.
|
||||
@@ -38,19 +51,49 @@ static void print_launch_information();
|
||||
*/
|
||||
int cmdline_run(char *argv[], int argc)
|
||||
{
|
||||
print_launch_information();
|
||||
// For argparse's sake, add virtual first argument process path
|
||||
argc++;
|
||||
argv--;
|
||||
|
||||
if (argc > 0) {
|
||||
if (_stricmp(argv[0], "edit") == 0) {
|
||||
//
|
||||
int version = 0, width = 0, height = 0;
|
||||
|
||||
argparse_option_t options[] = {
|
||||
OPT_HELP(),
|
||||
OPT_BOOLEAN('v', "version", &version, "show version information and exit"),
|
||||
OPT_END()
|
||||
};
|
||||
|
||||
argparse_t argparse;
|
||||
argparse_init(&argparse, options, usage, 0);
|
||||
argc = argparse_parse(&argparse, argc, argv);
|
||||
|
||||
if (version) {
|
||||
printf("%s v%s\n", OPENRCT2_NAME, OPENRCT2_VERSION);
|
||||
printf("%s (%s)\n", OPENRCT2_PLATFORM, OPENRCT2_ARCHITECTURE);
|
||||
printf("%s\n", OPENRCT2_TIMESTAMP);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argc != 0) {
|
||||
if (_stricmp(argv[0], "intro") == 0) {
|
||||
gOpenRCT2StartupAction = STARTUP_ACTION_INTRO;
|
||||
} else if (_stricmp(argv[0], "edit") == 0) {
|
||||
gOpenRCT2StartupAction = STARTUP_ACTION_EDIT;
|
||||
if (argc >= 2)
|
||||
strcpy(gOpenRCT2StartupActionPath, argv[1]);
|
||||
} else {
|
||||
gOpenRCT2StartupAction = STARTUP_ACTION_OPEN;
|
||||
strcpy(gOpenRCT2StartupActionPath, argv[0]);
|
||||
if (osinterface_file_exists(argv[0])) {
|
||||
gOpenRCT2StartupAction = STARTUP_ACTION_OPEN;
|
||||
strcpy(gOpenRCT2StartupActionPath, argv[0]);
|
||||
} else {
|
||||
fprintf(stderr, "error: %s does not exist\n", argv[0]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print_launch_information();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -72,28 +115,4 @@ static void print_launch_information()
|
||||
printf("Time: %s\n", buffer);
|
||||
|
||||
// TODO Print other potential information (e.g. user, hardware)
|
||||
}
|
||||
|
||||
//void check_cmdline_arg()
|
||||
//{
|
||||
// int argc;
|
||||
// char **argv;
|
||||
// char *args;
|
||||
//
|
||||
// args = RCT2_GLOBAL(0x009AC310, char*);
|
||||
// if (args == (char*)0xFFFFFFFF)
|
||||
// return;
|
||||
// RCT2_GLOBAL(0x009AC310, char*) = (char*)0xFFFFFFFF;
|
||||
//
|
||||
// argv = CommandLineToArgvA(args, &argc);
|
||||
// if (argc > 0) {
|
||||
// if (_stricmp(argv[0], "edit") == 0) {
|
||||
// if (argc >= 1)
|
||||
// editor_load_landscape(argv[1]);
|
||||
// } else {
|
||||
// rct2_open_file(argv[0]);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// LocalFree(argv);
|
||||
//}
|
||||
}
|
||||
32
src/config.c
32
src/config.c
@@ -74,21 +74,23 @@ static const uint16 _defaultShortcutKeys[SHORTCUT_COUNT] = {
|
||||
|
||||
general_configuration_t gGeneral_config;
|
||||
general_configuration_t gGeneral_config_default = {
|
||||
0, // play_intro
|
||||
1, // confirmation_prompt
|
||||
SCREENSHOT_FORMAT_PNG, // screenshot_format
|
||||
"", // game_path
|
||||
MEASUREMENT_FORMAT_IMPERIAL, // measurement_format
|
||||
TEMPERATURE_FORMAT_F, // temperature_format
|
||||
CURRENCY_POUNDS, // currency_format
|
||||
0, // construction_marker_colour
|
||||
1, // edge_scrolling
|
||||
0, // always_show_gridlines
|
||||
1, // landscape_smoothing
|
||||
0, // show_height_as_units
|
||||
1, // save_plugin_data
|
||||
0, // fullscreen mode (default: windowed)
|
||||
LANGUAGE_ENGLISH_UK
|
||||
0, // play_intro
|
||||
1, // confirmation_prompt
|
||||
SCREENSHOT_FORMAT_PNG, // screenshot_format
|
||||
"", // game_path
|
||||
MEASUREMENT_FORMAT_IMPERIAL, // measurement_format
|
||||
TEMPERATURE_FORMAT_F, // temperature_format
|
||||
CURRENCY_POUNDS, // currency_format
|
||||
0, // construction_marker_colour
|
||||
1, // edge_scrolling
|
||||
0, // always_show_gridlines
|
||||
1, // landscape_smoothing
|
||||
0, // show_height_as_units
|
||||
1, // save_plugin_data
|
||||
0, // fullscreen mode (default: windowed)
|
||||
-1, // window_width
|
||||
-1, // window_height
|
||||
LANGUAGE_ENGLISH_UK // language
|
||||
};
|
||||
sound_configuration_t gSound_config;
|
||||
|
||||
|
||||
@@ -130,6 +130,8 @@ typedef struct general_configuration {
|
||||
|
||||
//new
|
||||
uint8 fullscreen_mode;
|
||||
sint16 window_width;
|
||||
sint16 window_height;
|
||||
uint16 language;
|
||||
} general_configuration_t;
|
||||
|
||||
|
||||
@@ -59,8 +59,6 @@ void openrct2_launch()
|
||||
|
||||
RCT2_GLOBAL(RCT2_ADDRESS_RUN_INTRO_TICK_PART, uint8) = 0;
|
||||
RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) = SCREEN_FLAGS_PLAYING;
|
||||
|
||||
// TODO fix, crashes on first game logic update
|
||||
break;
|
||||
case STARTUP_ACTION_EDIT:
|
||||
if (strlen(gOpenRCT2StartupActionPath) == 0)
|
||||
|
||||
@@ -178,11 +178,11 @@ static void osinterface_create_window()
|
||||
osinterface_load_cursors();
|
||||
RCT2_CALLPROC_EBPSAFE(0x0068371D);
|
||||
|
||||
width = RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_RESOLUTION_WIDTH, sint16);
|
||||
height = RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_RESOLUTION_HEIGHT, sint16);
|
||||
width = gGeneral_config.window_width;
|
||||
height = gGeneral_config.window_height;
|
||||
|
||||
width = 640;
|
||||
height = 480;
|
||||
if (width == -1) width = 640;
|
||||
if (height == -1) height = 480;
|
||||
}
|
||||
|
||||
RCT2_GLOBAL(0x009E2D8C, sint32) = 0;
|
||||
|
||||
@@ -226,16 +226,19 @@ int rct2_open_file(const char *path)
|
||||
return 0;
|
||||
extension++;
|
||||
|
||||
if (_stricmp(extension, "sv6")) {
|
||||
if (_stricmp(extension, "sv6") == 0) {
|
||||
game_load_save(path);
|
||||
} else if (!_stricmp(extension, "sc6")) {
|
||||
return 1;
|
||||
} else if (_stricmp(extension, "sc6") == 0) {
|
||||
// TODO scenario install
|
||||
rct_scenario_basic scenarioBasic;
|
||||
strcpy(scenarioBasic.path, path);
|
||||
scenario_load_and_play_from_path(scenarioBasic.path);
|
||||
} else if (!_stricmp(extension, "td6") || !_stricmp(extension, "td4")) {
|
||||
} else if (_stricmp(extension, "td6") == 0 || _stricmp(extension, "td4") == 0) {
|
||||
// TODO track design install
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// rct2: 0x00407DB0
|
||||
|
||||
@@ -318,6 +318,8 @@ int scenario_load_and_play_from_path(const char *path)
|
||||
gfx_invalidate_screen();
|
||||
RCT2_GLOBAL(0x009DEA66, uint16) = 0;
|
||||
RCT2_GLOBAL(0x009DEA5C, uint16) = 62000; // (doesn't appear to ever be read)
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user