|
|
@@ -485,34 +485,34 @@ void ResourceCache::RemoveResourceRouter(ResourceRouter* router)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-SharedPtr<File> ResourceCache::GetFile(const String& nameIn, bool sendEventOnFailure)
|
|
|
+SharedPtr<File> ResourceCache::GetFile(const String& name, bool sendEventOnFailure)
|
|
|
{
|
|
|
MutexLock lock(resourceMutex_);
|
|
|
|
|
|
- String name = SanitateResourceName(nameIn);
|
|
|
+ String sanitatedName = SanitateResourceName(name);
|
|
|
if (!isRouting_)
|
|
|
{
|
|
|
isRouting_ = true;
|
|
|
for (unsigned i = 0; i < resourceRouters_.Size(); ++i)
|
|
|
- resourceRouters_[i]->Route(name, RESOURCE_GETFILE);
|
|
|
+ resourceRouters_[i]->Route(sanitatedName, RESOURCE_GETFILE);
|
|
|
isRouting_ = false;
|
|
|
}
|
|
|
|
|
|
- if (name.Length())
|
|
|
+ if (sanitatedName.Length())
|
|
|
{
|
|
|
File* file = nullptr;
|
|
|
|
|
|
if (searchPackagesFirst_)
|
|
|
{
|
|
|
- file = SearchPackages(name);
|
|
|
+ file = SearchPackages(sanitatedName);
|
|
|
if (!file)
|
|
|
- file = SearchResourceDirs(name);
|
|
|
+ file = SearchResourceDirs(sanitatedName);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- file = SearchResourceDirs(name);
|
|
|
+ file = SearchResourceDirs(sanitatedName);
|
|
|
if (!file)
|
|
|
- file = SearchPackages(name);
|
|
|
+ file = SearchPackages(sanitatedName);
|
|
|
}
|
|
|
|
|
|
if (file)
|
|
|
@@ -521,17 +521,17 @@ SharedPtr<File> ResourceCache::GetFile(const String& nameIn, bool sendEventOnFai
|
|
|
|
|
|
if (sendEventOnFailure)
|
|
|
{
|
|
|
- if (resourceRouters_.Size() && name.Empty() && !nameIn.Empty())
|
|
|
- URHO3D_LOGERROR("Resource request " + nameIn + " was blocked");
|
|
|
+ if (resourceRouters_.Size() && sanitatedName.Empty() && !name.Empty())
|
|
|
+ URHO3D_LOGERROR("Resource request " + name + " was blocked");
|
|
|
else
|
|
|
- URHO3D_LOGERROR("Could not find resource " + name);
|
|
|
+ URHO3D_LOGERROR("Could not find resource " + sanitatedName);
|
|
|
|
|
|
if (Thread::IsMainThread())
|
|
|
{
|
|
|
using namespace ResourceNotFound;
|
|
|
|
|
|
VariantMap& eventData = GetEventDataMap();
|
|
|
- eventData[P_RESOURCENAME] = name.Length() ? name : nameIn;
|
|
|
+ eventData[P_RESOURCENAME] = sanitatedName.Length() ? sanitatedName : name;
|
|
|
SendEvent(E_RESOURCENOTFOUND, eventData);
|
|
|
}
|
|
|
}
|
|
|
@@ -539,41 +539,41 @@ SharedPtr<File> ResourceCache::GetFile(const String& nameIn, bool sendEventOnFai
|
|
|
return SharedPtr<File>();
|
|
|
}
|
|
|
|
|
|
-Resource* ResourceCache::GetExistingResource(StringHash type, const String& nameIn)
|
|
|
+Resource* ResourceCache::GetExistingResource(StringHash type, const String& name)
|
|
|
{
|
|
|
- String name = SanitateResourceName(nameIn);
|
|
|
+ String sanitatedName = SanitateResourceName(name);
|
|
|
|
|
|
if (!Thread::IsMainThread())
|
|
|
{
|
|
|
- URHO3D_LOGERROR("Attempted to get resource " + name + " from outside the main thread");
|
|
|
+ URHO3D_LOGERROR("Attempted to get resource " + sanitatedName + " from outside the main thread");
|
|
|
return nullptr;
|
|
|
}
|
|
|
|
|
|
// If empty name, return null pointer immediately
|
|
|
- if (name.Empty())
|
|
|
+ if (sanitatedName.Empty())
|
|
|
return nullptr;
|
|
|
|
|
|
- StringHash nameHash(name);
|
|
|
+ StringHash nameHash(sanitatedName);
|
|
|
|
|
|
const SharedPtr<Resource>& existing = FindResource(type, nameHash);
|
|
|
return existing;
|
|
|
}
|
|
|
|
|
|
-Resource* ResourceCache::GetResource(StringHash type, const String& nameIn, bool sendEventOnFailure)
|
|
|
+Resource* ResourceCache::GetResource(StringHash type, const String& name, bool sendEventOnFailure)
|
|
|
{
|
|
|
- String name = SanitateResourceName(nameIn);
|
|
|
+ String sanitatedName = SanitateResourceName(name);
|
|
|
|
|
|
if (!Thread::IsMainThread())
|
|
|
{
|
|
|
- URHO3D_LOGERROR("Attempted to get resource " + name + " from outside the main thread");
|
|
|
+ URHO3D_LOGERROR("Attempted to get resource " + sanitatedName + " from outside the main thread");
|
|
|
return nullptr;
|
|
|
}
|
|
|
|
|
|
// If empty name, return null pointer immediately
|
|
|
- if (name.Empty())
|
|
|
+ if (sanitatedName.Empty())
|
|
|
return nullptr;
|
|
|
|
|
|
- StringHash nameHash(name);
|
|
|
+ StringHash nameHash(sanitatedName);
|
|
|
|
|
|
#ifdef URHO3D_THREADING
|
|
|
// Check if the resource is being background loaded but is now needed immediately
|
|
|
@@ -604,12 +604,12 @@ Resource* ResourceCache::GetResource(StringHash type, const String& nameIn, bool
|
|
|
}
|
|
|
|
|
|
// Attempt to load the resource
|
|
|
- SharedPtr<File> file = GetFile(name, sendEventOnFailure);
|
|
|
+ SharedPtr<File> file = GetFile(sanitatedName, sendEventOnFailure);
|
|
|
if (!file)
|
|
|
return nullptr; // Error is already logged
|
|
|
|
|
|
- URHO3D_LOGDEBUG("Loading resource " + name);
|
|
|
- resource->SetName(name);
|
|
|
+ URHO3D_LOGDEBUG("Loading resource " + sanitatedName);
|
|
|
+ resource->SetName(sanitatedName);
|
|
|
|
|
|
if (!resource->Load(*(file.Get())))
|
|
|
{
|
|
|
@@ -619,7 +619,7 @@ Resource* ResourceCache::GetResource(StringHash type, const String& nameIn, bool
|
|
|
using namespace LoadFailed;
|
|
|
|
|
|
VariantMap& eventData = GetEventDataMap();
|
|
|
- eventData[P_RESOURCENAME] = name;
|
|
|
+ eventData[P_RESOURCENAME] = sanitatedName;
|
|
|
SendEvent(E_LOADFAILED, eventData);
|
|
|
}
|
|
|
|
|
|
@@ -635,32 +635,32 @@ Resource* ResourceCache::GetResource(StringHash type, const String& nameIn, bool
|
|
|
return resource;
|
|
|
}
|
|
|
|
|
|
-bool ResourceCache::BackgroundLoadResource(StringHash type, const String& nameIn, bool sendEventOnFailure, Resource* caller)
|
|
|
+bool ResourceCache::BackgroundLoadResource(StringHash type, const String& name, bool sendEventOnFailure, Resource* caller)
|
|
|
{
|
|
|
#ifdef URHO3D_THREADING
|
|
|
// If empty name, fail immediately
|
|
|
- String name = SanitateResourceName(nameIn);
|
|
|
- if (name.Empty())
|
|
|
+ String sanitatedName = SanitateResourceName(name);
|
|
|
+ if (sanitatedName.Empty())
|
|
|
return false;
|
|
|
|
|
|
// First check if already exists as a loaded resource
|
|
|
- StringHash nameHash(name);
|
|
|
+ StringHash nameHash(sanitatedName);
|
|
|
if (FindResource(type, nameHash) != noResource)
|
|
|
return false;
|
|
|
|
|
|
- return backgroundLoader_->QueueResource(type, name, sendEventOnFailure, caller);
|
|
|
+ return backgroundLoader_->QueueResource(type, sanitatedName, sendEventOnFailure, caller);
|
|
|
#else
|
|
|
// When threading not supported, fall back to synchronous loading
|
|
|
- return GetResource(type, nameIn, sendEventOnFailure);
|
|
|
+ return GetResource(type, name, sendEventOnFailure);
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
-SharedPtr<Resource> ResourceCache::GetTempResource(StringHash type, const String& nameIn, bool sendEventOnFailure)
|
|
|
+SharedPtr<Resource> ResourceCache::GetTempResource(StringHash type, const String& name, bool sendEventOnFailure)
|
|
|
{
|
|
|
- String name = SanitateResourceName(nameIn);
|
|
|
+ String sanitatedName = SanitateResourceName(name);
|
|
|
|
|
|
// If empty name, return null pointer immediately
|
|
|
- if (name.Empty())
|
|
|
+ if (sanitatedName.Empty())
|
|
|
return SharedPtr<Resource>();
|
|
|
|
|
|
SharedPtr<Resource> resource;
|
|
|
@@ -683,11 +683,11 @@ SharedPtr<Resource> ResourceCache::GetTempResource(StringHash type, const String
|
|
|
}
|
|
|
|
|
|
// Attempt to load the resource
|
|
|
- SharedPtr<File> file = GetFile(name, sendEventOnFailure);
|
|
|
+ SharedPtr<File> file = GetFile(sanitatedName, sendEventOnFailure);
|
|
|
if (!file)
|
|
|
return SharedPtr<Resource>(); // Error is already logged
|
|
|
|
|
|
- URHO3D_LOGDEBUG("Loading temporary resource " + name);
|
|
|
+ URHO3D_LOGDEBUG("Loading temporary resource " + sanitatedName);
|
|
|
resource->SetName(file->GetName());
|
|
|
|
|
|
if (!resource->Load(*(file.Get())))
|
|
|
@@ -698,7 +698,7 @@ SharedPtr<Resource> ResourceCache::GetTempResource(StringHash type, const String
|
|
|
using namespace LoadFailed;
|
|
|
|
|
|
VariantMap& eventData = GetEventDataMap();
|
|
|
- eventData[P_RESOURCENAME] = name;
|
|
|
+ eventData[P_RESOURCENAME] = sanitatedName;
|
|
|
SendEvent(E_LOADFAILED, eventData);
|
|
|
}
|
|
|
|
|
|
@@ -729,37 +729,37 @@ void ResourceCache::GetResources(PODVector<Resource*>& result, StringHash type)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-bool ResourceCache::Exists(const String& nameIn) const
|
|
|
+bool ResourceCache::Exists(const String& name) const
|
|
|
{
|
|
|
MutexLock lock(resourceMutex_);
|
|
|
|
|
|
- String name = SanitateResourceName(nameIn);
|
|
|
+ String sanitatedName = SanitateResourceName(name);
|
|
|
if (!isRouting_)
|
|
|
{
|
|
|
isRouting_ = true;
|
|
|
for (unsigned i = 0; i < resourceRouters_.Size(); ++i)
|
|
|
- resourceRouters_[i]->Route(name, RESOURCE_CHECKEXISTS);
|
|
|
+ resourceRouters_[i]->Route(sanitatedName, RESOURCE_CHECKEXISTS);
|
|
|
isRouting_ = false;
|
|
|
}
|
|
|
|
|
|
- if (name.Empty())
|
|
|
+ if (sanitatedName.Empty())
|
|
|
return false;
|
|
|
|
|
|
for (unsigned i = 0; i < packages_.Size(); ++i)
|
|
|
{
|
|
|
- if (packages_[i]->Exists(name))
|
|
|
+ if (packages_[i]->Exists(sanitatedName))
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
auto* fileSystem = GetSubsystem<FileSystem>();
|
|
|
for (unsigned i = 0; i < resourceDirs_.Size(); ++i)
|
|
|
{
|
|
|
- if (fileSystem->FileExists(resourceDirs_[i] + name))
|
|
|
+ if (fileSystem->FileExists(resourceDirs_[i] + sanitatedName))
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
// Fallback using absolute path
|
|
|
- return fileSystem->FileExists(name);
|
|
|
+ return fileSystem->FileExists(sanitatedName);
|
|
|
}
|
|
|
|
|
|
unsigned long long ResourceCache::GetMemoryBudget(StringHash type) const
|
|
|
@@ -838,18 +838,18 @@ String ResourceCache::GetPreferredResourceDir(const String& path) const
|
|
|
return fixedPath;
|
|
|
}
|
|
|
|
|
|
-String ResourceCache::SanitateResourceName(const String& nameIn) const
|
|
|
+String ResourceCache::SanitateResourceName(const String& name) const
|
|
|
{
|
|
|
// Sanitate unsupported constructs from the resource name
|
|
|
- String name = GetInternalPath(nameIn);
|
|
|
- name.Replace("../", "");
|
|
|
- name.Replace("./", "");
|
|
|
+ String sanitatedName = GetInternalPath(name);
|
|
|
+ sanitatedName.Replace("../", "");
|
|
|
+ sanitatedName.Replace("./", "");
|
|
|
|
|
|
// If the path refers to one of the resource directories, normalize the resource name
|
|
|
auto* fileSystem = GetSubsystem<FileSystem>();
|
|
|
if (resourceDirs_.Size())
|
|
|
{
|
|
|
- String namePath = GetPath(name);
|
|
|
+ String namePath = GetPath(sanitatedName);
|
|
|
String exePath = fileSystem->GetProgramDir().Replaced("/./", "/");
|
|
|
for (unsigned i = 0; i < resourceDirs_.Size(); ++i)
|
|
|
{
|
|
|
@@ -863,15 +863,15 @@ String ResourceCache::SanitateResourceName(const String& nameIn) const
|
|
|
namePath = namePath.Substring(relativeResourcePath.Length());
|
|
|
}
|
|
|
|
|
|
- name = namePath + GetFileNameAndExtension(name);
|
|
|
+ sanitatedName = namePath + GetFileNameAndExtension(sanitatedName);
|
|
|
}
|
|
|
|
|
|
- return name.Trimmed();
|
|
|
+ return sanitatedName.Trimmed();
|
|
|
}
|
|
|
|
|
|
-String ResourceCache::SanitateResourceDirName(const String& nameIn) const
|
|
|
+String ResourceCache::SanitateResourceDirName(const String& name) const
|
|
|
{
|
|
|
- String fixedPath = AddTrailingSlash(nameIn);
|
|
|
+ String fixedPath = AddTrailingSlash(name);
|
|
|
if (!IsAbsolutePath(fixedPath))
|
|
|
fixedPath = GetSubsystem<FileSystem>()->GetCurrentDir() + fixedPath;
|
|
|
|
|
|
@@ -1098,34 +1098,34 @@ void ResourceCache::HandleBeginFrame(StringHash eventType, VariantMap& eventData
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
-File* ResourceCache::SearchResourceDirs(const String& nameIn)
|
|
|
+File* ResourceCache::SearchResourceDirs(const String& name)
|
|
|
{
|
|
|
auto* fileSystem = GetSubsystem<FileSystem>();
|
|
|
for (unsigned i = 0; i < resourceDirs_.Size(); ++i)
|
|
|
{
|
|
|
- if (fileSystem->FileExists(resourceDirs_[i] + nameIn))
|
|
|
+ if (fileSystem->FileExists(resourceDirs_[i] + name))
|
|
|
{
|
|
|
// Construct the file first with full path, then rename it to not contain the resource path,
|
|
|
- // so that the file's name can be used in further GetFile() calls (for example over the network)
|
|
|
- File* file(new File(context_, resourceDirs_[i] + nameIn));
|
|
|
- file->SetName(nameIn);
|
|
|
+ // so that the file's sanitatedName can be used in further GetFile() calls (for example over the network)
|
|
|
+ File* file(new File(context_, resourceDirs_[i] + name));
|
|
|
+ file->SetName(name);
|
|
|
return file;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Fallback using absolute path
|
|
|
- if (fileSystem->FileExists(nameIn))
|
|
|
- return new File(context_, nameIn);
|
|
|
+ if (fileSystem->FileExists(name))
|
|
|
+ return new File(context_, name);
|
|
|
|
|
|
return nullptr;
|
|
|
}
|
|
|
|
|
|
-File* ResourceCache::SearchPackages(const String& nameIn)
|
|
|
+File* ResourceCache::SearchPackages(const String& name)
|
|
|
{
|
|
|
for (unsigned i = 0; i < packages_.Size(); ++i)
|
|
|
{
|
|
|
- if (packages_[i]->Exists(nameIn))
|
|
|
- return new File(context_, packages_[i], nameIn);
|
|
|
+ if (packages_[i]->Exists(name))
|
|
|
+ return new File(context_, packages_[i], name);
|
|
|
}
|
|
|
|
|
|
return nullptr;
|