bool ResourceManager::Exists(const char *ResRef, const TypeID *type, bool silent) const { if (ResRef[0] == '\0') return false; // TODO: check various caches const std::vector<ResourceDesc> &types = PluginMgr::Get()->GetResourceDesc(type); for (size_t j = 0; j < types.size(); j++) if (cacheMap.get(ConstructFilename(ResRef, types[j].GetExt()))) return true; for (size_t j = 0; j < types.size(); j++) { for (size_t i = 0; i < searchPath.size(); i++) { if (searchPath[i]->HasResource(ResRef, types[j])) { return true; } } } if (!silent) { printMessage("ResourceManager", "Searching for %s... ", WHITE, ResRef); print("Tried "); PrintPossibleFiles(ResRef,type); printStatus( "NOT FOUND", YELLOW ); } return false; }
Resource* ResourceManager::GetResource(const char* ResRef, const TypeID *type, bool silent) const { if (ResRef[0] == '\0') return NULL; if (!silent) { printMessage("ResourceManager", "Searching for %s... ", WHITE, ResRef); } const std::vector<ResourceDesc> &types = PluginMgr::Get()->GetResourceDesc(type); for (size_t j = 0; j < types.size(); j++) { FileStream *str = OpenCacheFile(ConstructFilename(ResRef, types[j].GetExt())); if (str) { Resource *res = types[j].Create(str); if (!silent) { print( "%s.%s...", ResRef, types[j].GetExt() ); printStatus("Cache", GREEN); } return res; } } for (size_t j = 0; j < types.size(); j++) { for (size_t i = 0; i < searchPath.size(); i++) { DataStream *str = searchPath[i]->GetResource(ResRef, types[j]); if (str) { Resource *res = types[j].Create(str); if (res) { if (!silent) { print( "%s.%s...", ResRef, types[j].GetExt() ); printStatus( searchPath[i]->GetDescription(), GREEN ); } return res; } } } } if (!silent) { print("Tried "); PrintPossibleFiles(ResRef,type); printStatus( "ERROR", LIGHT_RED ); } return NULL; }
bool ResourceManager::Exists(const char *ResRef, const TypeID *type, bool silent) const { if (ResRef[0] == '\0') return false; // TODO: check various caches const std::vector<ResourceDesc> &types = PluginMgr::Get()->GetResourceDesc(type); for (size_t j = 0; j < types.size(); j++) { for (size_t i = 0; i < searchPath.size(); i++) { if (searchPath[i]->HasResource(ResRef, types[j])) { return true; } } } if (!silent) { StringBuffer buffer; buffer.appendFormatted("Couldn't find '%s'... ", ResRef); buffer.append("Tried "); PrintPossibleFiles(buffer, ResRef,type); Log(WARNING, "ResourceManager", buffer); } return false; }
Resource* ResourceManager::GetResource(const char* ResRef, const TypeID *type, bool silent, bool useCorrupt) const { if (ResRef[0] == '\0') return NULL; if (!silent) { Log(MESSAGE, "ResourceManager", "Searching for '%s'...", ResRef); } const std::vector<ResourceDesc> &types = PluginMgr::Get()->GetResourceDesc(type); for (size_t j = 0; j < types.size(); j++) { for (size_t i = 0; i < searchPath.size(); i++) { DataStream *str = searchPath[i]->GetResource(ResRef, types[j]); if (!str && useCorrupt && core->UseCorruptedHack) { // don't look at other paths if requested core->UseCorruptedHack = false; return NULL; } core->UseCorruptedHack = false; if (str) { Resource *res = types[j].Create(str); if (res) { if (!silent) { Log(MESSAGE, "ResourceManager", "Found '%s.%s' in '%s'.", ResRef, types[j].GetExt(), searchPath[i]->GetDescription()); } return res; } } } } if (!silent) { StringBuffer buffer; buffer.appendFormatted("Couldn't find '%s'... ", ResRef); buffer.append("Tried "); PrintPossibleFiles(buffer, ResRef,type); Log(WARNING, "ResourceManager", buffer); } return NULL; }