path Attributes::resolve(path name) { Attribute *a = _search_attr(attrs, name.generic_string()); if (a && a->link().size() == 0) return name; path partial; for(auto it=name.begin();it!=name.end();++it) { partial /= *it; a = _search_attr(attrs, partial.generic_string()); if (a) { if (a->link().size()) { path rest(a->link()); ++it; //everything matched - this is a link! if (it == name.end()) return a->link(); for(;it!=name.end();++it) rest /= *it; return resolve(rest); } else //name is no valid path! return name; } } return name; }
Mp3Lib::Episode::Episode(path p) { #ifndef SILENT_EPISODE_CORE cout << " Episode::Episode(" << p << ")" << endl; #endif _path = p; _hash = sha256(p.generic_string()); _pMp3File = NULL; #ifndef SILENT_EPISODE_CORE cout << " Episode::init(void)" << endl; #endif vector<path> mp3s = FileBrowser::getFiles(_path, MP3); #ifndef SILENT_EPISODE_INFO cout << " Episode " << _hash << " (" << _path << ") is parsing mp3s" << endl; #endif for(vector<path>::iterator it = mp3s.begin(); it!=mp3s.end(); ++it) { #ifndef SILENT_EPISODE_INFO cout << " Mp3 " << *it << endl; #endif _mp3Files.push_back(*it); } _mp3FilesIterator = _mp3Files.begin(); #ifndef SILENT_SERIES_INFO cout << " Episode " << _path << " parsing mp3s done" << endl; #endif //FileBrowser::browseFolders(_path, this, COVER); //FileBrowser::browseFolders(_path, this, MP3); }
TTFFontPtr LoadFixedSizeFont(const path &path, int pointSize)const { const std::string pathUtf8 = ConvertPathToUtf8(GetResourceAbspath(path)); TTFFontPtr pFont(TTF_OpenFont(pathUtf8.c_str(), pointSize)); if (!pFont) { throw std::runtime_error("Cannot find font at " + path.generic_string()); } return pFont; }
SDLSurfacePtr LoadFileImage(const path &path)const { const std::string pathUtf8 = ConvertPathToUtf8(GetResourceAbspath(path)); SDLSurfacePtr pSurface(IMG_Load(pathUtf8.c_str())); if (!pSurface) { throw std::runtime_error("Cannot find texture at " + path.generic_string()); } return pSurface; }
void Attributes::addLink(path name, path to) { Attribute a(resolve(name)); to = resolve(to); if (a.name == to) return; a.setLink(to.generic_string()); append(a); }
void HTMLEditor::Save(const path & path) { if (path.empty()) { throw runtime_error("Path cannot be empty!"); } if (path.has_parent_path()) { create_directories(path.parent_path()); } std::ofstream file(path.generic_string()); if (!file.is_open()) { throw runtime_error("Invalid path specified" + path.generic_string()); } file << "<!DOCTYPE html>\n<html>\n<head>\n\t<title>" << EncodeHtmlStr(m_document.GetTitle()) << "</title>\n</head>\n" << "<body>\n" << CreateBody(path) << "</body>\n</html>"; file.close(); }
virtual void save( const path& db ) override { std::ofstream out( db.generic_string(), std::ofstream::binary | std::ofstream::out | std::ofstream::trunc ); FC_ASSERT( out ); auto ver = get_object_version(); fc::raw::pack( out, _next_id ); fc::raw::pack( out, ver ); this->inspect_all_objects( [&]( const object& o ) { auto vec = fc::raw::pack( static_cast<const object_type&>(o) ); auto packed_vec = fc::raw::pack( vec ); out.write( packed_vec.data(), packed_vec.size() ); }); }
path GetResourceAbspath(const path &relpath)const { if (relpath.is_absolute()) { return relpath; } for (const auto &dir : m_searchPaths) { const path abspath = absolute(relpath, dir); if (exists(abspath)) { return abspath; } } throw std::runtime_error("Resource not found: " + relpath.generic_string()); }
virtual void open( const path& db )override { if( !fc::exists( db ) ) return; fc::file_mapping fm( db.generic_string().c_str(), fc::read_only ); fc::mapped_region mr( fm, fc::read_only, 0, fc::file_size(db) ); fc::datastream<const char*> ds( (const char*)mr.get_address(), mr.get_size() ); fc::sha256 open_ver; fc::raw::unpack(ds, _next_id); fc::raw::unpack(ds, open_ver); FC_ASSERT( open_ver == get_object_version(), "Incompatible Version, the serialization of objects in this index has changed" ); try { vector<char> tmp; while( true ) { fc::raw::unpack( ds, tmp ); load( tmp ); } } catch ( const fc::exception& ){} }
std::string LoadFileAsString(const path &relpath) { const path abspath = GetResourceAbspath(relpath); std::ifstream input; input.open(abspath.native()); if (!input.is_open()) { throw std::runtime_error("Cannot open for reading: " + abspath.generic_string()); } std::string text; text.reserve(FILE_RESERVE_SIZE); input.exceptions(std::ios::badbit); std::string line; while (std::getline(input, line)) { text.append(line); text.append("\n"); } return text; }
size_t hash_value(const path& p) noexcept { return std::hash<path::string_type>()(p.generic_string()); }
/** path to UTF-8 encoding. */ std::string toString(const path& p) { return p.generic_string(); }