mirror of
https://github.com/dhewm/dhewm3.git
synced 2025-03-21 02:01:03 +00:00
Windows: Don't put stdout.txt and stderr.txt into binary dir
It might not be writable.. which will cause game startup to fail. Put them in My Documents/My Games/dhewm3/ instead, like the save games.
This commit is contained in:
parent
fa363ab5ef
commit
6a507c6a5b
2 changed files with 48 additions and 14 deletions
|
@ -10,6 +10,8 @@
|
|||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef _WIN32_WCE
|
||||
# define DIR_SEPERATOR TEXT("\\")
|
||||
# undef _getcwd
|
||||
|
@ -195,22 +197,50 @@ static void cleanup_output(void) {
|
|||
}
|
||||
}
|
||||
|
||||
extern int Sys_GetHomeDir(char *dst, size_t size);
|
||||
|
||||
/* Redirect the output (stdout and stderr) to a file */
|
||||
static void redirect_output(void)
|
||||
{
|
||||
DWORD pathlen;
|
||||
#ifdef _WIN32_WCE
|
||||
wchar_t path[MAX_PATH];
|
||||
#error "adapt homedir code for wchar_t!"
|
||||
#else
|
||||
char path[MAX_PATH];
|
||||
struct _stat st;
|
||||
|
||||
// DG: use "My Documents/My Games/dhewm3" to write stdout.txt and stderr.txt
|
||||
// instead of the binary, which might not be writable
|
||||
Sys_GetHomeDir(path, sizeof(path));
|
||||
|
||||
if (_stat(path, &st) == -1) {
|
||||
// oops, "My Documents/My Games/dhewm3" doesn't exist - does My Games/ at least exist?
|
||||
char myGamesPath[MAX_PATH];
|
||||
memcpy(myGamesPath, path, MAX_PATH);
|
||||
char* lastslash = strrchr(myGamesPath, '/');
|
||||
if (lastslash != NULL) {
|
||||
*lastslash = '\0';
|
||||
}
|
||||
if (_stat(myGamesPath, &st) == -1) {
|
||||
// if My Documents/My Games/ doesn't exist, create it
|
||||
_mkdir(myGamesPath);
|
||||
}
|
||||
|
||||
_mkdir(path); // create My Documents/My Games/dhewm3/
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
FILE *newfp;
|
||||
|
||||
#if 0 // DG: don't do this anymore.
|
||||
DWORD pathlen;
|
||||
pathlen = GetModuleFileName(NULL, path, SDL_arraysize(path));
|
||||
while ( pathlen > 0 && path[pathlen] != '\\' ) {
|
||||
--pathlen;
|
||||
}
|
||||
path[pathlen] = '\0';
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32_WCE
|
||||
wcsncpy( stdoutPath, path, SDL_arraysize(stdoutPath) );
|
||||
|
|
|
@ -283,21 +283,23 @@ Based on (with kind permission) Yamagi Quake II's Sys_GetHomeDir()
|
|||
Returns the number of characters written to dst
|
||||
==============
|
||||
*/
|
||||
static int GetHomeDir(char *dst, size_t size)
|
||||
{
|
||||
int len;
|
||||
WCHAR profile[MAX_OSPATH];
|
||||
extern "C" { // DG: I need this in SDL_win32_main.c
|
||||
int Sys_GetHomeDir(char *dst, size_t size)
|
||||
{
|
||||
int len;
|
||||
WCHAR profile[MAX_OSPATH];
|
||||
|
||||
/* Get the path to "My Documents" directory */
|
||||
SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, 0, profile);
|
||||
/* Get the path to "My Documents" directory */
|
||||
SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, 0, profile);
|
||||
|
||||
len = WPath2A(dst, size, profile);
|
||||
if (len == 0)
|
||||
return 0;
|
||||
len = WPath2A(dst, size, profile);
|
||||
if (len == 0)
|
||||
return 0;
|
||||
|
||||
idStr::Append(dst, size, "/My Games/dhewm3");
|
||||
idStr::Append(dst, size, "/My Games/dhewm3");
|
||||
|
||||
return len;
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
static int GetRegistryPath(char *dst, size_t size, const WCHAR *subkey, const WCHAR *name) {
|
||||
|
@ -354,6 +356,8 @@ bool Sys_GetPath(sysPath_t type, idStr &path) {
|
|||
common->Warning("base path '%s' does not exist", s.c_str());
|
||||
}
|
||||
|
||||
// Note: apparently there is no registry entry for the Doom 3 Demo
|
||||
|
||||
// fallback to vanilla doom3 cd install
|
||||
if (GetRegistryPath(buf, sizeof(buf), L"SOFTWARE\\id\\Doom 3", L"InstallPath") > 0) {
|
||||
path = buf;
|
||||
|
@ -369,13 +373,13 @@ bool Sys_GetPath(sysPath_t type, idStr &path) {
|
|||
return true;
|
||||
}
|
||||
|
||||
common->Warning("vanilla doom3 path not found");
|
||||
common->Warning("vanilla doom3 path not found either");
|
||||
|
||||
return false;
|
||||
|
||||
case PATH_CONFIG:
|
||||
case PATH_SAVE:
|
||||
if (GetHomeDir(buf, sizeof(buf)) < 1) {
|
||||
if (Sys_GetHomeDir(buf, sizeof(buf)) < 1) {
|
||||
Sys_Error("ERROR: Couldn't get dir to home path");
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue