From eefdd8343ea68e5e3a1335c99ba00bf8dfe40a31 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sat, 18 Jan 2025 23:38:56 +0100 Subject: [PATCH] Win32: Make sure dhewm3log.txt can be created If it (or Documents/My Games/dhewm3/) can't be created, show a windows MessageBox with an error message and exit. Would've made #544 easier to figure out --- neo/sys/win32/win_main.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/neo/sys/win32/win_main.cpp b/neo/sys/win32/win_main.cpp index 72072a6d..2c8929ec 100644 --- a/neo/sys/win32/win_main.cpp +++ b/neo/sys/win32/win_main.cpp @@ -1090,10 +1090,22 @@ static void redirect_output(void) } if (_stat(myGamesPath, &st) == -1) { /* if My Documents/My Games/ doesn't exist, create it */ - _mkdir(myGamesPath); + if( _mkdir(myGamesPath) != 0 && errno != EEXIST ) { + char msg[2048]; + D3_snprintfC99( msg, sizeof(msg), "Failed to create '%s',\n error number is %d (%s).\nPermission problem?", + myGamesPath, errno, strerror(errno) ); + MessageBox( NULL, msg, "Can't create 'My Games' directory!", MB_OK | MB_ICONERROR ); + exit(1); + } + } + /* create My Documents/My Games/dhewm3/ */ + if( _mkdir(path) != 0 && errno != EEXIST ) { + char msg[2048]; + D3_snprintfC99( msg, sizeof(msg), "Failed to create '%s'\n(for savegames, configs and logs),\n error number is %d (%s)\nIs Documents/My Games/ write protected?", + path, errno, strerror(errno) ); + MessageBox( NULL, msg, "Can't create 'My Games/dhewm3' directory!", MB_OK | MB_ICONERROR ); + exit(1); } - - _mkdir(path); /* create My Documents/My Games/dhewm3/ */ } FILE *newfp; @@ -1127,6 +1139,12 @@ static void redirect_output(void) newfp = fopen(stdoutPath, TEXT("w")); if ( newfp ) { *stdout = *newfp; + } else { + char msg[2048]; + D3_snprintfC99( msg, sizeof(msg), "Failed to create '%s',\n error number is %d (%s)\nIs Documents/My Games/dhewm3/\n or dhewm3log.txt write protected?", + stdoutPath, errno, strerror(errno) ); + MessageBox( NULL, msg, "Can't create dhewm3log.txt!", MB_OK | MB_ICONERROR ); + exit(1); } #endif } @@ -1142,6 +1160,12 @@ static void redirect_output(void) newfp = fopen(stderrPath, TEXT("w")); if ( newfp ) { *stderr = *newfp; + } else { + char msg[2048]; + D3_snprintfC99( msg, sizeof(msg), "Failed to create '%s',\n error number is %d (%s)\nIs Documents/My Games/dhewm3/ write protected?", + stdoutPath, errno, strerror(errno) ); + MessageBox( NULL, msg, "Can't create stderr.txt!", MB_OK | MB_ICONERROR ); + exit(1); } #endif }