From 468275bb94f975b9e1c2e7e90a03caa37bd0e142 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 17 Sep 2003 21:06:16 +0000 Subject: added a static method setDefaultDirectory to class File; used this to simplify some code; added a global g_sound pointer in bs2, this cuts down on uses of g_sword2 (of course both should be removed on the long run); some other minor tweaks/fixes svn-id: r10278 --- common/file.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'common/file.cpp') diff --git a/common/file.cpp b/common/file.cpp index 81fd148e98..3f1412033d 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -22,6 +22,10 @@ #include "common/file.h" #include "common/util.h" + +char *File::_defaultDirectory = 0; + + FILE *File::fopenNoCase(const char *filename, const char *directory, const char *mode) { FILE *file; char buf[512]; @@ -111,6 +115,11 @@ FILE *File::fopenNoCase(const char *filename, const char *directory, const char return NULL; } +void File::setDefaultDirectory(const char *directory) { + free(_defaultDirectory); + _defaultDirectory = strdup(directory); +} + File::File() { _handle = NULL; _ioFailed = false; @@ -131,6 +140,10 @@ bool File::open(const char *filename, const char *directory, int mode, byte encb if (filename == NULL || *filename == 0) return false; + + // If no directory was specified, use the default directory (if any). + if (directory == NULL) + directory = _defaultDirectory ? _defaultDirectory : ""; clearIOFailed(); -- cgit v1.2.3