/
SilovAndrey
/
easel
Обзор
Документация
Войти
/
SilovAndrey
/
easel
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/resources.cpp
91 строка
2 KB
Andrey HomePC
Easel v0.1.0: C++23 modular canvas library with ThorVG backend
10 июл 2026, 08:59
10 июл 2026, 08:59
90be3cb
Код
Авторство
О чём код?
module; #include <algorithm> #include <iostream> #include <mutex> #include <vector> #include <filesystem> module Resource; std::pair<std::vector<resource::Path>&, std::mutex&> get_resource_paths() { static std::vector<resource::Path> resource_paths; static std::mutex resource_paths_mutex; return {resource_paths, resource_paths_mutex}; } // struct resource_setter // { // resource_setter() // { // resource::init_paths(); // } // }; namespace resource { void add_path(Path const& path, bool search_first) { auto [resource_paths, resource_paths_mutex] = get_resource_paths(); std::lock_guard<std::mutex> guard(resource_paths_mutex); if (search_first) resource_paths.insert(resource_paths.begin(), path); else resource_paths.push_back(path); } // namespace // { // struct resource_setter // { // resource_setter() // { // init_paths(); // } // }; //} Path find_file(Path const& file) { //static resource_setter init_resources; if (file.is_absolute()) { if (std::filesystem::exists(file)) return file; return Path{}; // Return an empty path if the file does not exist } auto [resource_paths, resource_paths_mutex] = get_resource_paths(); std::lock_guard<std::mutex> guard(resource_paths_mutex); auto it = std::find_if(resource_paths.begin(), resource_paths.end(), [&file](const Path &path) { return std::filesystem::exists(path / file); }); return (it != resource_paths.end()) ? (*it / file) : Path{}; } Path find_directory(Path const& dir) { //static resource_setter init_resources; if (dir.is_absolute()) { if (std::filesystem::is_directory(dir)) return dir; return Path{}; // Return an empty path if the directory does not exist } auto [resource_paths, resource_paths_mutex] = get_resource_paths(); std::lock_guard<std::mutex> guard(resource_paths_mutex); auto it = std::find_if(resource_paths.begin(), resource_paths.end(), [&dir](const Path &path) { return std::filesystem::is_directory(path / dir); }); return (it != resource_paths.end()) ? (*it / dir) : Path{}; } }