diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/client.cpp | 35 | ||||
-rw-r--r-- | src/client/client.h | 4 |
2 files changed, 26 insertions, 13 deletions
diff --git a/src/client/client.cpp b/src/client/client.cpp index caa3cc78c..3190641cf 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -200,14 +200,30 @@ void Client::scanModSubfolder(const std::string &mod_name, const std::string &mo std::string full_path = mod_path + DIR_DELIM + mod_subpath; std::vector<fs::DirListNode> mod = fs::GetDirListing(full_path); for (const fs::DirListNode &j : mod) { - std::string filename = j.name; if (j.dir) { - scanModSubfolder(mod_name, mod_path, mod_subpath - + filename + DIR_DELIM); + scanModSubfolder(mod_name, mod_path, mod_subpath + j.name + DIR_DELIM); continue; } - std::replace( mod_subpath.begin(), mod_subpath.end(), DIR_DELIM_CHAR, '/'); - m_mod_files[mod_name + ":" + mod_subpath + filename] = full_path + filename; + std::replace(mod_subpath.begin(), mod_subpath.end(), DIR_DELIM_CHAR, '/'); + + std::string real_path = full_path + j.name; + std::string vfs_path = mod_name + ":" + mod_subpath + j.name; + infostream << "Client::scanModSubfolder(): Loading \"" << real_path + << "\" as \"" << vfs_path << "\"." << std::endl; + + std::ifstream is(real_path, std::ios::binary | std::ios::ate); + if(!is.good()) { + errorstream << "Client::scanModSubfolder(): Can't read file \"" + << real_path << "\"." << std::endl; + continue; + } + auto size = is.tellg(); + std::string contents(size, '\0'); + is.seekg(0); + is.read(&contents[0], size); + + infostream << " size: " << size << " bytes" << std::endl; + m_mod_vfs.emplace(vfs_path, contents); } } @@ -1866,12 +1882,9 @@ scene::IAnimatedMesh* Client::getMesh(const std::string &filename, bool cache) const std::string* Client::getModFile(const std::string &filename) { - StringMap::const_iterator it = m_mod_files.find(filename); - if (it == m_mod_files.end()) { - errorstream << "Client::getModFile(): File not found: \"" << filename - << "\"" << std::endl; - return NULL; - } + StringMap::const_iterator it = m_mod_vfs.find(filename); + if (it == m_mod_vfs.end()) + return nullptr; return &it->second; } diff --git a/src/client/client.h b/src/client/client.h index e3c931837..40ad4c064 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -576,8 +576,6 @@ private: // Storage for mesh data for creating multiple instances of the same mesh StringMap m_mesh_data; - StringMap m_mod_files; - // own state LocalClientState m_state; @@ -588,11 +586,13 @@ private: IntervalLimiter m_localdb_save_interval; u16 m_cache_save_interval; + // Client modding ClientScripting *m_script = nullptr; bool m_modding_enabled; std::unordered_map<std::string, ModMetadata *> m_mod_storages; float m_mod_storage_save_timer = 10.0f; std::vector<ModSpec> m_mods; + StringMap m_mod_vfs; bool m_shutdown = false; |