Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for older VS versions, make sure dhewm3log.txt was created on Windows #642

Merged
merged 2 commits into from
Jan 18, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
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
  • Loading branch information
DanielGibson committed Jan 18, 2025
commit 0434b08f62e3766661f4f3ae386f19482e98920a
30 changes: 27 additions & 3 deletions neo/sys/win32/win_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
Expand All @@ -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) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy-paste error, wrong variable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good find!

MessageBox( NULL, msg, "Can't create stderr.txt!", MB_OK | MB_ICONERROR );
exit(1);
}
#endif
}
Expand Down