- Added directory detection to the -file parameter. This obsoletes -dir, so

that parameter is now gone.
- Removed automatic ".wad" appending from FWadCollection::InitMultipleFiles()
  since it isn't needed and prevented files without extensions from being
  loaded. D_AddFile() already takes care of adding the extension if the
  name as-given does not exist.
- Fixed: Loading single files did not print a newline in the startup text.


SVN r1784 (trunk)
This commit is contained in:
Randy Heit 2009-09-02 03:47:48 +00:00
commit c24c31cc9f
7 changed files with 191 additions and 52 deletions

View file

@ -28,6 +28,14 @@ gamedir will hold progdir + the game directory (id1, id2, etc)
FString progdir;
//==========================================================================
//
// IsSeperator
//
// Returns true if the character is a path seperator.
//
//==========================================================================
static inline bool IsSeperator (int c)
{
if (c == '/')
@ -39,6 +47,14 @@ static inline bool IsSeperator (int c)
return false;
}
//==========================================================================
//
// FixPathSeperator
//
// Convert backslashes to forward slashes.
//
//==========================================================================
void FixPathSeperator (char *path)
{
while (*path)
@ -49,6 +65,14 @@ void FixPathSeperator (char *path)
}
}
//==========================================================================
//
// copystring
//
// Replacement for strdup that uses new instead of malloc.
//
//==========================================================================
char *copystring (const char *s)
{
char *b;
@ -66,6 +90,13 @@ char *copystring (const char *s)
return b;
}
//==========================================================================
//
// ReplaceString
//
// Do not use in new code.
//
//==========================================================================
void ReplaceString (char **ptr, const char *str)
{
@ -87,11 +118,12 @@ void ReplaceString (char **ptr, const char *str)
*/
/*
================
Q_filelength
================
*/
//==========================================================================
//
// Q_filelength
//
//==========================================================================
int Q_filelength (FILE *f)
{
int pos;
@ -106,17 +138,20 @@ int Q_filelength (FILE *f)
}
/*
==============
FileExists
==============
*/
//==========================================================================
//
// FileExists
//
// Returns true if the given path exists and is a readable file.
//
//==========================================================================
bool FileExists (const char *filename)
{
FILE *f;
// [RH] Empty filenames are never there
if (*filename == 0)
if (filename == NULL || *filename == 0)
return false;
f = fopen (filename, "r");
@ -126,6 +161,31 @@ bool FileExists (const char *filename)
return true;
}
//==========================================================================
//
// DirEntryExists
//
// Returns true if the given path exists, be it a directory or a file.
//
//==========================================================================
bool DirEntryExists(const char *pathname)
{
if (pathname == NULL || *pathname == 0)
return false;
struct stat info;
return stat(pathname, &info) == 0;
}
//==========================================================================
//
// DefaultExtension -- char array version
//
// Appends the extension to a pathname if it does not already have one.
//
//==========================================================================
void DefaultExtension (char *path, const char *extension)
{
char *src;
@ -145,6 +205,14 @@ void DefaultExtension (char *path, const char *extension)
strcat (path, extension);
}
//==========================================================================
//
// DefaultExtension -- FString version
//
// Appends the extension to a pathname if it does not already have one.
//
//==========================================================================
void DefaultExtension (FString &path, const char *extension)
{
const char *src = &path[int(path.Len())-1];
@ -160,13 +228,17 @@ void DefaultExtension (FString &path, const char *extension)
}
/*
====================
Extract file parts
====================
*/
//==========================================================================
//
// ExtractFilePath
//
// Returns the directory part of a pathname.
//
// FIXME: should include the slash, otherwise
// backing to an empty path will be wrong when appending a slash
//
//==========================================================================
FString ExtractFilePath (const char *path)
{
const char *src;
@ -182,6 +254,14 @@ FString ExtractFilePath (const char *path)
return FString(path, src - path);
}
//==========================================================================
//
// ExtractFileBase
//
// Returns the file part of a pathname, optionally including the extension.
//
//==========================================================================
FString ExtractFileBase (const char *path, bool include_extension)
{
const char *src, *dot;
@ -221,11 +301,12 @@ FString ExtractFileBase (const char *path, bool include_extension)
}
/*
==============
ParseNum / ParseHex
==============
*/
//==========================================================================
//
// ParseHex
//
//==========================================================================
int ParseHex (const char *hex)
{
const char *str;
@ -253,6 +334,11 @@ int ParseHex (const char *hex)
return num;
}
//==========================================================================
//
// ParseNum
//
//==========================================================================
int ParseNum (const char *str)
{
@ -263,8 +349,13 @@ int ParseNum (const char *str)
return atol (str);
}
//==========================================================================
//
// IsNum
//
// [RH] Returns true if the specified string is a valid decimal number
//
//==========================================================================
bool IsNum (const char *str)
{
@ -279,7 +370,13 @@ bool IsNum (const char *str)
return true;
}
//==========================================================================
//
// CheckWildcards
//
// [RH] Checks if text matches the wildcard pattern using ? or *
//
//==========================================================================
bool CheckWildcards (const char *pattern, const char *text)
{
@ -317,7 +414,13 @@ bool CheckWildcards (const char *pattern, const char *text)
return (*pattern | *text) == 0;
}
//==========================================================================
//
// FormatGUID
//
// [RH] Print a GUID to a text buffer using the standard format.
//
//==========================================================================
void FormatGUID (char *buffer, size_t buffsize, const GUID &guid)
{
@ -329,7 +432,14 @@ void FormatGUID (char *buffer, size_t buffsize, const GUID &guid)
guid.Data4[6], guid.Data4[7]);
}
//==========================================================================
//
// myasctime
//
// [RH] Returns the current local time as ASCII, even if it's too early
//
//==========================================================================
const char *myasctime ()
{
time_t clock;
@ -347,10 +457,13 @@ const char *myasctime ()
}
}
/************************************************************************/
/* CreatePath: creates a directory including all levels necessary */
/* */
/************************************************************************/
//==========================================================================
//
// CreatePath
//
// Creates a directory including all levels necessary
//
//==========================================================================
#ifdef _WIN32
void DoCreatePath(const char *fn)
{
@ -413,8 +526,14 @@ void CreatePath(const char *fn)
}
#endif
//==========================================================================
//
// strbin1 -- In-place version
//
// [RH] Replaces the escape sequences in a string with actual escaped characters.
// This operation is done in-place. The result is the new length of the string.
//
//==========================================================================
int strbin (char *str)
{
@ -504,8 +623,14 @@ int strbin (char *str)
return int(str - start);
}
//==========================================================================
//
// strbin1 -- String-creating version
//
// [RH] Replaces the escape sequences in a string with actual escaped characters.
// This operation is done in-place. The result is the new length of the string.
// This operation is done in-place.
//
//==========================================================================
FString strbin1 (const char *start)
{