| 68 | } |
| 69 | |
| 70 | ResourceData ResourceManager::loadFile(const std::string& path) const |
| 71 | { |
| 72 | std::ifstream stream(path, std::ios::binary); |
| 73 | |
| 74 | stream.seekg(0, stream.end); |
| 75 | std::ifstream::pos_type size = stream.tellg(); |
| 76 | stream.seekg(0, stream.beg); |
| 77 | if(size>0) |
| 78 | { |
| 79 | //supply custom deleter to properly free array |
| 80 | std::shared_ptr<unsigned char> data(new unsigned char[size], array_deleter); |
| 81 | stream.read((char*)data.get(), size); |
| 82 | stream.close(); |
| 83 | |
| 84 | ResourceData ret = {data, (size_t)size}; |
| 85 | return ret; |
| 86 | } |
| 87 | |
| 88 | //error reading file, return an "empty" ResourceData |
| 89 | LOG(LogError) << "Error reading file: " << path; |
| 90 | ResourceData ret = {NULL, 0}; |
| 91 | return ret; |
| 92 | } |
| 93 | |
| 94 | bool ResourceManager::fileExists(const std::string& path) const |
| 95 | { |