- if (m_media_receive_started) {
- bool all_stopped = true;
- for (std::list<MediaFetchThread*>::iterator thread = m_media_fetch_threads.begin();
- thread != m_media_fetch_threads.end(); ++thread) {
- all_stopped &= !(*thread)->IsRunning();
- while (!(*thread)->m_file_data.empty()) {
- std::pair <std::string, std::string> out = (*thread)->m_file_data.pop_front();
- if(m_media_received_count < m_media_count)
- m_media_received_count++;
-
- bool success = loadMedia(out.second, out.first);
- if(success){
- verbosestream<<"Client: Loaded received media: "
- <<"\""<<out.first<<"\". Caching."<<std::endl;
- } else{
- infostream<<"Client: Failed to load received media: "
- <<"\""<<out.first<<"\". Not caching."<<std::endl;
- continue;
- }
-
- bool did = fs::CreateAllDirs(getMediaCacheDir());
- if(!did){
- errorstream<<"Could not create media cache directory"
- <<std::endl;
- }
-
- {
- std::map<std::string, std::string>::iterator n;
- n = m_media_name_sha1_map.find(out.first);
- if(n == m_media_name_sha1_map.end())
- errorstream<<"The server sent a file that has not "
- <<"been announced."<<std::endl;
- else
- m_media_cache.update_sha1(out.second);
- }
- }
- }
- if (all_stopped) {
- std::list<MediaRequest> fetch_failed;
- for (std::list<MediaFetchThread*>::iterator thread = m_media_fetch_threads.begin();
- thread != m_media_fetch_threads.end(); ++thread) {
- for (std::list<MediaRequest>::iterator request = (*thread)->m_failed.begin();
- request != (*thread)->m_failed.end(); ++request)
- fetch_failed.push_back(*request);
- (*thread)->m_failed.clear();
- }
- if (fetch_failed.size() > 0) {
- infostream << "Failed to remote-fetch " << fetch_failed.size() << " files. "
- << "Requesting them the usual way." << std::endl;
- request_media(fetch_failed);
- }