diff --git a/docs/rh-log.txt b/docs/rh-log.txt index c8030b92b..f868f4bf2 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,4 +1,11 @@ September 1, 2009 +- 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. - Fixed: A_JumpIf(InTarget)Inventory jumped if the check amount was greater than the item's max amount and the item was maxed. - Fixed: Some dmadds wads used zero-length sprites as placeholders. When you diff --git a/src/cmdlib.cpp b/src/cmdlib.cpp index 5403141ee..b00a1d24c 100644 --- a/src/cmdlib.cpp +++ b/src/cmdlib.cpp @@ -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) { diff --git a/src/cmdlib.h b/src/cmdlib.h index d42d2e5aa..fe41204ec 100644 --- a/src/cmdlib.h +++ b/src/cmdlib.h @@ -18,6 +18,7 @@ int Q_filelength (FILE *f); bool FileExists (const char *filename); +bool DirEntryExists (const char *pathname); extern FString progdir; diff --git a/src/d_main.cpp b/src/d_main.cpp index e48762ea7..d3cda5dbb 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -1235,7 +1235,7 @@ void D_AddFile (const char *file, bool check) return; } - if (check && !FileExists (file)) + if (check && !DirEntryExists (file)) { const char *f = BaseFileSearch (file, ".wad"); if (f == NULL) @@ -1405,13 +1405,13 @@ static const char *BaseFileSearch (const char *file, const char *ext, bool lookf if (lookfirstinprogdir) { mysnprintf (wad, countof(wad), "%s%s%s", progdir.GetChars(), progdir[progdir.Len() - 1] != '/' ? "/" : "", file); - if (FileExists (wad)) + if (DirEntryExists (wad)) { return wad; } } - if (FileExists (file)) + if (DirEntryExists (file)) { mysnprintf (wad, countof(wad), "%s", file); return wad; @@ -1454,7 +1454,7 @@ static const char *BaseFileSearch (const char *file, const char *ext, bool lookf if (dir != NULL) { mysnprintf (wad, countof(wad), "%s%s%s", dir, dir[strlen (dir) - 1] != '/' ? "/" : "", file); - if (FileExists (wad)) + if (DirEntryExists (wad)) { return wad; } @@ -1748,11 +1748,8 @@ void D_DoomMain (void) files2->Destroy(); files3->Destroy(); - const char *loaddir = Args->CheckValue("-dir"); - // FIXME: consider the search path list for directory, too. - Printf ("W_Init: Init WADfiles.\n"); - Wads.InitMultipleFiles (&wadfiles, loaddir); + Wads.InitMultipleFiles (&wadfiles); // [RH] Initialize localizable strings. GStrings.LoadStrings (false); diff --git a/src/resourcefiles/file_lump.cpp b/src/resourcefiles/file_lump.cpp index e70a5f609..d092e9293 100644 --- a/src/resourcefiles/file_lump.cpp +++ b/src/resourcefiles/file_lump.cpp @@ -67,7 +67,7 @@ FLumpFile::FLumpFile(const char *filename, FileReader *file) : FUncompressedFile // //========================================================================== -bool FLumpFile::Open(bool) +bool FLumpFile::Open(bool quiet) { FString name(ExtractFileBase (Filename)); @@ -81,6 +81,10 @@ bool FLumpFile::Open(bool) Lumps->Flags = 0; Lumps->FullName = NULL; NumLumps = 1; + if (!quiet) + { + Printf("\n"); + } return true; } diff --git a/src/w_wad.cpp b/src/w_wad.cpp index a322f0aa8..10352fd24 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -160,7 +160,7 @@ void FWadCollection::DeleteAll () // //========================================================================== -void FWadCollection::InitMultipleFiles (wadlist_t **filenames, const char *loaddir) +void FWadCollection::InitMultipleFiles (wadlist_t **filenames) { int numfiles; @@ -172,18 +172,10 @@ void FWadCollection::InitMultipleFiles (wadlist_t **filenames, const char *loadd { wadlist_t *next = (*filenames)->next; int baselump = NumLumps; - char name[PATH_MAX]; - - // [RH] Automatically append .wad extension if none is specified. - strcpy (name, (*filenames)->name); - FixPathSeperator (name); - DefaultExtension (name, ".wad"); - - AddFile (name); + AddFile ((*filenames)->name); M_Free (*filenames); *filenames = next; } - if (loaddir != NULL) AddFile(loaddir, NULL, true); NumLumps = LumpInfo.Size(); if (NumLumps == 0) @@ -230,9 +222,20 @@ int FWadCollection::AddExternalFile(const char *filename) // [RH] Removed reload hack //========================================================================== -void FWadCollection::AddFile (const char *filename, FileReader *wadinfo, bool isdir) +void FWadCollection::AddFile (const char *filename, FileReader *wadinfo) { - int startlump; + int startlump; + bool isdir; + + // Does this exist? If so, is it a directory? + struct stat info; + if (stat(filename, &info) != 0) + { + Printf(TEXTCOLOR_RED "Could not stat %s\n", filename); + PrintLastError(); + return; + } + isdir = (info.st_mode & S_IFDIR) != 0; if (wadinfo == NULL && !isdir) { @@ -253,8 +256,10 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadinfo, bool is FResourceFile *resfile; - if (!isdir) resfile = FResourceFile::OpenResourceFile(filename, wadinfo); - else resfile = FResourceFile::OpenDirectory(filename); + if (!isdir) + resfile = FResourceFile::OpenResourceFile(filename, wadinfo); + else + resfile = FResourceFile::OpenDirectory(filename); if (resfile != NULL) { diff --git a/src/w_wad.h b/src/w_wad.h index dfc1a4a29..293a328f5 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -153,8 +153,8 @@ public: // The wadnum for the IWAD enum { IWAD_FILENUM = 1 }; - void InitMultipleFiles (wadlist_t **filenames, const char *loaddir); - void AddFile (const char *filename, FileReader *wadinfo = NULL, bool isdir = false); + void InitMultipleFiles (wadlist_t **filenames); + void AddFile (const char *filename, FileReader *wadinfo = NULL); int CheckIfWadLoaded (const char *name); const char *GetWadName (int wadnum) const;