#include "threading/mutex_auto_lock.h"
#include "client/clientevent.h"
#include "client/renderingengine.h"
+#include "client/tile.h"
#include "util/auth.h"
#include "util/directiontables.h"
#include "util/pointedthing.h"
text = wgettext("Initializing nodes...");
RenderingEngine::draw_load_screen(text, guienv, m_tsrc, 0, 72);
m_nodedef->updateAliases(m_itemdef);
- std::string texture_path = g_settings->get("texture_path");
- if (!texture_path.empty() && fs::IsDir(texture_path))
- m_nodedef->applyTextureOverrides(texture_path + DIR_DELIM + "override.txt");
+ for (const auto &path : getTextureDirs())
+ m_nodedef->applyTextureOverrides(path + DIR_DELIM + "override.txt");
m_nodedef->setNodeRegistrationStatus(true);
m_nodedef->runNodeResolveCallbacks();
delete[] text;
/*
Check from texture_path
*/
- const std::string &texture_path = g_settings->get("texture_path");
- if (!texture_path.empty()) {
- std::string testpath = texture_path + DIR_DELIM + filename;
+ for (const auto &path : getTextureDirs()) {
+ std::string testpath = path + DIR_DELIM + filename;
// Check all filename extensions. Returns "" if not found.
fullpath = getImagePath(testpath);
+ if (!fullpath.empty())
+ break;
}
/*
return getTexture(tname);
}
+
+const std::vector<std::string> &getTextureDirs()
+{
+ static thread_local std::vector<std::string> dirs =
+ fs::GetRecursiveDirs(g_settings->get("texture_path"));
+ return dirs;
+}
//! The first is base texture, the second is overlay.
TileLayer layers[MAX_TILE_LAYERS];
};
+
+const std::vector<std::string> &getTextureDirs();
#endif
-void GetRecursiveSubPaths(const std::string &path, std::vector<std::string> &dst)
+void GetRecursiveDirs(std::vector<std::string> &dirs, const std::string &dir)
+{
+ static const std::set<char> chars_to_ignore = { '_', '.' };
+ if (dir.empty() || !IsDir(dir))
+ return;
+ dirs.push_back(dir);
+ fs::GetRecursiveSubPaths(dir, dirs, false, chars_to_ignore);
+}
+
+std::vector<std::string> GetRecursiveDirs(const std::string &dir)
+{
+ std::vector<std::string> result;
+ GetRecursiveDirs(result, dir);
+ return result;
+}
+
+void GetRecursiveSubPaths(const std::string &path,
+ std::vector<std::string> &dst,
+ bool list_files,
+ const std::set<char> &ignore)
{
std::vector<DirListNode> content = GetDirListing(path);
for (const auto &n : content) {
std::string fullpath = path + DIR_DELIM + n.name;
- dst.push_back(fullpath);
- if (n.dir) {
- GetRecursiveSubPaths(fullpath, dst);
- }
+ if (ignore.count(n.name[0]))
+ continue;
+ if (list_files || n.dir)
+ dst.push_back(fullpath);
+ if (n.dir)
+ GetRecursiveSubPaths(fullpath, dst, list_files, ignore);
}
}
#pragma once
+#include <set>
#include <string>
#include <vector>
#include "exceptions.h"
// Returns path to temp directory, can return "" on error
std::string TempPath();
+/* Returns a list of subdirectories, including the path itself, but excluding
+ hidden directories (whose names start with . or _)
+*/
+void GetRecursiveDirs(std::vector<std::string> &dirs, const std::string &dir);
+std::vector<std::string> GetRecursiveDirs(const std::string &dir);
+
/* Multiplatform */
-// The path itself not included
-void GetRecursiveSubPaths(const std::string &path, std::vector<std::string> &dst);
+/* The path itself not included, returns a list of all subpaths.
+ dst - vector that contains all the subpaths.
+ list files - include files in the list of subpaths.
+ ignore - paths that start with these charcters will not be listed.
+*/
+void GetRecursiveSubPaths(const std::string &path,
+ std::vector<std::string> &dst,
+ bool list_files,
+ const std::set<char> &ignore = {});
// Tries to delete all, returns false if any failed
bool DeletePaths(const std::vector<std::string> &paths);
std::vector<std::string> paths;
paths.push_back(spec.path);
- fs::GetRecursiveSubPaths(spec.path, paths);
+ fs::GetRecursiveSubPaths(spec.path, paths, true);
// Delete files
if (!fs::DeletePaths(paths)) {
m_nodedef->updateAliases(m_itemdef);
// Apply texture overrides from texturepack/override.txt
- std::string texture_path = g_settings->get("texture_path");
- if (!texture_path.empty() && fs::IsDir(texture_path))
- m_nodedef->applyTextureOverrides(texture_path + DIR_DELIM + "override.txt");
+ for (const auto &path : fs::GetRecursiveDirs(g_settings->get("texture_path")))
+ m_nodedef->applyTextureOverrides(path + DIR_DELIM + "override.txt");
m_nodedef->setNodeRegistrationStatus(true);
paths.push_back(mod.path + DIR_DELIM + "models");
paths.push_back(mod.path + DIR_DELIM + "locale");
}
- paths.push_back(porting::path_user + DIR_DELIM + "textures" + DIR_DELIM + "server");
-
+ fs::GetRecursiveDirs(paths, porting::path_user + DIR_DELIM +
+ "textures" + DIR_DELIM + "server");
// Collect media file information from paths into cache
for (const std::string &mediapath : paths) {
std::vector<fs::DirListNode> dirlist = fs::GetDirListing(mediapath);