From 01625455d975f05d41f051d0256cf4ae32f154e2 Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 8 Dec 2018 21:17:34 -0500 Subject: [PATCH] more startup tweaking for Windows --- sys/winnt/windmain.c | 34 +++++++++++++++++++++------------- sys/winnt/winnt.c | 8 ++++---- win/win32/winhack.c | 4 +++- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/sys/winnt/windmain.c b/sys/winnt/windmain.c index 9768a8e6f..72bf24c11 100644 --- a/sys/winnt/windmain.c +++ b/sys/winnt/windmain.c @@ -241,16 +241,20 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/ Strcpy(hackdir, dir); } if (argc > 1) { +#if 0 #if !defined(TTY_GRAPHICS) int sfd = 0; boolean tmpconsole = FALSE; hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); #endif +#endif /* 0 */ + /* * Now we know the directory containing 'record' and * may do a prscore(). */ if (!strncmp(argv[1], "-s", 2)) { +#if 0 #if !defined(TTY_GRAPHICS) /* * Check to see if we're redirecting to a file. @@ -264,11 +268,13 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/ nethack_exit(EXIT_SUCCESS); } #endif +#endif /* 0 */ #ifdef SYSCF initoptions(); #endif prscore(argc, argv); +#if 0 #if !defined(TTY_GRAPHICS) if (tmpconsole) { getreturn("to exit"); @@ -276,25 +282,26 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/ tmpconsole = FALSE; } #endif +#endif /* 0 */ nethack_exit(EXIT_SUCCESS); } - -#if defined(MSWIN_GRAPHICS) - if (!strncmpi(argv[1], "-clearreg", 6)) { /* clear registry */ - mswin_destroy_reg(); - nethack_exit(EXIT_SUCCESS); + if (GUILaunched) { + if (!strncmpi(argv[1], "-clearreg", 6)) { /* clear registry */ + mswin_destroy_reg(); + nethack_exit(EXIT_SUCCESS); + } } -#endif - /* Don't initialize the window system just to print usage */ + /* Don't initialize the full window system just to print usage */ if (!strncmp(argv[1], "-?", 2) || !strncmp(argv[1], "/?", 2)) { nhusage(); - +#if 0 #if !defined(TTY_GRAPHICS) if (tmpconsole) { getreturn("to exit"); freefakeconsole(); tmpconsole = FALSE; } +#endif #endif nethack_exit(EXIT_SUCCESS); } @@ -313,18 +320,19 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/ if (argc >= 1 && !strcmpi(default_window_sys, "mswin") - && strstri(argv[0], "nethackw.exe")) + && (strstri(argv[0], "nethackw.exe") || GUILaunched)) iflags.windowtype_locked = TRUE; + if (!iflags.windowtype_locked) { #if defined(TTY_GRAPHICS) - if (!iflags.windowtype_locked) Strcpy(default_window_sys, "tty"); #else #if defined(CURSES_GRAPHICS) - if (!iflags.windowtype_locked) Strcpy(default_window_sys, "curses"); -#endif -#endif +#endif /* CURSES */ +#endif /* TTY */ + } + choose_windows(default_window_sys); if (!dlb_init()) { pline( diff --git a/sys/winnt/winnt.c b/sys/winnt/winnt.c index f5121bddc..c5c214f19 100644 --- a/sys/winnt/winnt.c +++ b/sys/winnt/winnt.c @@ -495,12 +495,12 @@ void nhassert_failed(const char * exp, const char * file, int line) error(message); } -/* nethack_enter_winnt() is the first thing called from main */ +/* nethack_enter_winnt() is called from main immediately after + initializing the window port */ void nethack_enter_winnt() { -#ifdef TTY_GRAPHICS - nethack_enter_nttty(); -#endif + if (WINDOWPORT("tty")) + nethack_enter_nttty(); } /* CP437 to Unicode mapping according to the Unicode Consortium */ diff --git a/win/win32/winhack.c b/win/win32/winhack.c index 6796a5ce6..c6941d7c0 100644 --- a/win/win32/winhack.c +++ b/win/win32/winhack.c @@ -63,6 +63,8 @@ _nhapply_image_transparent(HDC hDC, int x, int y, int width, int height, // Global Variables: NHWinApp _nethack_app; +extern int GUILaunched; /* We tell shared startup code in windmain.c + that the GUI was launched via this */ #ifdef __BORLANDC__ #define _stricmp(s1, s2) stricmp(s1, s2) @@ -233,7 +235,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, } free(savefile); } - + GUILaunched = 1; /* let main do the argument processing */ (void) main(argc, argv); return 0; -- 2.40.0