MCPcopy Create free account
hub / github.com/MayaPosch/NymphCast / loadFile

Method loadFile

src/server/gui/core/resources/ResourceManager.cpp:70–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70ResourceData 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
94bool ResourceManager::fileExists(const std::string& path) const
95{

Callers

nothing calls this directly

Calls 3

readMethod · 0.80
getMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected