gui: clean up error handling in resource manager

Change-Id: Ib94e661ab0c608deb2d119168709c85a9a44b2fa
This commit is contained in:
that
2015-01-18 12:00:02 +01:00
parent 4a64f63615
commit f74ac8740c

View File

@@ -256,82 +256,45 @@ void ResourceManager::LoadResources(xml_node<>* resList, ZipArchive* pZip)
if (!attr)
break;
Resource* res = NULL;
std::string type = attr->value();
if (type == "font")
{
FontResource* res = new FontResource(child, pZip);
if (res == NULL || res->GetResource() == NULL)
{
std::string res_name;
if (child->first_attribute("name"))
res_name = child->first_attribute("name")->value();
if (res_name.empty() && child->first_attribute("filename"))
res_name = child->first_attribute("filename")->value();
if (!res_name.empty()) {
LOGERR("Resource (%s)-(%s) failed to load\n", type.c_str(), res_name.c_str());
} else
LOGERR("Resource type (%s) failed to load\n", type.c_str());
delete res;
}
else
{
mResources.push_back((Resource*) res);
}
res = new FontResource(child, pZip);
}
else if (type == "image")
{
ImageResource* res = new ImageResource(child, pZip);
if (res == NULL || res->GetResource() == NULL)
{
std::string res_name;
if (child->first_attribute("name"))
res_name = child->first_attribute("name")->value();
if (res_name.empty() && child->first_attribute("filename"))
res_name = child->first_attribute("filename")->value();
if (!res_name.empty()) {
LOGERR("Resource (%s)-(%s) failed to load\n", type.c_str(), res_name.c_str());
} else
LOGERR("Resource type (%s) failed to load\n", type.c_str());
delete res;
}
else
{
mResources.push_back((Resource*) res);
}
res = new ImageResource(child, pZip);
}
else if (type == "animation")
{
AnimationResource* res = new AnimationResource(child, pZip);
if (res == NULL || res->GetResource() == NULL)
{
std::string res_name;
if (child->first_attribute("name"))
res_name = child->first_attribute("name")->value();
if (res_name.empty() && child->first_attribute("filename"))
res_name = child->first_attribute("filename")->value();
if (!res_name.empty()) {
LOGERR("Resource (%s)-(%s) failed to load\n", type.c_str(), res_name.c_str());
} else
LOGERR("Resource type (%s) failed to load\n", type.c_str());
delete res;
}
else
{
mResources.push_back((Resource*) res);
}
res = new AnimationResource(child, pZip);
}
else
{
LOGERR("Resource type (%s) not supported.\n", type.c_str());
}
if (res == NULL || res->GetResource() == NULL)
{
std::string res_name;
if (child->first_attribute("name"))
res_name = child->first_attribute("name")->value();
if (res_name.empty() && child->first_attribute("filename"))
res_name = child->first_attribute("filename")->value();
if (!res_name.empty()) {
LOGERR("Resource (%s)-(%s) failed to load\n", type.c_str(), res_name.c_str());
} else
LOGERR("Resource type (%s) failed to load\n", type.c_str());
delete res;
}
else
{
mResources.push_back(res);
}
child = child->next_sibling("resource");
}
}