Resolve pathes before adding them to the search path.

Working with canonical fullpathes everywhere makes debugging easier.
And it will be used in a later commit to make sure, that each path is
added only once.
This commit is contained in:
Yamagi 2020-10-20 08:20:20 +02:00
parent 7553dc4856
commit 1a913eb7d1
4 changed files with 37 additions and 5 deletions

View file

@ -519,6 +519,20 @@ Sys_RemoveDir(const char *path)
}
}
void
Sys_Realpath(const char *in, char *out, size_t size)
{
char *converted = realpath(in, NULL);
if (converted == NULL)
{
Com_Error(ERR_FATAL, "Couldn't get realpath for %s\n", in);
}
Q_strlcpy(out, converted, size);
free(converted);
}
/* ================================================================ */
void *

View file

@ -586,6 +586,23 @@ Sys_RemoveDir(const char *path)
RemoveDirectoryW(wpath);
}
void
Sys_Realpath(const char *in, char *out, size_t size)
{
WCHAR win[MAX_OSPATH] = {0};
WCHAR wconverted[MAX_OSPATH] = {0};
MultiByteToWideChar(CP_UTF8, 0, in, -1, win, sizeof(win));
_wfullpath(wconverted, win, size);
if (wconverted == NULL)
{
Com_Error(ERR_FATAL, "Couldn't get realpath for %s\n", in);
}
WideCharToMultiByte(CP_UTF8, 0, wconverted, -1, out, size, NULL, NULL);
}
/* ======================================================================= */
void *

View file

@ -1805,9 +1805,12 @@ const char* FS_GetFilenameForHandle(fileHandle_t f)
// --------
void FS_AddDirToRawPath (const char *rawdir, qboolean create) {
// Convert backslashes to forward slashes.
char *dir = strdup(rawdir);
char dir[MAX_OSPATH] = {0};
// Get the realpath.
Sys_Realpath(rawdir, dir, sizeof(dir));
// Convert backslashes to forward slashes.
for (int i = 0; i < strlen(dir); i++)
{
if (dir[i] == '\\')
@ -1835,9 +1838,6 @@ void FS_AddDirToRawPath (const char *rawdir, qboolean create) {
search->create = create;
search->next = fs_rawPath;
fs_rawPath = search;
// Cleanup
free(dir);
}

View file

@ -821,6 +821,7 @@ void *Sys_GetGameAPI(void *parms);
void Sys_UnloadGame(void);
void Sys_GetWorkDir(char *buffer, size_t len);
qboolean Sys_SetWorkDir(char *path);
void Sys_Realpath(const char *in, char *out, size_t size);
// Windows only (system.c)
#ifdef _WIN32