blob: 5efa0933d0edc82e6b1dca75113e83e00879312d [file] [log] [blame]
Matt Mowere04eee72016-12-31 00:38:57 -06001/*
bigbiffd58ba182020-03-23 10:02:29 -04002 Copyright 2012 to 2020 TeamWin
Matt Mowere04eee72016-12-31 00:38:57 -06003 This file is part of TWRP/TeamWin Recovery Project.
4
5 TWRP is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 TWRP is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with TWRP. If not, see <http://www.gnu.org/licenses/>.
17*/
18
Dees_Troy51a0e822012-09-05 15:24:24 -040019// resource.cpp - Source to manage GUI resources
20
21#include <stdarg.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
Dees_Troy51a0e822012-09-05 15:24:24 -040025#include <unistd.h>
Dees_Troy51a0e822012-09-05 15:24:24 -040026
27#include <string>
28#include <sstream>
29#include <iostream>
30#include <iomanip>
Ethan Yonker3fdcda42016-11-30 12:29:37 -060031#include <fcntl.h>
Dees_Troy51a0e822012-09-05 15:24:24 -040032
bigbiffd58ba182020-03-23 10:02:29 -040033#include "zipwrap.hpp"
Dees_Troy51a0e822012-09-05 15:24:24 -040034extern "C" {
Dees_Troy2673cec2013-04-02 20:22:16 +000035#include "../twcommon.h"
Ethan Yonker63e414f2015-02-06 15:44:39 -060036#include "gui.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040037}
bigbiffd58ba182020-03-23 10:02:29 -040038
39#include "../minuitwrp/truetype.hpp"
Ethan Yonkerfbb43532015-12-28 21:54:50 +010040#include "../minuitwrp/minui.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040041
42#include "rapidxml.hpp"
43#include "objects.hpp"
44
45#define TMP_RESOURCE_NAME "/tmp/extract.bin"
46
Ethan Yonker8373cfe2017-09-08 06:50:54 -050047Resource::Resource(xml_node<>* node, ZipWrap* pZip __unused)
Dees_Troy51a0e822012-09-05 15:24:24 -040048{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020049 if (node && node->first_attribute("name"))
50 mName = node->first_attribute("name")->value();
Dees_Troy51a0e822012-09-05 15:24:24 -040051}
52
Ethan Yonker8373cfe2017-09-08 06:50:54 -050053int Resource::ExtractResource(ZipWrap* pZip, std::string folderName, std::string fileName, std::string fileExtn, std::string destFile)
Dees_Troy51a0e822012-09-05 15:24:24 -040054{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020055 if (!pZip)
56 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -040057
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020058 std::string src = folderName + "/" + fileName + fileExtn;
Ethan Yonker8373cfe2017-09-08 06:50:54 -050059 if (!pZip->ExtractEntry(src, destFile, 0666))
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020060 return -1;
Ethan Yonker8373cfe2017-09-08 06:50:54 -050061 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -040062}
63
Ethan Yonker8373cfe2017-09-08 06:50:54 -050064void Resource::LoadImage(ZipWrap* pZip, std::string file, gr_surface* surface)
Ethan Yonker63e414f2015-02-06 15:44:39 -060065{
thatb240f4a2016-03-14 01:21:38 +010066 int rc = 0;
Ethan Yonker63e414f2015-02-06 15:44:39 -060067 if (ExtractResource(pZip, "images", file, ".png", TMP_RESOURCE_NAME) == 0)
68 {
thatb240f4a2016-03-14 01:21:38 +010069 rc = res_create_surface(TMP_RESOURCE_NAME, surface);
Ethan Yonker63e414f2015-02-06 15:44:39 -060070 unlink(TMP_RESOURCE_NAME);
71 }
72 else if (ExtractResource(pZip, "images", file, "", TMP_RESOURCE_NAME) == 0)
73 {
74 // JPG includes the .jpg extension in the filename so extension should be blank
thatb240f4a2016-03-14 01:21:38 +010075 rc = res_create_surface(TMP_RESOURCE_NAME, surface);
Ethan Yonker63e414f2015-02-06 15:44:39 -060076 unlink(TMP_RESOURCE_NAME);
77 }
78 else if (!pZip)
79 {
80 // File name in xml may have included .png so try without adding .png
thatb240f4a2016-03-14 01:21:38 +010081 rc = res_create_surface(file.c_str(), surface);
Ethan Yonker63e414f2015-02-06 15:44:39 -060082 }
thatb240f4a2016-03-14 01:21:38 +010083 if (rc != 0)
84 LOGINFO("Failed to load image from %s%s, error %d\n", file.c_str(), pZip ? " (zip)" : "", rc);
Ethan Yonker63e414f2015-02-06 15:44:39 -060085}
86
87void Resource::CheckAndScaleImage(gr_surface source, gr_surface* destination, int retain_aspect)
88{
89 if (!source) {
90 *destination = NULL;
91 return;
92 }
93 if (get_scale_w() != 0 && get_scale_h() != 0) {
94 float scale_w = get_scale_w(), scale_h = get_scale_h();
95 if (retain_aspect) {
96 if (scale_w < scale_h)
97 scale_h = scale_w;
98 else
99 scale_w = scale_h;
100 }
101 if (res_scale_surface(source, destination, scale_w, scale_h)) {
102 LOGINFO("Error scaling image, using regular size.\n");
103 *destination = source;
104 }
105 } else {
106 *destination = source;
107 }
108}
109
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500110FontResource::FontResource(xml_node<>* node, ZipWrap* pZip)
Dees_Troy51a0e822012-09-05 15:24:24 -0400111 : Resource(node, pZip)
112{
Ethan Yonker74db1572015-10-28 12:44:49 -0500113 origFontSize = 0;
114 origFont = NULL;
115 LoadFont(node, pZip);
116}
117
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500118void FontResource::LoadFont(xml_node<>* node, ZipWrap* pZip)
Ethan Yonker74db1572015-10-28 12:44:49 -0500119{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200120 std::string file;
Vojtech Bocek76ee9032014-09-07 15:01:56 +0200121 xml_attribute<>* attr;
Dees_Troy51a0e822012-09-05 15:24:24 -0400122
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200123 mFont = NULL;
124 if (!node)
125 return;
Dees_Troy51a0e822012-09-05 15:24:24 -0400126
Vojtech Bocek76ee9032014-09-07 15:01:56 +0200127 attr = node->first_attribute("filename");
128 if (!attr)
129 return;
Dees_Troy51a0e822012-09-05 15:24:24 -0400130
Vojtech Bocek76ee9032014-09-07 15:01:56 +0200131 file = attr->value();
132
Matt Mowera8a89d12016-12-30 18:10:37 -0600133 if (file.size() >= 4 && file.compare(file.size()-4, 4, ".ttf") == 0)
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200134 {
Ethan Yonker74db1572015-10-28 12:44:49 -0500135 int font_size = 0;
Vojtech Bocek76ee9032014-09-07 15:01:56 +0200136
Ethan Yonker74db1572015-10-28 12:44:49 -0500137 if (origFontSize != 0) {
138 attr = node->first_attribute("scale");
139 if (attr == NULL)
140 return;
141 font_size = origFontSize * atoi(attr->value()) / 100;
142 } else {
143 attr = node->first_attribute("size");
144 if (attr == NULL)
145 return;
146 font_size = scale_theme_min(atoi(attr->value()));
147 origFontSize = font_size;
148 }
Vojtech Bocek76ee9032014-09-07 15:01:56 +0200149
Vojtech Bocek76ee9032014-09-07 15:01:56 +0200150 int dpi = 300;
151
152 attr = node->first_attribute("dpi");
Matt Mowera8a89d12016-12-30 18:10:37 -0600153 if (attr)
Vojtech Bocek76ee9032014-09-07 15:01:56 +0200154 dpi = atoi(attr->value());
155
thatb240f4a2016-03-14 01:21:38 +0100156 // we can't use TMP_RESOURCE_NAME here because the ttf subsystem is caching the name and scaling needs to reload the font
157 std::string tmpname = "/tmp/" + file;
158 if (ExtractResource(pZip, "fonts", file, "", tmpname) == 0)
Vojtech Bocek76ee9032014-09-07 15:01:56 +0200159 {
bigbiffd58ba182020-03-23 10:02:29 -0400160 mFont = twrpTruetype::gr_ttf_loadFont(tmpname.c_str(), font_size, dpi);
Vojtech Bocek76ee9032014-09-07 15:01:56 +0200161 }
162 else
163 {
Dees Troy3454ade2015-01-20 19:21:04 +0000164 file = std::string(TWRES "fonts/") + file;
bigbiffd58ba182020-03-23 10:02:29 -0400165 mFont = twrpTruetype::gr_ttf_loadFont(file.c_str(), font_size, dpi);
Vojtech Bocek76ee9032014-09-07 15:01:56 +0200166 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200167 }
168 else
169 {
Ethan Yonker88037f42015-10-04 22:09:08 -0500170 LOGERR("Non-TTF fonts are no longer supported.\n");
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200171 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400172}
173
Ethan Yonker74db1572015-10-28 12:44:49 -0500174void FontResource::DeleteFont() {
bigbiffd58ba182020-03-23 10:02:29 -0400175 if (mFont) {
176 twrpTruetype::gr_ttf_freeFont(mFont);
177 }
Ethan Yonker74db1572015-10-28 12:44:49 -0500178 mFont = NULL;
bigbiffd58ba182020-03-23 10:02:29 -0400179 if (origFont) {
180 twrpTruetype::gr_ttf_freeFont(origFont);
181 }
Ethan Yonker74db1572015-10-28 12:44:49 -0500182 origFont = NULL;
183}
184
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500185void FontResource::Override(xml_node<>* node, ZipWrap* pZip) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500186 if (!origFont) {
187 origFont = mFont;
188 } else if (mFont) {
bigbiffd58ba182020-03-23 10:02:29 -0400189 twrpTruetype::gr_ttf_freeFont(mFont);
Ethan Yonker74db1572015-10-28 12:44:49 -0500190 mFont = NULL;
191 }
192 LoadFont(node, pZip);
193}
194
Dees_Troy51a0e822012-09-05 15:24:24 -0400195FontResource::~FontResource()
196{
Ethan Yonker74db1572015-10-28 12:44:49 -0500197 DeleteFont();
Dees_Troy51a0e822012-09-05 15:24:24 -0400198}
199
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500200ImageResource::ImageResource(xml_node<>* node, ZipWrap* pZip)
Dees_Troy51a0e822012-09-05 15:24:24 -0400201 : Resource(node, pZip)
202{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200203 std::string file;
Ethan Yonker63e414f2015-02-06 15:44:39 -0600204 gr_surface temp_surface = NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -0400205
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200206 mSurface = NULL;
Ethan Yonker619a7212014-12-03 16:47:37 -0600207 if (!node) {
208 LOGERR("ImageResource node is NULL\n");
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200209 return;
Ethan Yonker619a7212014-12-03 16:47:37 -0600210 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400211
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200212 if (node->first_attribute("filename"))
213 file = node->first_attribute("filename")->value();
Ethan Yonker63e414f2015-02-06 15:44:39 -0600214 else {
215 LOGERR("No filename specified for image resource.\n");
216 return;
217 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400218
that5267a212015-05-06 23:45:57 +0200219 bool retain_aspect = (node->first_attribute("retainaspect") != NULL);
220 // the value does not matter, if retainaspect is present, we assume that we want to retain it
Ethan Yonker63e414f2015-02-06 15:44:39 -0600221 LoadImage(pZip, file, &temp_surface);
222 CheckAndScaleImage(temp_surface, &mSurface, retain_aspect);
Dees_Troy51a0e822012-09-05 15:24:24 -0400223}
224
225ImageResource::~ImageResource()
226{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200227 if (mSurface)
228 res_free_surface(mSurface);
Dees_Troy51a0e822012-09-05 15:24:24 -0400229}
230
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500231AnimationResource::AnimationResource(xml_node<>* node, ZipWrap* pZip)
Dees_Troy51a0e822012-09-05 15:24:24 -0400232 : Resource(node, pZip)
233{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200234 std::string file;
235 int fileNum = 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400236
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200237 if (!node)
238 return;
Dees_Troy51a0e822012-09-05 15:24:24 -0400239
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200240 if (node->first_attribute("filename"))
241 file = node->first_attribute("filename")->value();
Ethan Yonker63e414f2015-02-06 15:44:39 -0600242 else {
243 LOGERR("No filename specified for image resource.\n");
244 return;
245 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400246
that5267a212015-05-06 23:45:57 +0200247 bool retain_aspect = (node->first_attribute("retainaspect") != NULL);
248 // the value does not matter, if retainaspect is present, we assume that we want to retain it
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200249 for (;;)
250 {
251 std::ostringstream fileName;
252 fileName << file << std::setfill ('0') << std::setw (3) << fileNum;
Dees_Troy51a0e822012-09-05 15:24:24 -0400253
Ethan Yonker63e414f2015-02-06 15:44:39 -0600254 gr_surface surface, temp_surface = NULL;
255 LoadImage(pZip, fileName.str(), &temp_surface);
256 CheckAndScaleImage(temp_surface, &surface, retain_aspect);
257 if (surface) {
258 mSurfaces.push_back(surface);
259 fileNum++;
260 } else
261 break; // Done loading animation images
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200262 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400263}
264
265AnimationResource::~AnimationResource()
266{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200267 std::vector<gr_surface>::iterator it;
Dees_Troy51a0e822012-09-05 15:24:24 -0400268
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200269 for (it = mSurfaces.begin(); it != mSurfaces.end(); ++it)
270 res_free_surface(*it);
271
272 mSurfaces.clear();
Dees_Troy51a0e822012-09-05 15:24:24 -0400273}
274
that74ac6062015-03-04 22:39:34 +0100275FontResource* ResourceManager::FindFont(const std::string& name) const
Dees_Troy51a0e822012-09-05 15:24:24 -0400276{
that74ac6062015-03-04 22:39:34 +0100277 for (std::vector<FontResource*>::const_iterator it = mFonts.begin(); it != mFonts.end(); ++it)
278 if (name == (*it)->GetName())
279 return *it;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200280 return NULL;
Dees_Troy51a0e822012-09-05 15:24:24 -0400281}
282
that74ac6062015-03-04 22:39:34 +0100283ImageResource* ResourceManager::FindImage(const std::string& name) const
Dees_Troy51a0e822012-09-05 15:24:24 -0400284{
that74ac6062015-03-04 22:39:34 +0100285 for (std::vector<ImageResource*>::const_iterator it = mImages.begin(); it != mImages.end(); ++it)
286 if (name == (*it)->GetName())
287 return *it;
288 return NULL;
289}
290
291AnimationResource* ResourceManager::FindAnimation(const std::string& name) const
292{
293 for (std::vector<AnimationResource*>::const_iterator it = mAnimations.begin(); it != mAnimations.end(); ++it)
294 if (name == (*it)->GetName())
295 return *it;
296 return NULL;
297}
298
thatb2e8f672015-03-05 20:25:39 +0100299std::string ResourceManager::FindString(const std::string& name) const
300{
Ethan Yonker58f21322018-08-24 11:17:36 -0500301 //if (this != NULL) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500302 std::map<std::string, string_resource_struct>::const_iterator it = mStrings.find(name);
303 if (it != mStrings.end())
304 return it->second.value;
305 LOGERR("String resource '%s' not found. No default value.\n", name.c_str());
306 PageManager::AddStringResource("NO DEFAULT", name, "[" + name + ("]"));
Ethan Yonker58f21322018-08-24 11:17:36 -0500307 /*} else {
Ethan Yonker74db1572015-10-28 12:44:49 -0500308 LOGINFO("String resources not loaded when looking for '%s'. No default value.\n", name.c_str());
Ethan Yonker58f21322018-08-24 11:17:36 -0500309 }*/
thatb2e8f672015-03-05 20:25:39 +0100310 return "[" + name + ("]");
311}
312
Ethan Yonker74db1572015-10-28 12:44:49 -0500313std::string ResourceManager::FindString(const std::string& name, const std::string& default_string) const
314{
Ethan Yonker58f21322018-08-24 11:17:36 -0500315 //if (this != NULL) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500316 std::map<std::string, string_resource_struct>::const_iterator it = mStrings.find(name);
317 if (it != mStrings.end())
318 return it->second.value;
319 LOGERR("String resource '%s' not found. Using default value.\n", name.c_str());
320 PageManager::AddStringResource("DEFAULT", name, default_string);
Ethan Yonker58f21322018-08-24 11:17:36 -0500321 /*} else {
Ethan Yonker74db1572015-10-28 12:44:49 -0500322 LOGINFO("String resources not loaded when looking for '%s'. Using default value.\n", name.c_str());
Ethan Yonker58f21322018-08-24 11:17:36 -0500323 }*/
Ethan Yonker74db1572015-10-28 12:44:49 -0500324 return default_string;
325}
326
327void ResourceManager::DumpStrings() const
328{
Ethan Yonker58f21322018-08-24 11:17:36 -0500329 /*if (this == NULL) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500330 gui_print("No string resources\n");
331 return;
Ethan Yonker58f21322018-08-24 11:17:36 -0500332 }*/
Ethan Yonker74db1572015-10-28 12:44:49 -0500333 std::map<std::string, string_resource_struct>::const_iterator it;
334 gui_print("Dumping all strings:\n");
335 for (it = mStrings.begin(); it != mStrings.end(); it++)
336 gui_print("source: %s: '%s' = '%s'\n", it->second.source.c_str(), it->first.c_str(), it->second.value.c_str());
337 gui_print("Done dumping strings\n");
338}
339
that74ac6062015-03-04 22:39:34 +0100340ResourceManager::ResourceManager()
341{
Ethan Yonker780cd392014-07-21 15:24:39 -0500342}
343
Ethan Yonker74db1572015-10-28 12:44:49 -0500344void ResourceManager::AddStringResource(std::string resource_source, std::string resource_name, std::string value)
345{
346 string_resource_struct res;
347 res.source = resource_source;
348 res.value = value;
349 mStrings[resource_name] = res;
350}
351
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500352void ResourceManager::LoadResources(xml_node<>* resList, ZipWrap* pZip, std::string resource_source)
Ethan Yonker780cd392014-07-21 15:24:39 -0500353{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200354 if (!resList)
355 return;
that0f425062015-03-04 23:05:00 +0100356
357 for (xml_node<>* child = resList->first_node(); child; child = child->next_sibling())
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200358 {
that0f425062015-03-04 23:05:00 +0100359 std::string type = child->name();
360 if (type == "resource") {
361 // legacy format : <resource type="...">
362 xml_attribute<>* attr = child->first_attribute("type");
363 type = attr ? attr->value() : "*unspecified*";
364 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400365
that74ac6062015-03-04 22:39:34 +0100366 bool error = false;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200367 if (type == "font")
368 {
that74ac6062015-03-04 22:39:34 +0100369 FontResource* res = new FontResource(child, pZip);
Ethan Yonker58f21322018-08-24 11:17:36 -0500370 if (res && res->GetResource())
that74ac6062015-03-04 22:39:34 +0100371 mFonts.push_back(res);
372 else {
373 error = true;
374 delete res;
375 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200376 }
Ethan Yonker74db1572015-10-28 12:44:49 -0500377 else if (type == "fontoverride")
378 {
379 if (mFonts.size() != 0 && child && child->first_attribute("name")) {
380 string FontName = child->first_attribute("name")->value();
381 size_t font_count = mFonts.size(), i;
382 bool found = false;
383
384 for (i = 0; i < font_count; i++) {
385 if (mFonts[i]->GetName() == FontName) {
386 mFonts[i]->Override(child, pZip);
387 found = true;
388 break;
389 }
390 }
391 if (!found) {
392 LOGERR("Unable to locate font '%s' for override.\n", FontName.c_str());
393 }
394 } else if (mFonts.size() != 0)
395 LOGERR("Unable to locate font name for type fontoverride.\n");
396 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200397 else if (type == "image")
398 {
that5267a212015-05-06 23:45:57 +0200399 ImageResource* res = new ImageResource(child, pZip);
Ethan Yonker58f21322018-08-24 11:17:36 -0500400 if (res && res->GetResource())
that74ac6062015-03-04 22:39:34 +0100401 mImages.push_back(res);
402 else {
403 error = true;
404 delete res;
405 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200406 }
407 else if (type == "animation")
408 {
that5267a212015-05-06 23:45:57 +0200409 AnimationResource* res = new AnimationResource(child, pZip);
Ethan Yonker58f21322018-08-24 11:17:36 -0500410 if (res && res->GetResourceCount())
that74ac6062015-03-04 22:39:34 +0100411 mAnimations.push_back(res);
412 else {
413 error = true;
414 delete res;
415 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200416 }
thatb2e8f672015-03-05 20:25:39 +0100417 else if (type == "string")
418 {
Ethan Yonker74db1572015-10-28 12:44:49 -0500419 if (xml_attribute<>* attr = child->first_attribute("name")) {
420 string_resource_struct res;
421 res.source = resource_source;
422 res.value = child->value();
423 mStrings[attr->value()] = res;
424 } else
thatb2e8f672015-03-05 20:25:39 +0100425 error = true;
426 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200427 else
428 {
429 LOGERR("Resource type (%s) not supported.\n", type.c_str());
that74ac6062015-03-04 22:39:34 +0100430 error = true;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200431 }
thatf6ed8fc2015-02-14 20:23:16 +0100432
that74ac6062015-03-04 22:39:34 +0100433 if (error)
thatf74ac872015-01-18 12:00:02 +0100434 {
435 std::string res_name;
436 if (child->first_attribute("name"))
437 res_name = child->first_attribute("name")->value();
438 if (res_name.empty() && child->first_attribute("filename"))
439 res_name = child->first_attribute("filename")->value();
440
441 if (!res_name.empty()) {
442 LOGERR("Resource (%s)-(%s) failed to load\n", type.c_str(), res_name.c_str());
443 } else
444 LOGERR("Resource type (%s) failed to load\n", type.c_str());
thatf74ac872015-01-18 12:00:02 +0100445 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200446 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400447}
448
449ResourceManager::~ResourceManager()
450{
that74ac6062015-03-04 22:39:34 +0100451 for (std::vector<FontResource*>::iterator it = mFonts.begin(); it != mFonts.end(); ++it)
452 delete *it;
Dees_Troy51a0e822012-09-05 15:24:24 -0400453
that74ac6062015-03-04 22:39:34 +0100454 for (std::vector<ImageResource*>::iterator it = mImages.begin(); it != mImages.end(); ++it)
455 delete *it;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200456
that74ac6062015-03-04 22:39:34 +0100457 for (std::vector<AnimationResource*>::iterator it = mAnimations.begin(); it != mAnimations.end(); ++it)
458 delete *it;
Dees_Troy51a0e822012-09-05 15:24:24 -0400459}