Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1 | // resource.cpp - Source to manage GUI resources |
| 2 | |
| 3 | #include <stdarg.h> |
| 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> |
| 6 | #include <string.h> |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 7 | #include <unistd.h> |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 8 | |
| 9 | #include <string> |
| 10 | #include <sstream> |
| 11 | #include <iostream> |
| 12 | #include <iomanip> |
| 13 | |
that | b2e8f67 | 2015-03-05 20:25:39 +0100 | [diff] [blame] | 14 | #include "../minzip/Zip.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 15 | extern "C" { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 16 | #include "../twcommon.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 17 | #include "../minuitwrp/minui.h" |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 18 | #include "gui.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | #include "rapidxml.hpp" |
| 22 | #include "objects.hpp" |
| 23 | |
| 24 | #define TMP_RESOURCE_NAME "/tmp/extract.bin" |
| 25 | |
| 26 | Resource::Resource(xml_node<>* node, ZipArchive* pZip) |
| 27 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 28 | if (node && node->first_attribute("name")) |
| 29 | mName = node->first_attribute("name")->value(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 30 | } |
| 31 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 32 | int Resource::ExtractResource(ZipArchive* pZip, std::string folderName, std::string fileName, std::string fileExtn, std::string destFile) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 33 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 34 | if (!pZip) |
| 35 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 36 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 37 | std::string src = folderName + "/" + fileName + fileExtn; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 38 | |
| 39 | const ZipEntry* binary = mzFindZipEntry(pZip, src.c_str()); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 40 | if (binary == NULL) { |
| 41 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 42 | } |
| 43 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 44 | unlink(destFile.c_str()); |
| 45 | int fd = creat(destFile.c_str(), 0666); |
| 46 | if (fd < 0) |
| 47 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 48 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 49 | int ret = 0; |
| 50 | if (!mzExtractZipEntryToFile(pZip, binary, fd)) |
| 51 | ret = -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 52 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 53 | close(fd); |
| 54 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 55 | } |
| 56 | |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 57 | void Resource::LoadImage(ZipArchive* pZip, std::string file, gr_surface* source) |
| 58 | { |
| 59 | if (ExtractResource(pZip, "images", file, ".png", TMP_RESOURCE_NAME) == 0) |
| 60 | { |
| 61 | res_create_surface(TMP_RESOURCE_NAME, source); |
| 62 | unlink(TMP_RESOURCE_NAME); |
| 63 | } |
| 64 | else if (ExtractResource(pZip, "images", file, "", TMP_RESOURCE_NAME) == 0) |
| 65 | { |
| 66 | // JPG includes the .jpg extension in the filename so extension should be blank |
| 67 | res_create_surface(TMP_RESOURCE_NAME, source); |
| 68 | unlink(TMP_RESOURCE_NAME); |
| 69 | } |
| 70 | else if (!pZip) |
| 71 | { |
| 72 | // File name in xml may have included .png so try without adding .png |
| 73 | res_create_surface(file.c_str(), source); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | void Resource::CheckAndScaleImage(gr_surface source, gr_surface* destination, int retain_aspect) |
| 78 | { |
| 79 | if (!source) { |
| 80 | *destination = NULL; |
| 81 | return; |
| 82 | } |
| 83 | if (get_scale_w() != 0 && get_scale_h() != 0) { |
| 84 | float scale_w = get_scale_w(), scale_h = get_scale_h(); |
| 85 | if (retain_aspect) { |
| 86 | if (scale_w < scale_h) |
| 87 | scale_h = scale_w; |
| 88 | else |
| 89 | scale_w = scale_h; |
| 90 | } |
| 91 | if (res_scale_surface(source, destination, scale_w, scale_h)) { |
| 92 | LOGINFO("Error scaling image, using regular size.\n"); |
| 93 | *destination = source; |
| 94 | } |
| 95 | } else { |
| 96 | *destination = source; |
| 97 | } |
| 98 | } |
| 99 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 100 | FontResource::FontResource(xml_node<>* node, ZipArchive* pZip) |
| 101 | : Resource(node, pZip) |
| 102 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 103 | std::string file; |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 104 | xml_attribute<>* attr; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 105 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 106 | mFont = NULL; |
| 107 | if (!node) |
| 108 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 109 | |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 110 | attr = node->first_attribute("filename"); |
| 111 | if (!attr) |
| 112 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 113 | |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 114 | file = attr->value(); |
| 115 | |
| 116 | #ifndef TW_DISABLE_TTF |
| 117 | if(file.size() >= 4 && file.compare(file.size()-4, 4, ".ttf") == 0) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 118 | { |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 119 | m_type = TYPE_TTF; |
| 120 | |
| 121 | attr = node->first_attribute("size"); |
| 122 | if(!attr) |
| 123 | return; |
| 124 | |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 125 | int size = scale_theme_min(atoi(attr->value())); |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 126 | int dpi = 300; |
| 127 | |
| 128 | attr = node->first_attribute("dpi"); |
| 129 | if(attr) |
| 130 | dpi = atoi(attr->value()); |
| 131 | |
| 132 | if (ExtractResource(pZip, "fonts", file, "", TMP_RESOURCE_NAME) == 0) |
| 133 | { |
| 134 | mFont = gr_ttf_loadFont(TMP_RESOURCE_NAME, size, dpi); |
| 135 | unlink(TMP_RESOURCE_NAME); |
| 136 | } |
| 137 | else |
| 138 | { |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 139 | file = std::string(TWRES "fonts/") + file; |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 140 | mFont = gr_ttf_loadFont(file.c_str(), size, dpi); |
| 141 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 142 | } |
| 143 | else |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 144 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 145 | { |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 146 | m_type = TYPE_TWRP; |
| 147 | |
| 148 | if(file.size() >= 4 && file.compare(file.size()-4, 4, ".ttf") == 0) |
| 149 | { |
| 150 | attr = node->first_attribute("fallback"); |
| 151 | if (!attr) |
| 152 | return; |
| 153 | |
| 154 | file = attr->value(); |
| 155 | } |
| 156 | |
| 157 | if (ExtractResource(pZip, "fonts", file, ".dat", TMP_RESOURCE_NAME) == 0) |
| 158 | { |
| 159 | mFont = gr_loadFont(TMP_RESOURCE_NAME); |
| 160 | unlink(TMP_RESOURCE_NAME); |
| 161 | } |
| 162 | else |
| 163 | { |
| 164 | mFont = gr_loadFont(file.c_str()); |
| 165 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 166 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | FontResource::~FontResource() |
| 170 | { |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 171 | if(mFont) |
| 172 | { |
| 173 | #ifndef TW_DISABLE_TTF |
| 174 | if(m_type == TYPE_TTF) |
| 175 | gr_ttf_freeFont(mFont); |
| 176 | else |
| 177 | #endif |
| 178 | gr_freeFont(mFont); |
| 179 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 180 | } |
| 181 | |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 182 | ImageResource::ImageResource(xml_node<>* node, ZipArchive* pZip, int retain_aspect) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 183 | : Resource(node, pZip) |
| 184 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 185 | std::string file; |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 186 | gr_surface temp_surface = NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 187 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 188 | mSurface = NULL; |
Ethan Yonker | 619a721 | 2014-12-03 16:47:37 -0600 | [diff] [blame] | 189 | if (!node) { |
| 190 | LOGERR("ImageResource node is NULL\n"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 191 | return; |
Ethan Yonker | 619a721 | 2014-12-03 16:47:37 -0600 | [diff] [blame] | 192 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 193 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 194 | if (node->first_attribute("filename")) |
| 195 | file = node->first_attribute("filename")->value(); |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 196 | else { |
| 197 | LOGERR("No filename specified for image resource.\n"); |
| 198 | return; |
| 199 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 200 | |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 201 | LoadImage(pZip, file, &temp_surface); |
| 202 | CheckAndScaleImage(temp_surface, &mSurface, retain_aspect); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | ImageResource::~ImageResource() |
| 206 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 207 | if (mSurface) |
| 208 | res_free_surface(mSurface); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 209 | } |
| 210 | |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 211 | AnimationResource::AnimationResource(xml_node<>* node, ZipArchive* pZip, int retain_aspect) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 212 | : Resource(node, pZip) |
| 213 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 214 | std::string file; |
| 215 | int fileNum = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 216 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 217 | if (!node) |
| 218 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 219 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 220 | if (node->first_attribute("filename")) |
| 221 | file = node->first_attribute("filename")->value(); |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 222 | else { |
| 223 | LOGERR("No filename specified for image resource.\n"); |
| 224 | return; |
| 225 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 226 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 227 | for (;;) |
| 228 | { |
| 229 | std::ostringstream fileName; |
| 230 | fileName << file << std::setfill ('0') << std::setw (3) << fileNum; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 231 | |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 232 | gr_surface surface, temp_surface = NULL; |
| 233 | LoadImage(pZip, fileName.str(), &temp_surface); |
| 234 | CheckAndScaleImage(temp_surface, &surface, retain_aspect); |
| 235 | if (surface) { |
| 236 | mSurfaces.push_back(surface); |
| 237 | fileNum++; |
| 238 | } else |
| 239 | break; // Done loading animation images |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 240 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | AnimationResource::~AnimationResource() |
| 244 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 245 | std::vector<gr_surface>::iterator it; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 246 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 247 | for (it = mSurfaces.begin(); it != mSurfaces.end(); ++it) |
| 248 | res_free_surface(*it); |
| 249 | |
| 250 | mSurfaces.clear(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 251 | } |
| 252 | |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 253 | FontResource* ResourceManager::FindFont(const std::string& name) const |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 254 | { |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 255 | for (std::vector<FontResource*>::const_iterator it = mFonts.begin(); it != mFonts.end(); ++it) |
| 256 | if (name == (*it)->GetName()) |
| 257 | return *it; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 258 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 259 | } |
| 260 | |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 261 | ImageResource* ResourceManager::FindImage(const std::string& name) const |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 262 | { |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 263 | for (std::vector<ImageResource*>::const_iterator it = mImages.begin(); it != mImages.end(); ++it) |
| 264 | if (name == (*it)->GetName()) |
| 265 | return *it; |
| 266 | return NULL; |
| 267 | } |
| 268 | |
| 269 | AnimationResource* ResourceManager::FindAnimation(const std::string& name) const |
| 270 | { |
| 271 | for (std::vector<AnimationResource*>::const_iterator it = mAnimations.begin(); it != mAnimations.end(); ++it) |
| 272 | if (name == (*it)->GetName()) |
| 273 | return *it; |
| 274 | return NULL; |
| 275 | } |
| 276 | |
that | b2e8f67 | 2015-03-05 20:25:39 +0100 | [diff] [blame] | 277 | std::string ResourceManager::FindString(const std::string& name) const |
| 278 | { |
| 279 | std::map<std::string, std::string>::const_iterator it = mStrings.find(name); |
| 280 | if (it != mStrings.end()) |
| 281 | return it->second; |
| 282 | return "[" + name + ("]"); |
| 283 | } |
| 284 | |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 285 | ResourceManager::ResourceManager() |
| 286 | { |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | void ResourceManager::LoadResources(xml_node<>* resList, ZipArchive* pZip) |
| 290 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 291 | if (!resList) |
| 292 | return; |
that | 0f42506 | 2015-03-04 23:05:00 +0100 | [diff] [blame] | 293 | |
| 294 | for (xml_node<>* child = resList->first_node(); child; child = child->next_sibling()) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 295 | { |
that | 0f42506 | 2015-03-04 23:05:00 +0100 | [diff] [blame] | 296 | std::string type = child->name(); |
| 297 | if (type == "resource") { |
| 298 | // legacy format : <resource type="..."> |
| 299 | xml_attribute<>* attr = child->first_attribute("type"); |
| 300 | type = attr ? attr->value() : "*unspecified*"; |
| 301 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 302 | |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 303 | bool error = false; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 304 | if (type == "font") |
| 305 | { |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 306 | FontResource* res = new FontResource(child, pZip); |
| 307 | if (res->GetResource()) |
| 308 | mFonts.push_back(res); |
| 309 | else { |
| 310 | error = true; |
| 311 | delete res; |
| 312 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 313 | } |
| 314 | else if (type == "image") |
| 315 | { |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 316 | int retain = 0; |
| 317 | xml_attribute<>* retain_aspect_ratio = child->first_attribute("retainaspect"); |
| 318 | if (retain_aspect_ratio) |
| 319 | retain = 1; // the value does not matter, if retainaspect is present, we assume that we want to retain it |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 320 | ImageResource* res = new ImageResource(child, pZip, retain); |
| 321 | if (res->GetResource()) |
| 322 | mImages.push_back(res); |
| 323 | else { |
| 324 | error = true; |
| 325 | delete res; |
| 326 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 327 | } |
| 328 | else if (type == "animation") |
| 329 | { |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 330 | int retain = 0; |
| 331 | xml_attribute<>* retain_aspect_ratio = child->first_attribute("retainaspect"); |
| 332 | if (retain_aspect_ratio) |
| 333 | retain = 1; // the value does not matter, if retainaspect is present, we assume that we want to retain it |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 334 | AnimationResource* res = new AnimationResource(child, pZip, retain); |
| 335 | if (res->GetResourceCount()) |
| 336 | mAnimations.push_back(res); |
| 337 | else { |
| 338 | error = true; |
| 339 | delete res; |
| 340 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 341 | } |
that | b2e8f67 | 2015-03-05 20:25:39 +0100 | [diff] [blame] | 342 | else if (type == "string") |
| 343 | { |
| 344 | if (xml_attribute<>* attr = child->first_attribute("name")) |
| 345 | mStrings[attr->value()] = child->value(); |
| 346 | else |
| 347 | error = true; |
| 348 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 349 | else |
| 350 | { |
| 351 | LOGERR("Resource type (%s) not supported.\n", type.c_str()); |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 352 | error = true; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 353 | } |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 354 | |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 355 | if (error) |
that | f74ac87 | 2015-01-18 12:00:02 +0100 | [diff] [blame] | 356 | { |
| 357 | std::string res_name; |
| 358 | if (child->first_attribute("name")) |
| 359 | res_name = child->first_attribute("name")->value(); |
| 360 | if (res_name.empty() && child->first_attribute("filename")) |
| 361 | res_name = child->first_attribute("filename")->value(); |
| 362 | |
| 363 | if (!res_name.empty()) { |
| 364 | LOGERR("Resource (%s)-(%s) failed to load\n", type.c_str(), res_name.c_str()); |
| 365 | } else |
| 366 | LOGERR("Resource type (%s) failed to load\n", type.c_str()); |
that | f74ac87 | 2015-01-18 12:00:02 +0100 | [diff] [blame] | 367 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 368 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | ResourceManager::~ResourceManager() |
| 372 | { |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 373 | for (std::vector<FontResource*>::iterator it = mFonts.begin(); it != mFonts.end(); ++it) |
| 374 | delete *it; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 375 | |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 376 | for (std::vector<ImageResource*>::iterator it = mImages.begin(); it != mImages.end(); ++it) |
| 377 | delete *it; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 378 | |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 379 | for (std::vector<AnimationResource*>::iterator it = mAnimations.begin(); it != mAnimations.end(); ++it) |
| 380 | delete *it; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 381 | } |