Change normalizeFilename signature

pull/3117/head
Cédric Mocquillon 3 years ago
parent d4e26746a3
commit c2df0949e2

@ -66,13 +66,10 @@ namespace MWGui
void LoadingScreen::findSplashScreens() void LoadingScreen::findSplashScreens()
{ {
std::string pattern = "Splash/";
mResourceSystem->getVFS()->normalizeFilename(pattern);
/* priority given to the left */ /* priority given to the left */
const std::array<std::string, 7> supported_extensions {{".tga", ".dds", ".ktx", ".png", ".bmp", ".jpeg", ".jpg"}}; const std::array<std::string, 7> supported_extensions {{".tga", ".dds", ".ktx", ".png", ".bmp", ".jpeg", ".jpg"}};
for (const auto& name : mResourceSystem->getVFS()->getRecursiveDirectoryIterator(pattern)) for (const auto& name : mResourceSystem->getVFS()->getRecursiveDirectoryIterator("Splash/"))
{ {
size_t pos = name.find_last_of('.'); size_t pos = name.find_last_of('.');
if (pos != std::string::npos) if (pos != std::string::npos)

@ -598,8 +598,6 @@ namespace MWRender
} }
animationPath.replace(animationPath.size()-3, 3, "/"); animationPath.replace(animationPath.size()-3, 3, "/");
mResourceSystem->getVFS()->normalizeFilename(animationPath);
for (const auto& name : mResourceSystem->getVFS()->getRecursiveDirectoryIterator(animationPath)) for (const auto& name : mResourceSystem->getVFS()->getRecursiveDirectoryIterator(animationPath))
{ {
size_t pos = name.find_last_of('.'); size_t pos = name.find_last_of('.');
@ -1292,8 +1290,6 @@ namespace MWRender
} }
animationPath.replace(animationPath.size()-4, 4, "/"); animationPath.replace(animationPath.size()-4, 4, "/");
resourceSystem->getVFS()->normalizeFilename(animationPath);
for (const auto& name : resourceSystem->getVFS()->getRecursiveDirectoryIterator(animationPath)) for (const auto& name : resourceSystem->getVFS()->getRecursiveDirectoryIterator(animationPath))
{ {
size_t pos = name.find_last_of('.'); size_t pos = name.find_last_of('.');

@ -131,7 +131,7 @@ namespace MWSound
max = std::max(min, max); max = std::max(min, max);
Sound_Buffer& sfx = mSoundBuffers.emplace_back("Sound/" + sound.mSound, volume, min, max); Sound_Buffer& sfx = mSoundBuffers.emplace_back("Sound/" + sound.mSound, volume, min, max);
mVfs->normalizeFilename(sfx.mResourceName); sfx.mResourceName = mVfs->normalizeFilename(sfx.mResourceName);
mBufferNameMap.emplace(soundId, &sfx); mBufferNameMap.emplace(soundId, &sfx);
return &sfx; return &sfx;

@ -295,10 +295,7 @@ namespace MWSound
{ {
std::vector<std::string> filelist; std::vector<std::string> filelist;
std::string pattern = "Music/" + playlist; for (const auto& name : mVFS->getRecursiveDirectoryIterator("Music/" + playlist))
mVFS->normalizeFilename(pattern);
for (const auto& name : mVFS->getRecursiveDirectoryIterator(pattern))
filelist.push_back(name); filelist.push_back(name);
mMusicFiles[playlist] = filelist; mMusicFiles[playlist] = filelist;
@ -345,10 +342,7 @@ namespace MWSound
if(!mOutput->isInitialized()) if(!mOutput->isInitialized())
return; return;
std::string voicefile = "Sound/"+filename; DecoderPtr decoder = loadVoice(mVFS->normalizeFilename("Sound/" + filename));
mVFS->normalizeFilename(voicefile);
DecoderPtr decoder = loadVoice(voicefile);
if (!decoder) if (!decoder)
return; return;
@ -379,10 +373,7 @@ namespace MWSound
if(!mOutput->isInitialized()) if(!mOutput->isInitialized())
return; return;
std::string voicefile = "Sound/"+filename; DecoderPtr decoder = loadVoice(mVFS->normalizeFilename("Sound/" + filename));
mVFS->normalizeFilename(voicefile);
DecoderPtr decoder = loadVoice(voicefile);
if (!decoder) if (!decoder)
return; return;

@ -191,10 +191,7 @@ namespace Gui
void FontLoader::loadBitmapFonts(bool exportToFile) void FontLoader::loadBitmapFonts(bool exportToFile)
{ {
std::string pattern = "Fonts/"; for (const auto& name : mVFS->getRecursiveDirectoryIterator("Fonts/"))
mVFS->normalizeFilename(pattern);
for (const auto& name : mVFS->getRecursiveDirectoryIterator(pattern))
{ {
size_t pos = name.find_last_of('.'); size_t pos = name.find_last_of('.');
if (pos != std::string::npos && name.compare(pos, name.size() - pos, ".fnt") == 0) if (pos != std::string::npos && name.compare(pos, name.size() - pos, ".fnt") == 0)

@ -121,8 +121,7 @@ BulletShapeManager::~BulletShapeManager()
osg::ref_ptr<const BulletShape> BulletShapeManager::getShape(const std::string &name) osg::ref_ptr<const BulletShape> BulletShapeManager::getShape(const std::string &name)
{ {
std::string normalized = name; const std::string normalized = mVFS->normalizeFilename(name);
mVFS->normalizeFilename(normalized);
osg::ref_ptr<BulletShape> shape; osg::ref_ptr<BulletShape> shape;
osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(normalized); osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(normalized);
@ -180,8 +179,7 @@ osg::ref_ptr<const BulletShape> BulletShapeManager::getShape(const std::string &
osg::ref_ptr<BulletShapeInstance> BulletShapeManager::cacheInstance(const std::string &name) osg::ref_ptr<BulletShapeInstance> BulletShapeManager::cacheInstance(const std::string &name)
{ {
std::string normalized = name; const std::string normalized = mVFS->normalizeFilename(name);
mVFS->normalizeFilename(normalized);
osg::ref_ptr<BulletShapeInstance> instance = createInstance(normalized); osg::ref_ptr<BulletShapeInstance> instance = createInstance(normalized);
if (instance) if (instance)
@ -191,8 +189,7 @@ osg::ref_ptr<BulletShapeInstance> BulletShapeManager::cacheInstance(const std::s
osg::ref_ptr<BulletShapeInstance> BulletShapeManager::getInstance(const std::string &name) osg::ref_ptr<BulletShapeInstance> BulletShapeManager::getInstance(const std::string &name)
{ {
std::string normalized = name; const std::string normalized = mVFS->normalizeFilename(name);
mVFS->normalizeFilename(normalized);
osg::ref_ptr<osg::Object> obj = mInstanceCache->takeFromObjectCache(normalized); osg::ref_ptr<osg::Object> obj = mInstanceCache->takeFromObjectCache(normalized);
if (obj.get()) if (obj.get())

@ -83,8 +83,7 @@ namespace Resource
osg::ref_ptr<osg::Image> ImageManager::getImage(const std::string &filename) osg::ref_ptr<osg::Image> ImageManager::getImage(const std::string &filename)
{ {
std::string normalized = filename; const std::string normalized = mVFS->normalizeFilename(filename);
mVFS->normalizeFilename(normalized);
osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(normalized); osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(normalized);
if (obj) if (obj)

@ -133,8 +133,7 @@ namespace Resource
osg::ref_ptr<const SceneUtil::KeyframeHolder> KeyframeManager::get(const std::string &name) osg::ref_ptr<const SceneUtil::KeyframeHolder> KeyframeManager::get(const std::string &name)
{ {
std::string normalized = name; const std::string normalized = mVFS->normalizeFilename(name);
mVFS->normalizeFilename(normalized);
osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(normalized); osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(normalized);
if (obj) if (obj)

@ -358,10 +358,7 @@ namespace Resource
bool SceneManager::checkLoaded(const std::string &name, double timeStamp) bool SceneManager::checkLoaded(const std::string &name, double timeStamp)
{ {
std::string normalized = name; return mCache->checkInObjectCache(mVFS->normalizeFilename(name), timeStamp);
mVFS->normalizeFilename(normalized);
return mCache->checkInObjectCache(normalized, timeStamp);
} }
/// @brief Callback to read image files from the VFS. /// @brief Callback to read image files from the VFS.
@ -533,8 +530,7 @@ namespace Resource
osg::ref_ptr<const osg::Node> SceneManager::getTemplate(const std::string &name, bool compile) osg::ref_ptr<const osg::Node> SceneManager::getTemplate(const std::string &name, bool compile)
{ {
std::string normalized = name; std::string normalized = mVFS->normalizeFilename(name);
mVFS->normalizeFilename(normalized);
osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(normalized); osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(normalized);
if (obj) if (obj)
@ -603,8 +599,7 @@ namespace Resource
osg::ref_ptr<osg::Node> SceneManager::cacheInstance(const std::string &name) osg::ref_ptr<osg::Node> SceneManager::cacheInstance(const std::string &name)
{ {
std::string normalized = name; const std::string normalized = mVFS->normalizeFilename(name);
mVFS->normalizeFilename(normalized);
osg::ref_ptr<osg::Node> node = createInstance(normalized); osg::ref_ptr<osg::Node> node = createInstance(normalized);
@ -642,8 +637,7 @@ namespace Resource
osg::ref_ptr<osg::Node> SceneManager::getInstance(const std::string &name) osg::ref_ptr<osg::Node> SceneManager::getInstance(const std::string &name)
{ {
std::string normalized = name; const std::string normalized = mVFS->normalizeFilename(name);
mVFS->normalizeFilename(normalized);
osg::ref_ptr<osg::Object> obj = mInstanceCache->takeFromObjectCache(normalized); osg::ref_ptr<osg::Object> obj = mInstanceCache->takeFromObjectCache(normalized);
if (obj.get()) if (obj.get())

@ -86,9 +86,11 @@ namespace VFS
return mIndex.find(normalized) != mIndex.end(); return mIndex.find(normalized) != mIndex.end();
} }
void Manager::normalizeFilename(std::string &name) const std::string Manager::normalizeFilename(const std::string& name) const
{ {
normalize_path(name, mStrict); std::string result = name;
normalize_path(result, mStrict);
return result;
} }
std::string Manager::getArchive(const std::string& name) const std::string Manager::getArchive(const std::string& name) const
@ -105,6 +107,6 @@ namespace VFS
RecursiveDirectoryIterator Manager::getRecursiveDirectoryIterator(const std::string& path) const RecursiveDirectoryIterator Manager::getRecursiveDirectoryIterator(const std::string& path) const
{ {
return RecursiveDirectoryIterator(mIndex, path); return RecursiveDirectoryIterator(mIndex, normalizeFilename(path));
} }
} }

@ -87,7 +87,7 @@ namespace VFS
/// Normalize the given filename, making slashes/backslashes consistent, and lower-casing if mStrict is false. /// Normalize the given filename, making slashes/backslashes consistent, and lower-casing if mStrict is false.
/// @note May be called from any thread once the index has been built. /// @note May be called from any thread once the index has been built.
void normalizeFilename(std::string& name) const; [[nodiscard]] std::string normalizeFilename(const std::string& name) const;
/// Retrieve a file by name. /// Retrieve a file by name.
/// @note Throws an exception if the file can not be found. /// @note Throws an exception if the file can not be found.

Loading…
Cancel
Save