-
Notifications
You must be signed in to change notification settings - Fork 86
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
Allow macOS and Linux to find files in the executable directory #493
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,7 +236,12 @@ void I_SwitchToWindow(HWND hwnd) | |
} | ||
} | ||
|
||
const char *I_DoomExeDir(void) | ||
const char *I_DoomDir(void) | ||
{ | ||
return I_ExeDir(); | ||
} | ||
|
||
const char *I_ExeDir(void) | ||
{ | ||
extern char **dsda_argv; | ||
|
||
|
@@ -284,7 +289,12 @@ const char* I_GetTempDir(void) | |
|
||
#elif defined(AMIGA) | ||
|
||
const char *I_DoomExeDir(void) | ||
const char *I_DoomDir(void) | ||
{ | ||
return "PROGDIR:"; | ||
} | ||
|
||
const char *I_ExeDir(void) | ||
{ | ||
return "PROGDIR:"; | ||
} | ||
|
@@ -300,7 +310,7 @@ const char* I_GetTempDir(void) | |
// cph 2006/07/23 - give prboom+ its own dir | ||
static const char prboom_dir[] = {"/.dsda-doom"}; // Mead rem extra slash 8/21/03 | ||
|
||
const char *I_DoomExeDir(void) | ||
const char *I_DoomDir(void) | ||
{ | ||
static char *base; | ||
if (!base) // cache multiple requests | ||
|
@@ -318,6 +328,32 @@ const char *I_DoomExeDir(void) | |
return base; | ||
} | ||
|
||
const char *I_ExeDir(void) | ||
{ | ||
extern char **dsda_argv; | ||
|
||
static const char current_dir_dummy[] = {"."}; // proff - rem extra slash 8/21/03 | ||
static char *base; | ||
if (!base) // cache multiple requests | ||
{ | ||
size_t len = strlen(*dsda_argv); | ||
char *p = (base = (char*)Z_Malloc(len+1)) + len - 1; | ||
strcpy(base,*dsda_argv); | ||
while (p > base && *p!='/' && *p!='\\') | ||
*p--=0; | ||
if (*p=='/' || *p=='\\') | ||
*p--=0; | ||
if (strlen(base) < 2 || !M_WriteAccess(base)) | ||
{ | ||
Z_Free(base); | ||
base = (char*)Z_Malloc(1024); | ||
if (!M_getcwd(base, 1024) || !M_WriteAccess(base)) | ||
strcpy(base, current_dir_dummy); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No there is no reason it needs to persist. I simply copied over the code from the Windows function, didnt even try to understand it. |
||
} | ||
} | ||
return base; | ||
} | ||
|
||
const char *I_GetTempDir(void) | ||
{ | ||
return "/tmp"; | ||
|
@@ -376,9 +412,12 @@ char* I_FindFileInternal(const char* wfname, const char* ext, dboolean isStatic) | |
const char *dir; // directory | ||
const char *sub; // subdirectory | ||
const char *env; // environment variable | ||
const char *(*func)(void); // for I_DoomExeDir | ||
const char *(*func)(void); // for functions that return the directory | ||
} search0[] = { | ||
{NULL, NULL, NULL, I_DoomExeDir}, // config directory | ||
{NULL, NULL, NULL, I_ExeDir}, // executable directory | ||
#ifndef _WIN32 | ||
{NULL, NULL, NULL, I_DoomDir}, // config and autoload directory. on windows, this is the same as I_ExeDir | ||
#endif | ||
{NULL}, // current working directory | ||
{NULL, NULL, "DOOMWADDIR"}, // run-time $DOOMWADDIR | ||
{DOOMWADDIR}, // build-time configured DOOMWADDIR | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we rather call this
I_ConfigDir
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was originally going to name it that, but opted with DoomDir since that folder hosts more than just the config file.
Made a new commit that changes the name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, maybe
I_DataDir
? It's maybe too generic, plus confusing since dsda-doom has a "data dir" as well that's one level below that. Any other ideas?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like
I_ConfigDir
.Its pretty clear what it represents, so no one will be confused.