mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-06 03:45:35 +00:00
Fall back to top-level directory when looking for resources (Fixes #2169)
This commit is contained in:
parent
ac7c2a1473
commit
4a734f5cd3
1 changed files with 40 additions and 7 deletions
|
@ -4,6 +4,29 @@
|
||||||
|
|
||||||
#include <OgreResourceGroupManager.h>
|
#include <OgreResourceGroupManager.h>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
struct MatchPathSeparator
|
||||||
|
{
|
||||||
|
bool operator()( char ch ) const
|
||||||
|
{
|
||||||
|
return ch == '\\' || ch == '/';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string
|
||||||
|
getBasename( std::string const& pathname )
|
||||||
|
{
|
||||||
|
return std::string(
|
||||||
|
std::find_if( pathname.rbegin(), pathname.rend(),
|
||||||
|
MatchPathSeparator() ).base(),
|
||||||
|
pathname.end() );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bool Misc::ResourceHelpers::changeExtensionToDds(std::string &path)
|
bool Misc::ResourceHelpers::changeExtensionToDds(std::string &path)
|
||||||
{
|
{
|
||||||
Ogre::String::size_type pos = path.rfind('.');
|
Ogre::String::size_type pos = path.rfind('.');
|
||||||
|
@ -40,14 +63,24 @@ std::string Misc::ResourceHelpers::correctResourcePath(const std::string &topLev
|
||||||
|
|
||||||
// since we know all (GOTY edition or less) textures end
|
// since we know all (GOTY edition or less) textures end
|
||||||
// in .dds, we change the extension
|
// in .dds, we change the extension
|
||||||
if (changeExtensionToDds(correctedPath))
|
bool changedToDds = changeExtensionToDds(correctedPath);
|
||||||
|
if (Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(correctedPath))
|
||||||
|
return correctedPath;
|
||||||
|
// if it turns out that the above wasn't true in all cases (not for vanilla, but maybe mods)
|
||||||
|
// verify, and revert if false (this call succeeds quickly, but fails slowly)
|
||||||
|
if (changedToDds && Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(origExt))
|
||||||
|
return origExt;
|
||||||
|
|
||||||
|
// fall back to a resource in the top level directory if it exists
|
||||||
|
std::string fallback = topLevelDirectory + "\\" + getBasename(correctedPath);
|
||||||
|
if (Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(fallback))
|
||||||
|
return fallback;
|
||||||
|
|
||||||
|
if (changedToDds)
|
||||||
{
|
{
|
||||||
// if it turns out that the above wasn't true in all cases (not for vanilla, but maybe mods)
|
fallback = topLevelDirectory + "\\" + getBasename(origExt);
|
||||||
// verify, and revert if false (this call succeeds quickly, but fails slowly)
|
if (Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(fallback))
|
||||||
if(!Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(correctedPath))
|
return fallback;
|
||||||
{
|
|
||||||
return origExt;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return correctedPath;
|
return correctedPath;
|
||||||
|
|
Loading…
Reference in a new issue