maybe slightly better image loading maybe hopefully

This commit is contained in:
ouwou
2020-10-03 18:49:22 -04:00
parent c7a958a3bb
commit bbe36a8246
7 changed files with 105 additions and 66 deletions

View File

@@ -23,23 +23,14 @@ std::string Cache::SanitizeString(std::string str) {
}
void Cache::RespondFromPath(std::filesystem::path path, callback_type cb) {
/*if (!std::filesystem::exists(path)) return;
FILE *fp = std::fopen(path.string().c_str(), "rb");
if (fp == nullptr) return;
std::fseek(fp, 0, SEEK_END);
int len = std::ftell(fp);
std::rewind(fp);
std::vector<uint8_t> ret;
ret.resize(len);
std::fread(ret.data(), 1, len, fp);
std::fclose(fp);*/
cb(path.string());
}
void Cache::GetFileFromURL(std::string url, callback_type cb) {
auto cache_path = m_tmp_path / SanitizeString(url);
if (std::filesystem::exists(cache_path)) {
RespondFromPath(cache_path, cb);
m_futures.push_back(std::async(std::launch::async, [this, cache_path, cb]() {
RespondFromPath(cache_path, cb); }));
return;
}