forked from mirror/openmw-tes3mp
SoundManager: Set up the priority for file look up right and take care of a corner case
This commit is contained in:
parent
054a176c86
commit
ad6175c78a
3 changed files with 24 additions and 22 deletions
|
@ -71,9 +71,6 @@ namespace MWSound
|
|||
{
|
||||
if(useSound)
|
||||
{
|
||||
// Temporary list of all sound directories
|
||||
Files::PathContainer soundDirs;
|
||||
|
||||
// The music library will accept these filetypes
|
||||
// If none is given then it will accept all filetypes
|
||||
std::vector<std::string> acceptableExtensions;
|
||||
|
@ -82,16 +79,14 @@ namespace MWSound
|
|||
acceptableExtensions.push_back(".ogg");
|
||||
acceptableExtensions.push_back(".flac");
|
||||
|
||||
for (Files::PathContainer::const_iterator it = dataDirs.begin(); it != dataDirs.end(); ++it)
|
||||
// Makes a list of all sound files, searches in reverse for priority reasons
|
||||
for (Files::PathContainer::const_reverse_iterator it = dataDirs.rbegin(); it != dataDirs.rend(); ++it)
|
||||
{
|
||||
soundDirs.push_back( *it / std::string("Sound"));
|
||||
}
|
||||
for (Files::PathContainer::const_iterator it = soundDirs.begin(); it != soundDirs.end(); ++it)
|
||||
{
|
||||
Files::FileLister(*it, mSoundFiles, true);
|
||||
Files::FileLister(*it / std::string("Sound"), mSoundFiles, true);
|
||||
}
|
||||
|
||||
for (Files::PathContainer::const_iterator it = dataDirs.begin(); it != dataDirs.end(); ++it)
|
||||
// Makes a FileLibrary of all music files, searches in reverse for priority reasons
|
||||
for (Files::PathContainer::const_reverse_iterator it = dataDirs.rbegin(); it != dataDirs.rend(); ++it)
|
||||
{
|
||||
mMusicLibrary.add(*it / std::string("Music"), true, mFSStrict, acceptableExtensions);
|
||||
}
|
||||
|
@ -292,7 +287,6 @@ namespace MWSound
|
|||
|
||||
void SoundManager::streamMusic(const std::string& filename)
|
||||
{
|
||||
std::cout << filename << std::endl;
|
||||
std::string filePath = mMusicLibrary.locate(filename, mFSStrict).string();
|
||||
if(!filePath.empty())
|
||||
{
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
namespace Files
|
||||
|
@ -22,13 +23,24 @@ namespace Files
|
|||
void FileLibrary::add(const boost::filesystem::path &root, bool recursive, bool strict,
|
||||
const StringVector &acceptableExtensions)
|
||||
{
|
||||
PathContainer list;
|
||||
if (!boost::filesystem::exists(root))
|
||||
{
|
||||
std::cout << "Warning " << root.string() << " does not exist.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
std::string fileExtension;
|
||||
std::string type;
|
||||
FileLister(root, list, recursive);
|
||||
|
||||
for (PathContainer::iterator listIter = list.begin();
|
||||
listIter != list.end(); ++listIter)
|
||||
// remember the last location of the priority list when listing new items
|
||||
int length = mPriorityList.size();
|
||||
|
||||
// First makes a list of all candidate files
|
||||
FileLister(root, mPriorityList, recursive);
|
||||
|
||||
// Then sort these files into sections according to the folder they belong to
|
||||
for (PathContainer::iterator listIter = mPriorityList.begin() + length;
|
||||
listIter != mPriorityList.end(); ++listIter)
|
||||
{
|
||||
if( !acceptableExtensions.empty() )
|
||||
{
|
||||
|
@ -43,7 +55,7 @@ namespace Files
|
|||
boost::algorithm::to_lower(type);
|
||||
|
||||
mMap[type].push_back(*listIter);
|
||||
//std::cout << "Added path: " << listIter->string() << " in section "<< type <<std::endl;
|
||||
// std::cout << "Added path: " << listIter->string() << " in section "<< type <<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,12 +94,7 @@ namespace Files
|
|||
boost::filesystem::path result("");
|
||||
if (sectionName == "")
|
||||
{
|
||||
for(StringPathContMap::iterator iter = mMap.begin(); iter != mMap.end(); iter++)
|
||||
{
|
||||
result = FileListLocator(iter->second, boost::filesystem::path(item), strict);
|
||||
if (result != boost::filesystem::path(""))
|
||||
return result;
|
||||
}
|
||||
return FileListLocator(mPriorityList, boost::filesystem::path(item), strict);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace Files
|
|||
private:
|
||||
StringPathContMap mMap;
|
||||
PathContainer mEmptyPath;
|
||||
PathContainer mPriorityList;
|
||||
|
||||
public:
|
||||
/// Searches a path and adds the results to the library
|
||||
|
|
Loading…
Reference in a new issue