void datasource_cache::register_datasources(std::string const& str) { #ifdef MAPNIK_THREADSAFE mapnik::scoped_lock lock(mutex_); #endif plugin_directories_.insert(str); if (mapnik::util::exists(str) && mapnik::util::is_directory(str)) { boost::filesystem::directory_iterator end_itr; #ifdef _WINDOWS std::wstring wide_dir(mapnik::utf8_to_utf16(str)); for (boost::filesystem::directory_iterator itr(wide_dir); itr != end_itr; ++itr) #else for (boost::filesystem::directory_iterator itr(str); itr != end_itr; ++itr ) #endif { #if (BOOST_FILESYSTEM_VERSION == 3) if (!boost::filesystem::is_directory(*itr) && is_input_plugin(itr->path().filename().string())) #else // v2 if (!boost::filesystem::is_directory(*itr) && is_input_plugin(itr->path().leaf())) #endif { #if (BOOST_FILESYSTEM_VERSION == 3) if (register_datasource(itr->path().string())) #else // v2 if (register_datasource(itr->string())) #endif { registered_ = true; } } } } }
bool datasource_cache::register_datasources(std::string const& dir, bool recurse) { #ifdef MAPNIK_THREADSAFE mapnik::scoped_lock lock(mutex_); #endif if (!mapnik::util::exists(dir)) { return false; } plugin_directories_.insert(dir); if (!mapnik::util::is_directory(dir)) { return register_datasource(dir); } bool success = false; try { boost::filesystem::directory_iterator end_itr; #ifdef _WINDOWS std::wstring wide_dir(mapnik::utf8_to_utf16(dir)); for (boost::filesystem::directory_iterator itr(wide_dir); itr != end_itr; ++itr) { std::string file_name = mapnik::utf16_to_utf8(itr->path().wstring()); #else for (boost::filesystem::directory_iterator itr(dir); itr != end_itr; ++itr) { std::string file_name = itr->path().string(); #endif if (boost::filesystem::is_directory(*itr) && recurse) { if (register_datasources(file_name, true)) { success = true; } } else { std::string base_name = itr->path().filename().string(); if (!boost::algorithm::starts_with(base_name,".") && mapnik::util::is_regular_file(file_name) && is_input_plugin(file_name)) { if (register_datasource(file_name)) { success = true; } } } } } catch (std::exception const& ex) { MAPNIK_LOG_ERROR(datasource_cache) << "register_datasources: " << ex.what(); } return success; }
bool freetype_engine::register_fonts_impl(std::string const& dir, font_library & library, freetype_engine::font_file_mapping_type & font_file_mapping, bool recurse) { if (!mapnik::util::exists(dir)) { return false; } if (!mapnik::util::is_directory(dir)) { return register_font_impl(dir, library, font_file_mapping); } bool success = false; try { boost::filesystem::directory_iterator end_itr; #ifdef _WINDOWS std::wstring wide_dir(mapnik::utf8_to_utf16(dir)); for (boost::filesystem::directory_iterator itr(wide_dir); itr != end_itr; ++itr) { std::string file_name = mapnik::utf16_to_utf8(itr->path().wstring()); #else for (boost::filesystem::directory_iterator itr(dir); itr != end_itr; ++itr) { std::string file_name = itr->path().string(); #endif if (boost::filesystem::is_directory(*itr) && recurse) { if (register_fonts_impl(file_name, library, font_file_mapping, true)) { success = true; } } else { std::string base_name = itr->path().filename().string(); if (!boost::algorithm::starts_with(base_name,".") && mapnik::util::is_regular_file(file_name) && is_font_file(file_name)) { if (register_font_impl(file_name, library, font_file_mapping)) { success = true; } } } } } catch (std::exception const& ex) { MAPNIK_LOG_ERROR(font_engine_freetype) << "register_fonts: " << ex.what(); } return success; }
std::vector<std::string> list_directory(std::string const& dir) { std::vector<std::string> listing; boost::filesystem::directory_iterator end_itr; #ifdef _WINDOWS std::wstring wide_dir(mapnik::utf8_to_utf16(dir)); for (boost::filesystem::directory_iterator itr(wide_dir); itr != end_itr; ++itr) { listing.emplace_back(mapnik::utf16_to_utf8(itr->path().wstring())); } #else for (boost::filesystem::directory_iterator itr(dir); itr != end_itr; ++itr) { listing.emplace_back(itr->path().string()); } #endif return listing; }