From 42cdd27e0b597746faa22f78beae6da5fe5b936c Mon Sep 17 00:00:00 2001 From: "techdragon.nguyen@gmail.com" Date: Thu, 23 Feb 2012 02:11:14 +0000 Subject: [PATCH] fixed music bug for Momir and Random game types. The functions that determined if a file existed did not handle errors properly. Instead it would return an empty string which when appended to the base path would always return true. Thus a non-existent file would always be treated as if it existed. The guards I put in test for empty strings before continuing evaluation. I may have been a little judicious in the places where I put the gaurds in. We can remove the guards if it turns out we don't need them in all the places. --- JGE/src/JFileSystem.cpp | 2 ++ JGE/src/zipFS/zfsystem.cpp | 1 + projects/mtg/src/GameStateDuel.cpp | 8 ++++++-- projects/mtg/src/WResourceManager.cpp | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/JGE/src/JFileSystem.cpp b/JGE/src/JFileSystem.cpp index 20739aebc..a42336a33 100644 --- a/JGE/src/JFileSystem.cpp +++ b/JGE/src/JFileSystem.cpp @@ -196,6 +196,8 @@ bool JFileSystem::DirExists(const string& strDirname) bool JFileSystem::FileExists(const string& strFilename) { + if (strFilename.length() < 1 ) return false; + return (mSystemFS && mSystemFS->FileExists(strFilename)) || mUserFS->FileExists(strFilename); } diff --git a/JGE/src/zipFS/zfsystem.cpp b/JGE/src/zipFS/zfsystem.cpp index 51e8d8c9c..b8ef786d9 100644 --- a/JGE/src/zipFS/zfsystem.cpp +++ b/JGE/src/zipFS/zfsystem.cpp @@ -299,6 +299,7 @@ bool filesystem::DirExists(const std::string & folderName) bool filesystem::FileExists(const std::string & fileName) { + if (fileName.length() < 1) return false; //Check in zip file_info FileInfo; diff --git a/projects/mtg/src/GameStateDuel.cpp b/projects/mtg/src/GameStateDuel.cpp index c6b6ba09f..04c30e6a0 100644 --- a/projects/mtg/src/GameStateDuel.cpp +++ b/projects/mtg/src/GameStateDuel.cpp @@ -242,7 +242,10 @@ void GameStateDuel::End() //TODO Move This to utils or ResourceManager. Don't we have more generic functions that can do that? bool GameStateDuel::MusicExist(string FileName) { - return FileExists(WResourceManager::Instance()->musicFile(FileName)); + string musicFilename = WResourceManager::Instance()->musicFile(FileName); + if (musicFilename.length() < 1) return false; + + return FileExists(musicFilename); } void GameStateDuel::ConstructOpponentMenu() @@ -438,7 +441,8 @@ void GameStateDuel::Update(float dt) else if (mParent->gameType == GAME_TYPE_RANDOM1 || mParent->gameType == GAME_TYPE_RANDOM2) musictrack = "ai_baka_music_random.mp3"; - if (!MusicExist(musictrack)) musictrack = "ai_baka_music.mp3"; + if (!MusicExist(musictrack)) + musictrack = "ai_baka_music.mp3"; GameApp::playMusic(musictrack); } diff --git a/projects/mtg/src/WResourceManager.cpp b/projects/mtg/src/WResourceManager.cpp index 18bd68549..c08030975 100644 --- a/projects/mtg/src/WResourceManager.cpp +++ b/projects/mtg/src/WResourceManager.cpp @@ -754,7 +754,7 @@ string ResourceManagerImpl::musicFile(const string& filename) sprintf(defdir, "sound/%s", filename.c_str()); if (fileOK(defdir)) return defdir; - //Failure. Check raw faile. + //Failure. Check raw file. sprintf(defdir, "%s", filename.c_str()); if (fileOK(defdir)) return defdir;