From 2ad98500704f7a20d387af0655d9b084d6e5e47f Mon Sep 17 00:00:00 2001 From: Nicolay Korslund Date: Fri, 20 Aug 2010 14:20:05 +0200 Subject: [PATCH] Added .wav -> .mp3 sound file lookup --- apps/openmw/mwsound/soundmanager.cpp | 24 ++++++++++++++++++++++-- components/file_finder/file_finder.hpp | 12 ++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index 262c7a974..bd81ef6e6 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -104,17 +104,37 @@ namespace MWSound root->addFrameListener(&updater); } + std::string toMp3(const std::string &str) + { + std::string wav = str; + int i = str.size()-3; + wav[i++] = 'm'; + wav[i++] = 'p'; + wav[i++] = '3'; + return wav; + } + bool hasFile(const std::string &str) { - return files.has(str); + if(files.has(str)) return true; + // Not found? Try exchanging .wav with .mp3 + return files.has(toMp3(str)); } // Convert a Morrowind sound path (eg. Fx\funny.wav) to full path // with proper slash conversion (eg. datadir/Sound/Fx/funny.wav) std::string convertPath(const std::string &str) { - if(hasFile(str)) + // Search and return + if(files.has(str)) return files.lookup(str); + + // Try mp3 if the wav wasn't found + std::string mp3 = toMp3(str); + if(files.has(mp3)) + return files.lookup(mp3); + + // Give up return ""; } diff --git a/components/file_finder/file_finder.hpp b/components/file_finder/file_finder.hpp index eda73a85f..107121278 100644 --- a/components/file_finder/file_finder.hpp +++ b/components/file_finder/file_finder.hpp @@ -8,13 +8,14 @@ namespace FileFinder { -class FileFinder +template +class FileFinderT { - std::map table; + std::map table; struct Inserter : ReturnPath { - FileFinder *owner; + FileFinderT *owner; int cut; void add(const boost::filesystem::path &pth) @@ -28,7 +29,7 @@ class FileFinder Inserter inserter; public: - FileFinder(const boost::filesystem::path &path, bool recurse=true) + FileFinderT(const boost::filesystem::path &path, bool recurse=true) { inserter.owner = this; @@ -58,5 +59,8 @@ public: return table.find(file)->second; } }; + +// The default is to use path_less for equality checks +typedef FileFinderT FileFinder; } #endif