+ /*
+ Load fetched media
+ */
+ if (m_media_receive_started) {
+ bool all_stopped = true;
+ for (core::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.size() > 0) {
+ std::pair <std::string, std::string> out = (*thread)->m_file_data.pop_front();
+ ++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;
+ }
+
+ {
+ core::map<std::string, std::string>::Node *n;
+ n = m_media_name_sha1_map.find(out.first);
+ if(n == NULL)
+ errorstream<<"The server sent a file that has not "
+ <<"been announced."<<std::endl;
+ else
+ m_media_cache.update_sha1(out.second);
+ }
+ }
+ }
+ if (all_stopped) {
+ core::list<MediaRequest> fetch_failed;
+ for (core::list<MediaFetchThread*>::Iterator thread = m_media_fetch_threads.begin();
+ thread != m_media_fetch_threads.end(); thread++) {
+ for (core::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);
+ }
+ }
+ }
+