diff options
author | Max Horn | 2003-10-10 13:55:08 +0000 |
---|---|---|
committer | Max Horn | 2003-10-10 13:55:08 +0000 |
commit | 5301edc38306c27143f38d74085e6c095688f6aa (patch) | |
tree | 101c5188d06ac1f476edae9f3a5755e48554dc64 | |
parent | 1f9497cb1fbfcc8c3ffd412ce450144983b2452d (diff) | |
download | scummvm-rg350-5301edc38306c27143f38d74085e6c095688f6aa.tar.gz scummvm-rg350-5301edc38306c27143f38d74085e6c095688f6aa.tar.bz2 scummvm-rg350-5301edc38306c27143f38d74085e6c095688f6aa.zip |
some cleanup
svn-id: r10720
-rw-r--r-- | base/engine.cpp | 8 | ||||
-rw-r--r-- | base/engine.h | 3 | ||||
-rw-r--r-- | common/file.cpp | 9 | ||||
-rw-r--r-- | common/file.h | 6 | ||||
-rw-r--r-- | queen/resource.cpp | 9 | ||||
-rw-r--r-- | queen/resource.h | 4 | ||||
-rw-r--r-- | scumm/scummvm.cpp | 4 | ||||
-rw-r--r-- | simon/sound.cpp | 11 | ||||
-rw-r--r-- | simon/sound.h | 9 | ||||
-rw-r--r-- | sky/disk.cpp | 9 | ||||
-rw-r--r-- | sky/disk.h | 3 | ||||
-rw-r--r-- | sword2/sword2.cpp | 2 |
12 files changed, 37 insertions, 40 deletions
diff --git a/base/engine.cpp b/base/engine.cpp index 1445c8d6b2..ff74e8b83d 100644 --- a/base/engine.cpp +++ b/base/engine.cpp @@ -25,6 +25,7 @@ #include "base/engine.h" #include "base/gameDetector.h" #include "common/config-manager.h" +#include "common/file.h" #include "common/timer.h" #include "sound/mixer.h" @@ -32,13 +33,14 @@ Engine *g_engine = 0; Engine::Engine(GameDetector *detector, OSystem *syst) - : _system(syst) { + : _system(syst), _gameDataPath(ConfMan.get("path")) { g_engine = this; _mixer = detector->createMixer(); - _gameDataPath = strdup(ConfMan.get("path").c_str()); // FIXME - leak. Just conver to a String? - _timer = g_timer; + + // Set default file directory + File::setDefaultDirectory(_gameDataPath); } Engine::~Engine() { diff --git a/base/engine.h b/base/engine.h index 367e35f132..e1bb4c71cc 100644 --- a/base/engine.h +++ b/base/engine.h @@ -22,6 +22,7 @@ #define ENGINE_H #include "common/scummsys.h" +#include "common/str.h" #include "common/system.h" extern const char *gScummVMVersion; // e.g. "0.4.1" @@ -67,7 +68,7 @@ public: Timer * _timer; protected: - const char *_gameDataPath; + const Common::String _gameDataPath; public: Engine(GameDetector *detector, OSystem *syst); diff --git a/common/file.cpp b/common/file.cpp index 1110c683b5..cb6eb4545a 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -23,7 +23,7 @@ #include "common/util.h" -char *File::_defaultDirectory = 0; +Common::String File::_defaultDirectory; FILE *File::fopenNoCase(const char *filename, const char *directory, const char *mode) { @@ -119,9 +119,8 @@ FILE *File::fopenNoCase(const char *filename, const char *directory, const char return NULL; } -void File::setDefaultDirectory(const char *directory) { - free(_defaultDirectory); - _defaultDirectory = strdup(directory); +void File::setDefaultDirectory(const Common::String &directory) { + _defaultDirectory = directory; } File::File() { @@ -147,7 +146,7 @@ bool File::open(const char *filename, const char *directory, int mode, byte encb // If no directory was specified, use the default directory (if any). if (directory == NULL) - directory = _defaultDirectory ? _defaultDirectory : ""; + directory = _defaultDirectory.isEmpty() ? "" : _defaultDirectory.c_str(); clearIOFailed(); diff --git a/common/file.h b/common/file.h index c07d4e9d4a..b043608d22 100644 --- a/common/file.h +++ b/common/file.h @@ -24,6 +24,7 @@ #include "stdafx.h" #include "common/scummsys.h" +#include "common/str.h" class File { private: @@ -35,7 +36,7 @@ private: static FILE *fopenNoCase(const char *filename, const char *directory, const char *mode); - static char *_defaultDirectory; + static Common::String _defaultDirectory; public: enum { @@ -43,10 +44,11 @@ public: kFileWriteMode = 2 }; - static void setDefaultDirectory(const char *directory); + static void setDefaultDirectory(const Common::String &directory); File(); virtual ~File(); + bool open(const char *filename, const Common::String &directory) { return open(filename, directory.c_str()); } bool open(const char *filename, const char *directory = NULL, int mode = kFileReadMode, byte encbyte = 0); void close(); bool isOpen(); diff --git a/queen/resource.cpp b/queen/resource.cpp index bb8bac391c..61a1e55e13 100644 --- a/queen/resource.cpp +++ b/queen/resource.cpp @@ -43,14 +43,13 @@ const GameVersion Resource::_gameVersions[] = { { "PE100", true, true, 0x000B40F5 } }; -Resource::Resource(const char *datafilePath) - : _resourceEntries(0), _resourceTable(NULL) { +Resource::Resource(const Common::String &datafilePath) + : _resourceEntries(0), _resourceTable(NULL), _datafilePath(datafilePath) { - _datafilePath = datafilePath; _resourceFile = new File(); _resourceFile->open(dataFilename, _datafilePath); if (_resourceFile->isOpen() == false) - error("Could not open resource file '%s%s'", _datafilePath, dataFilename); + error("Could not open resource file '%s%s'", _datafilePath.c_str(), dataFilename); _gameVersion = detectGameVersion(_resourceFile->size()); @@ -62,7 +61,7 @@ Resource::Resource(const char *datafilePath) _resourceEntries = 1076; _resourceTable = _resourceTablePEM10; } else { - error("Couldn't find tablefile '%s%s'", _datafilePath, tableFilename); + error("Couldn't find tablefile '%s%s'", _datafilePath.c_str(), tableFilename); } } diff --git a/queen/resource.h b/queen/resource.h index 744ed8c3bf..bfc808f5d6 100644 --- a/queen/resource.h +++ b/queen/resource.h @@ -57,7 +57,7 @@ struct GameVersion { class Resource { public: - Resource(const char *datafilePath); + Resource(const Common::String &datafilePath); ~Resource(void); uint8 *loadFile(const char *filename, uint32 skipBytes = 0); bool exists(const char *filename); @@ -66,7 +66,7 @@ public: protected: File *_resourceFile; - const char *_datafilePath; + const Common::String _datafilePath; const GameVersion *_gameVersion; uint32 _resourceEntries; ResourceEntry *_resourceTable; diff --git a/scumm/scummvm.cpp b/scumm/scummvm.cpp index 07f7340f8d..94f79c615a 100644 --- a/scumm/scummvm.cpp +++ b/scumm/scummvm.cpp @@ -2507,7 +2507,7 @@ byte *ScummEngine::get2byteCharPtr(int idx) { const char *ScummEngine::getGameDataPath() const { #ifdef MACOSX - if (_version == 8 && !memcmp(_gameDataPath, "/Volumes/MONKEY3_", 17)) { + if (_version == 8 && _gameDataPath == "/Volumes/MONKEY3_") { // Special case for COMI on Mac OS X. The mount points on OS X depend // on the volume name. Hence if playing from CD, we'd get a problem. // So if loading of a resource file fails, we fall back to the (fixed) @@ -2531,7 +2531,7 @@ const char *ScummEngine::getGameDataPath() const { } #endif - return _gameDataPath; + return _gameDataPath.c_str(); } void ScummEngine::errorString(const char *buf1, char *buf2) { diff --git a/simon/sound.cpp b/simon/sound.cpp index 7ded523a17..b56d5a428f 100644 --- a/simon/sound.cpp +++ b/simon/sound.cpp @@ -235,11 +235,8 @@ int MP3Sound::playSound(uint sound, PlayingSoundHandle *handle, byte flags) /******************************************************************************/ -SimonSound::SimonSound(const byte game, const GameSpecificSettings *gss, const char *gameDataPath, SoundMixer *mixer) { - _game = game; - _gameDataPath = gameDataPath; - _mixer = mixer; - +SimonSound::SimonSound(const byte game, const GameSpecificSettings *gss, const Common::String &gameDataPath, SoundMixer *mixer) + : _game(game), _gameDataPath(gameDataPath), _mixer(mixer) { _voice_index = 0; _ambient_index = 0; @@ -343,7 +340,7 @@ SimonSound::~SimonSound() { free(_offsets); } -void SimonSound::readSfxFile(const char *filename, const char *gameDataPath) { +void SimonSound::readSfxFile(const char *filename, const Common::String &gameDataPath) { stopAll(); File *file = new File(); @@ -379,7 +376,7 @@ void SimonSound::loadSfxTable(File *gameFile, uint32 base) { _effects = new VocSound(_mixer, gameFile, base); } -void SimonSound::readVoiceFile(const char *filename, const char *gameDataPath) { +void SimonSound::readVoiceFile(const char *filename, const Common::String &gameDataPath) { stopAll(); File *file = new File(); diff --git a/simon/sound.h b/simon/sound.h index 52882ea2f6..c7da0bfdf0 100644 --- a/simon/sound.h +++ b/simon/sound.h @@ -22,6 +22,7 @@ #include "sound/mixer.h" #include "simon/intern.h" +#include "common/str.h" namespace Simon { @@ -30,7 +31,7 @@ class BaseSound; class SimonSound { private: byte _game; - const char *_gameDataPath; + const Common::String _gameDataPath; SoundMixer *_mixer; @@ -54,12 +55,12 @@ public: bool _voice_file; uint _ambient_playing; - SimonSound(const byte game, const GameSpecificSettings *gss, const char *gameDataPath, SoundMixer *mixer); + SimonSound(const byte game, const GameSpecificSettings *gss, const Common::String &gameDataPath, SoundMixer *mixer); ~SimonSound(); - void readSfxFile(const char *filename, const char *gameDataPath); + void readSfxFile(const char *filename, const Common::String &gameDataPath); void loadSfxTable(File *gameFile, uint32 base); - void readVoiceFile(const char *filename, const char *gameDataPath); + void readVoiceFile(const char *filename, const Common::String &gameDataPath); void playVoice(uint sound); void playEffects(uint sound); diff --git a/sky/disk.cpp b/sky/disk.cpp index 010953194f..61c4fc87db 100644 --- a/sky/disk.cpp +++ b/sky/disk.cpp @@ -31,12 +31,9 @@ static const char *dataFilename = "sky.dsk"; static const char *dinnerFilename = "sky.dnr"; -SkyDisk::SkyDisk(const char *gameDataPath) { +SkyDisk::SkyDisk(const Common::String &gameDataPath) { _prefRoot = NULL; - // Set default file directory - File::setDefaultDirectory(gameDataPath); - _dataDiskHandle = new File(); _dnrHandle = new File(); @@ -44,7 +41,7 @@ SkyDisk::SkyDisk(const char *gameDataPath) { _dnrHandle->open(dinnerFilename); if (_dnrHandle->isOpen() == false) - error("Could not open %s%s", gameDataPath, dinnerFilename); + error("Could not open %s%s", gameDataPath.c_str(), dinnerFilename); if (!(_dinnerTableEntries = _dnrHandle->readUint32LE())) error("Error reading from sky.dnr"); //even though it was opened correctly?! @@ -57,7 +54,7 @@ SkyDisk::SkyDisk(const char *gameDataPath) { _dataDiskHandle->open(dataFilename); if (_dataDiskHandle->isOpen() == false) - error("Error opening %s%s", gameDataPath, dataFilename); + error("Error opening %s%s", gameDataPath.c_str(), dataFilename); printf("Found BASS version v0.0%d (%d dnr entries)\n", determineGameVersion(), _dinnerTableEntries); diff --git a/sky/disk.h b/sky/disk.h index a369ae32c3..01905a9b2d 100644 --- a/sky/disk.h +++ b/sky/disk.h @@ -24,6 +24,7 @@ #include "stdafx.h" #include "common/scummsys.h" +#include "common/str.h" class File; @@ -38,7 +39,7 @@ struct PrefFile { class SkyDisk { public: - SkyDisk(const char *gameDataPath); + SkyDisk(const Common::String &gameDataPath); ~SkyDisk(void); uint8 *loadFile(uint16 fileNr, uint8 *dest); diff --git a/sword2/sword2.cpp b/sword2/sword2.cpp index 731850fae6..b045b8bbb1 100644 --- a/sword2/sword2.cpp +++ b/sword2/sword2.cpp @@ -120,8 +120,6 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) _mixer->setMusicVolume(256); g_sound = _sound = new Sound(_mixer); - - File::setDefaultDirectory(_gameDataPath); } void Sword2Engine::errorString(const char *buf1, char *buf2) { |