-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageFileURLLoader.cpp
43 lines (35 loc) · 1.06 KB
/
ImageFileURLLoader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "ImageFileURLLoader.h"
#include "ImageUrlLoader.h"
#include "FileUtil.h"
#include "SpriteUtil.h"
namespace dxco {
ImageFileURLLoader::ImageFileURLLoader(cocos2d::CCSprite* sprite, std::string filePath, std::string url, bool cache) {
this->sprite = sprite;
this->filePath = filePath;
this->url = url;
if (cache) {
std::string fileContent = FileUtil::readFile(filePath);
if (fileContent.size()) {
SpriteUtil::setTexture(sprite, SpriteUtil::createTextuteWithBytes(fileContent));
} else {
CCLOG("posting");
ImageUrlLoader* imageLoader = new ImageUrlLoader(sprite);
imageLoader->setSavePath(filePath);
imageLoader->get(url);
}
} else {
ImageUrlLoader* imageLoader = new ImageUrlLoader(sprite);
imageLoader->get(url);
}
}
bool ImageFileURLLoader::loadUsingFile() {
std::string fileContent = FileUtil::readFile(this->filePath);
if (fileContent.size()) {
cocos2d::CCTexture2D* texture = SpriteUtil::createTextuteWithBytes(fileContent);
this->sprite->setTexture(texture);
return true;
} else {
return false;
}
}
} /* namespace dxco */