gui: clean up error handling in resource manager
Change-Id: Ib94e661ab0c608deb2d119168709c85a9a44b2fa
diff --git a/gui/resources.cpp b/gui/resources.cpp
index 74f020b..0d32cee 100644
--- a/gui/resources.cpp
+++ b/gui/resources.cpp
@@ -256,82 +256,45 @@
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");
}
}