1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 09:39:43 +01:00

Fix info args not working with -console

The intention of the `-console` argument was to enable seeing console
output on Windows without having to use workarounds. However, this
didn't actually work for arguments like `-addresses` and `-version`,
because the program would exit first before it could get the chance to
create the console.

The other issue is that the console closes too quickly before output can
be read by the user. So to fix that, we must hold it open and let the
user close it when they want to by waiting for an enter press from
STDIN.
This commit is contained in:
Misa 2024-06-02 11:09:22 -07:00 committed by Misa Elizabeth Kai
parent a9d43b543f
commit dd15d67e62
2 changed files with 80 additions and 32 deletions

View file

@ -220,6 +220,12 @@ void vlog_open_console(void)
vlog_error("Could not redirect STDERR to console.");
}
handle = freopen("CON", "r", stdin);
if (handle == NULL)
{
vlog_error("Could not redirect STDIN to console.");
}
check_color_support();
if (!SetConsoleOutputCP(CP_UTF8))

View file

@ -363,6 +363,23 @@ static void emscriptenloop(void)
}
#endif
static void keep_console_open(const bool open_console)
{
if (!open_console)
{
return;
}
printf("Press ENTER to quit.");
int c;
do
{
c = getchar();
}
while (c != '\n' && c != EOF);
}
int main(int argc, char *argv[])
{
char* baseDir = NULL;
@ -370,9 +387,11 @@ int main(int argc, char *argv[])
char* langDir = NULL;
char* fontsDir = NULL;
bool seed_use_sdl_getticks = false;
#ifdef _WIN32
bool open_console = false;
#endif
bool print_version = false;
bool print_addresses = false;
int invalid_arg = 0;
int invalid_partial_arg = 0;
vlog_init();
@ -386,41 +405,16 @@ int main(int argc, char *argv[])
} \
else \
{ \
vlog_error("%s option requires one argument.", argv[i]); \
VVV_exit(1); \
invalid_partial_arg = i; \
}
if (ARG("-version"))
{
/* Just print the version and exit. No vlogging. */
puts(
"VVVVVV " RELEASE_VERSION
#ifdef MAKEANDPLAY
" [M&P]"
#endif
);
#ifdef INTERIM_VERSION_EXISTS
puts(COMMIT_DATE);
puts(INTERIM_COMMIT);
puts(BRANCH_NAME);
#endif
VVV_exit(0);
print_version = true;
}
else if (ARG("-addresses"))
{
printf("cl : %p\n", (void*) &cl);
printf("ed : %p\n", (void*) &ed);
printf("game : %p\n", (void*) &game);
printf("gameScreen : %p\n", (void*) &gameScreen);
printf("graphics : %p\n", (void*) &graphics);
printf("help : %p\n", (void*) &help);
printf("key : %p\n", (void*) &key);
printf("map : %p\n", (void*) &map);
printf("music : %p\n", (void*) &music);
printf("obj : %p\n", (void*) &obj);
printf("script : %p\n", (void*) &script);
VVV_exit(0);
print_addresses = true;
}
else if (ARG("-renderer"))
{
@ -541,8 +535,7 @@ int main(int argc, char *argv[])
#undef ARG
else
{
vlog_error("Error: invalid option: %s", argv[i]);
VVV_exit(1);
invalid_arg = i;
}
}
@ -557,6 +550,54 @@ int main(int argc, char *argv[])
}
#endif
if (invalid_arg > 0)
{
vlog_error("Error: invalid option: %s", argv[invalid_arg]);
keep_console_open(open_console);
VVV_exit(1);
}
else if (invalid_partial_arg > 0)
{
vlog_error("%s option requires one argument.", argv[invalid_partial_arg]);
keep_console_open(open_console);
VVV_exit(1);
}
if (print_version)
{
/* Just print the version and exit. No vlogging. */
puts(
"VVVVVV " RELEASE_VERSION
#ifdef MAKEANDPLAY
" [M&P]"
#endif
);
#ifdef INTERIM_VERSION_EXISTS
puts(COMMIT_DATE);
puts(INTERIM_COMMIT);
puts(BRANCH_NAME);
#endif
keep_console_open(open_console);
VVV_exit(0);
}
else if (print_addresses)
{
printf("cl : %p\n", (void*) &cl);
printf("ed : %p\n", (void*) &ed);
printf("game : %p\n", (void*) &game);
printf("gameScreen : %p\n", (void*) &gameScreen);
printf("graphics : %p\n", (void*) &graphics);
printf("help : %p\n", (void*) &help);
printf("key : %p\n", (void*) &key);
printf("map : %p\n", (void*) &map);
printf("music : %p\n", (void*) &music);
printf("obj : %p\n", (void*) &obj);
printf("script : %p\n", (void*) &script);
keep_console_open(open_console);
VVV_exit(0);
}
SDL_SetHintWithPriority(SDL_HINT_IME_SHOW_UI, "1", SDL_HINT_OVERRIDE);
/* We already do the button swapping in ButtonGlyphs, disable SDL's swapping */
@ -774,6 +815,7 @@ int main(int argc, char *argv[])
cl.ListOfMetaData.push_back(meta);
} else {
vlog_error("Level not found");
keep_console_open(open_console);
VVV_exit(1);
}
}