diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-04-28 11:52:04 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-04-28 11:53:18 +0200 |
commit | 3b03f87070d91f63f0dc3c7152723727781dcccf (patch) | |
tree | 7b06163f34248d1e632c032cfaf306787675e585 /src/Cache.cpp | |
parent | b0bfb8b8d1479502bd5adf17e6a1b94ec00c63ca (diff) |
Add commands, users side panel, improve image download
start using odhtdb
Diffstat (limited to 'src/Cache.cpp')
-rw-r--r-- | src/Cache.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp index accd0c4..abfa1dd 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -80,6 +80,7 @@ namespace dchat texture->generateMipmap(); return { texture, ImageByUrlResult::Type::CACHED }; } + delete texture; delete fileContent.data; } } @@ -100,7 +101,6 @@ namespace dchat { while(true) { - imageDownloadMutex.lock(); for(vector<ImageDownloadInfo>::iterator it = imageDownloadProcesses.begin(); it != imageDownloadProcesses.end();) { int exitStatus; @@ -114,7 +114,9 @@ namespace dchat filepath /= urlHash.toString(); ImageByUrlResult imageByUrlResult = loadImageFromFile(filepath); + imageDownloadMutex.lock(); imageUrlCache[it->url] = imageByUrlResult; + imageDownloadMutex.unlock(); switch(imageByUrlResult.type) { case ImageByUrlResult::Type::CACHED: @@ -130,11 +132,21 @@ namespace dchat else ++it; } - imageDownloadMutex.unlock(); - while(imageDownloadProcesses.empty()) + while(imageDownloadProcesses.empty() && imageDownloadProcessesQueue.empty()) this_thread::sleep_for(chrono::milliseconds(20)); + if(!imageDownloadProcessesQueue.empty()) + { + imageDownloadMutex.lock(); + for(auto imageDownloadInfo : imageDownloadProcessesQueue) + { + imageDownloadProcesses.push_back(imageDownloadInfo); + } + imageDownloadProcessesQueue.clear(); + imageDownloadMutex.unlock(); + } + this_thread::sleep_for(chrono::milliseconds(20)); } }); @@ -169,10 +181,10 @@ namespace dchat Process::string_type cmd = "curl -L --silent -o '"; cmd += filepath.native(); cmd += "' --max-filesize " + downloadLimitBytesStr + " --range 0-" + downloadLimitBytesStr + " --url '" + url + "'"; - // certutil.exe -urlcache -split -f "https://url/to/file" path/and/name/to/save/as/file + // TODO: Use this instead of curl on windows: certutil.exe -urlcache -split -f "https://url/to/file" path/and/name/to/save/as/file Process *process = new Process(cmd, "", nullptr, nullptr, false); ImageDownloadInfo imageDownloadInfo { process, url }; - imageDownloadProcesses.emplace_back(imageDownloadInfo); + imageDownloadProcessesQueue.emplace_back(imageDownloadInfo); return result; } } |