X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fclientmedia.cpp;h=ca6f3d563ca57911b07e380ff381bb5b244bbd03;hb=3caad3f3c9e319ca67d63231e8c64b2ace855fff;hp=1d825c14316b7069852969b82b39435747842b01;hpb=365e4ae0faee79ff7b62396f27667e8315ba94d4;p=oweals%2Fminetest.git diff --git a/src/clientmedia.cpp b/src/clientmedia.cpp index 1d825c143..ca6f3d563 100644 --- a/src/clientmedia.cpp +++ b/src/clientmedia.cpp @@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "log.h" #include "porting.h" #include "settings.h" -#include "main.h" #include "network/networkprotocol.h" #include "util/hex.h" #include "util/serialize.h" @@ -35,7 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc., static std::string getMediaCacheDir() { - return porting::path_user + DIR_DELIM + "cache" + DIR_DELIM + "media"; + return porting::path_cache + DIR_DELIM + "media"; } /* @@ -43,18 +42,9 @@ static std::string getMediaCacheDir() */ ClientMediaDownloader::ClientMediaDownloader(): - m_media_cache(getMediaCacheDir()) + m_media_cache(getMediaCacheDir()), + m_httpfetch_caller(HTTPFETCH_DISCARD) { - m_initial_step_done = false; - m_name_bound = ""; // works because "" is an invalid file name - m_uncached_count = 0; - m_uncached_received_count = 0; - m_httpfetch_caller = HTTPFETCH_DISCARD; - m_httpfetch_active = 0; - m_httpfetch_active_limit = 0; - m_httpfetch_next_id = 0; - m_httpfetch_timeout = 0; - m_outstanding_hash_sets = 0; } ClientMediaDownloader::~ClientMediaDownloader() @@ -70,9 +60,9 @@ ClientMediaDownloader::~ClientMediaDownloader() delete m_remotes[i]; } -void ClientMediaDownloader::addFile(std::string name, std::string sha1) +void ClientMediaDownloader::addFile(const std::string &name, const std::string &sha1) { - assert(!m_initial_step_done); + assert(!m_initial_step_done); // pre-condition // if name was already announced, ignore the new announcement if (m_files.count(name) != 0) { @@ -105,9 +95,9 @@ void ClientMediaDownloader::addFile(std::string name, std::string sha1) m_files.insert(std::make_pair(name, filestatus)); } -void ClientMediaDownloader::addRemoteServer(std::string baseurl) +void ClientMediaDownloader::addRemoteServer(const std::string &baseurl) { - assert(!m_initial_step_done); + assert(!m_initial_step_done); // pre-condition #ifdef USE_CURL @@ -349,18 +339,18 @@ void ClientMediaDownloader::remoteMediaReceived( std::string name; { - std::map::iterator it = + std::unordered_map::iterator it = m_remote_file_transfers.find(fetch_result.request_id); assert(it != m_remote_file_transfers.end()); name = it->second; m_remote_file_transfers.erase(it); } - assert(m_files.count(name) != 0); + sanity_check(m_files.count(name) != 0); FileStatus *filestatus = m_files[name]; - assert(!filestatus->received); - assert(filestatus->current_remote >= 0); + sanity_check(!filestatus->received); + sanity_check(filestatus->current_remote >= 0); RemoteServerStatus *remote = m_remotes[filestatus->current_remote]; @@ -382,6 +372,7 @@ void ClientMediaDownloader::remoteMediaReceived( s32 ClientMediaDownloader::selectRemoteServer(FileStatus *filestatus) { + // Pre-conditions assert(filestatus != NULL); assert(!filestatus->received); assert(filestatus->current_remote < 0); @@ -483,7 +474,7 @@ void ClientMediaDownloader::startRemoteMediaTransfers() void ClientMediaDownloader::startConventionalTransfers(Client *client) { - assert(m_httpfetch_active == 0); + assert(m_httpfetch_active == 0); // pre-condition if (m_uncached_received_count != m_uncached_count) { // Some media files have not been received yet, use the @@ -616,7 +607,7 @@ std::string ClientMediaDownloader::serializeRequiredHashSet() it = m_files.begin(); it != m_files.end(); ++it) { if (!it->second->received) { - assert(it->second->sha1.size() == 20); + FATAL_ERROR_IF(it->second->sha1.size() != 20, "Invalid SHA1 size"); os << it->second->sha1; } }