Skip to content

Commit eefdd83

Browse files
committed
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
1 parent 09b1ede commit eefdd83

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

neo/sys/win32/win_main.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,10 +1090,22 @@ static void redirect_output(void)
10901090
}
10911091
if (_stat(myGamesPath, &st) == -1) {
10921092
/* if My Documents/My Games/ doesn't exist, create it */
1093-
_mkdir(myGamesPath);
1093+
if( _mkdir(myGamesPath) != 0 && errno != EEXIST ) {
1094+
char msg[2048];
1095+
D3_snprintfC99( msg, sizeof(msg), "Failed to create '%s',\n error number is %d (%s).\nPermission problem?",
1096+
myGamesPath, errno, strerror(errno) );
1097+
MessageBox( NULL, msg, "Can't create 'My Games' directory!", MB_OK | MB_ICONERROR );
1098+
exit(1);
1099+
}
1100+
}
1101+
/* create My Documents/My Games/dhewm3/ */
1102+
if( _mkdir(path) != 0 && errno != EEXIST ) {
1103+
char msg[2048];
1104+
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?",
1105+
path, errno, strerror(errno) );
1106+
MessageBox( NULL, msg, "Can't create 'My Games/dhewm3' directory!", MB_OK | MB_ICONERROR );
1107+
exit(1);
10941108
}
1095-
1096-
_mkdir(path); /* create My Documents/My Games/dhewm3/ */
10971109
}
10981110

10991111
FILE *newfp;
@@ -1127,6 +1139,12 @@ static void redirect_output(void)
11271139
newfp = fopen(stdoutPath, TEXT("w"));
11281140
if ( newfp ) {
11291141
*stdout = *newfp;
1142+
} else {
1143+
char msg[2048];
1144+
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?",
1145+
stdoutPath, errno, strerror(errno) );
1146+
MessageBox( NULL, msg, "Can't create dhewm3log.txt!", MB_OK | MB_ICONERROR );
1147+
exit(1);
11301148
}
11311149
#endif
11321150
}
@@ -1142,6 +1160,12 @@ static void redirect_output(void)
11421160
newfp = fopen(stderrPath, TEXT("w"));
11431161
if ( newfp ) {
11441162
*stderr = *newfp;
1163+
} else {
1164+
char msg[2048];
1165+
D3_snprintfC99( msg, sizeof(msg), "Failed to create '%s',\n error number is %d (%s)\nIs Documents/My Games/dhewm3/ write protected?",
1166+
stdoutPath, errno, strerror(errno) );
1167+
MessageBox( NULL, msg, "Can't create stderr.txt!", MB_OK | MB_ICONERROR );
1168+
exit(1);
11451169
}
11461170
#endif
11471171
}

0 commit comments

Comments
 (0)