mirror of
https://github.com/fabiangreffrath/woof.git
synced 2025-09-24 04:29:34 -04:00
do not mistake WAD-named directories for actual WAD files (#2118)
* do not mistake WAD-named directories for actual WAD files * explicitly check for files not dirs
This commit is contained in:
parent
22a1ee93e2
commit
7e39b8d839
14
src/d_iwad.c
14
src/d_iwad.c
@ -453,15 +453,6 @@ static void CheckDOSDefaults(void)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Returns true if the specified path is a path to a file
|
|
||||||
// of the specified name.
|
|
||||||
|
|
||||||
static boolean DirIsFile(const char *path, const char *filename)
|
|
||||||
{
|
|
||||||
return strchr(path, DIR_SEPARATOR) != NULL
|
|
||||||
&& !strcasecmp(M_BaseName(path), filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add IWAD directories parsed from splitting a path string containing
|
// Add IWAD directories parsed from splitting a path string containing
|
||||||
// paths separated by PATH_SEPARATOR. 'suffix' is a string to concatenate
|
// paths separated by PATH_SEPARATOR. 'suffix' is a string to concatenate
|
||||||
// to the end of the paths before adding them.
|
// to the end of the paths before adding them.
|
||||||
@ -620,7 +611,6 @@ void BuildIWADDirList(void)
|
|||||||
|
|
||||||
char *D_FindWADByName(const char *name)
|
char *D_FindWADByName(const char *name)
|
||||||
{
|
{
|
||||||
char *path;
|
|
||||||
char *probe;
|
char *probe;
|
||||||
|
|
||||||
// Absolute path?
|
// Absolute path?
|
||||||
@ -643,7 +633,7 @@ char *D_FindWADByName(const char *name)
|
|||||||
// file.
|
// file.
|
||||||
|
|
||||||
probe = M_FileCaseExists(*dir);
|
probe = M_FileCaseExists(*dir);
|
||||||
if (DirIsFile(*dir, name) && probe != NULL)
|
if (probe != NULL)
|
||||||
{
|
{
|
||||||
return probe;
|
return probe;
|
||||||
}
|
}
|
||||||
@ -651,7 +641,7 @@ char *D_FindWADByName(const char *name)
|
|||||||
|
|
||||||
// Construct a string for the full path
|
// Construct a string for the full path
|
||||||
|
|
||||||
path = M_StringJoin(*dir, DIR_SEPARATOR_S, name);
|
char *path = M_StringJoin(*dir, DIR_SEPARATOR_S, name);
|
||||||
|
|
||||||
probe = M_FileCaseExists(path);
|
probe = M_FileCaseExists(path);
|
||||||
if (probe != NULL)
|
if (probe != NULL)
|
||||||
|
19
src/m_misc.c
19
src/m_misc.c
@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
// Check if a file exists
|
// Check if a file exists
|
||||||
|
|
||||||
boolean M_FileExists(const char *filename)
|
static boolean M_FileExistsNotDir(const char *filename)
|
||||||
{
|
{
|
||||||
FILE *fstream;
|
FILE *fstream;
|
||||||
|
|
||||||
@ -45,14 +45,11 @@ boolean M_FileExists(const char *filename)
|
|||||||
if (fstream != NULL)
|
if (fstream != NULL)
|
||||||
{
|
{
|
||||||
fclose(fstream);
|
fclose(fstream);
|
||||||
return true;
|
return M_DirExists(filename) == false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// If we can't open because the file is a directory, the
|
return false;
|
||||||
// "file" exists at least!
|
|
||||||
|
|
||||||
return errno == EISDIR;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +115,7 @@ char *M_FileCaseExists(const char *path)
|
|||||||
path_dup = M_StringDuplicate(path);
|
path_dup = M_StringDuplicate(path);
|
||||||
|
|
||||||
// 0: actual path
|
// 0: actual path
|
||||||
if (M_FileExists(path_dup))
|
if (M_FileExistsNotDir(path_dup))
|
||||||
{
|
{
|
||||||
return path_dup;
|
return path_dup;
|
||||||
}
|
}
|
||||||
@ -130,7 +127,7 @@ char *M_FileCaseExists(const char *path)
|
|||||||
// 1: lowercase filename, e.g. doom2.wad
|
// 1: lowercase filename, e.g. doom2.wad
|
||||||
M_StringToLower(filename);
|
M_StringToLower(filename);
|
||||||
|
|
||||||
if (M_FileExists(path_dup))
|
if (M_FileExistsNotDir(path_dup))
|
||||||
{
|
{
|
||||||
return path_dup;
|
return path_dup;
|
||||||
}
|
}
|
||||||
@ -138,7 +135,7 @@ char *M_FileCaseExists(const char *path)
|
|||||||
// 2: uppercase filename, e.g. DOOM2.WAD
|
// 2: uppercase filename, e.g. DOOM2.WAD
|
||||||
M_StringToUpper(filename);
|
M_StringToUpper(filename);
|
||||||
|
|
||||||
if (M_FileExists(path_dup))
|
if (M_FileExistsNotDir(path_dup))
|
||||||
{
|
{
|
||||||
return path_dup;
|
return path_dup;
|
||||||
}
|
}
|
||||||
@ -149,7 +146,7 @@ char *M_FileCaseExists(const char *path)
|
|||||||
{
|
{
|
||||||
M_StringToLower(ext + 1);
|
M_StringToLower(ext + 1);
|
||||||
|
|
||||||
if (M_FileExists(path_dup))
|
if (M_FileExistsNotDir(path_dup))
|
||||||
{
|
{
|
||||||
return path_dup;
|
return path_dup;
|
||||||
}
|
}
|
||||||
@ -160,7 +157,7 @@ char *M_FileCaseExists(const char *path)
|
|||||||
{
|
{
|
||||||
M_StringToLower(filename + 1);
|
M_StringToLower(filename + 1);
|
||||||
|
|
||||||
if (M_FileExists(path_dup))
|
if (M_FileExistsNotDir(path_dup))
|
||||||
{
|
{
|
||||||
return path_dup;
|
return path_dup;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
#include "doomtype.h"
|
#include "doomtype.h"
|
||||||
|
|
||||||
boolean M_FileExists(const char *file);
|
|
||||||
boolean M_DirExists(const char *path);
|
boolean M_DirExists(const char *path);
|
||||||
int M_FileLength(const char *path);
|
int M_FileLength(const char *path);
|
||||||
char *M_TempFile(const char *s);
|
char *M_TempFile(const char *s);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user