From f74ac8740cd745bf2bb4b8dcc5463fea9016dfd2 Mon Sep 17 00:00:00 2001 From: that Date: Sun, 18 Jan 2015 12:00:02 +0100 Subject: gui: clean up error handling in resource manager Change-Id: Ib94e661ab0c608deb2d119168709c85a9a44b2fa --- gui/resources.cpp | 85 ++++++++++++++++--------------------------------------- 1 file changed, 24 insertions(+), 61 deletions(-) (limited to 'gui') diff --git a/gui/resources.cpp b/gui/resources.cpp index 74f020b62..0d32ceee0 100644 --- a/gui/resources.cpp +++ b/gui/resources.cpp @@ -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"); } } -- cgit v1.2.3