mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 22:39:41 +00:00
Added .wav -> .mp3 sound file lookup
This commit is contained in:
parent
3127602c57
commit
2ad9850070
2 changed files with 30 additions and 6 deletions
|
@ -104,17 +104,37 @@ namespace MWSound
|
||||||
root->addFrameListener(&updater);
|
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)
|
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
|
// Convert a Morrowind sound path (eg. Fx\funny.wav) to full path
|
||||||
// with proper slash conversion (eg. datadir/Sound/Fx/funny.wav)
|
// with proper slash conversion (eg. datadir/Sound/Fx/funny.wav)
|
||||||
std::string convertPath(const std::string &str)
|
std::string convertPath(const std::string &str)
|
||||||
{
|
{
|
||||||
if(hasFile(str))
|
// Search and return
|
||||||
|
if(files.has(str))
|
||||||
return files.lookup(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 "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,14 @@
|
||||||
namespace FileFinder
|
namespace FileFinder
|
||||||
{
|
{
|
||||||
|
|
||||||
class FileFinder
|
template <typename LESS>
|
||||||
|
class FileFinderT
|
||||||
{
|
{
|
||||||
std::map<std::string, std::string, path_less> table;
|
std::map<std::string, std::string, LESS> table;
|
||||||
|
|
||||||
struct Inserter : ReturnPath
|
struct Inserter : ReturnPath
|
||||||
{
|
{
|
||||||
FileFinder *owner;
|
FileFinderT<LESS> *owner;
|
||||||
int cut;
|
int cut;
|
||||||
|
|
||||||
void add(const boost::filesystem::path &pth)
|
void add(const boost::filesystem::path &pth)
|
||||||
|
@ -28,7 +29,7 @@ class FileFinder
|
||||||
Inserter inserter;
|
Inserter inserter;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FileFinder(const boost::filesystem::path &path, bool recurse=true)
|
FileFinderT(const boost::filesystem::path &path, bool recurse=true)
|
||||||
{
|
{
|
||||||
inserter.owner = this;
|
inserter.owner = this;
|
||||||
|
|
||||||
|
@ -58,5 +59,8 @@ public:
|
||||||
return table.find(file)->second;
|
return table.find(file)->second;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// The default is to use path_less for equality checks
|
||||||
|
typedef FileFinderT<path_less> FileFinder;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue