bool OptionHandler::convertWaveformData( const boost::filesystem::path& input_filename, const boost::filesystem::path& output_filename, const Options& options) { WaveformBuffer buffer; if (!buffer.load(input_filename.c_str())) { return false; } const int bits = options.hasBits() ? options.getBits() : buffer.getBits(); bool success = true; const boost::filesystem::path output_file_ext = output_filename.extension(); if (output_file_ext == ".json") { success = buffer.saveAsJson(output_filename.c_str(), bits); } else if (output_file_ext == ".txt") { success = buffer.saveAsText(output_filename.c_str(), bits); } return success; }
void Scan(const boost::filesystem::path & path) { if(args.verbose) printf("scanning %s\n", path.c_str()); if(!boost::filesystem::exists(path)) throw OpenDirException(); if(!boost::filesystem::is_directory(path)) throw OpenDirException(); // dont parse SVN if(path.has_extension() && (strcasecmp(path.extension().c_str(), ".svn")==0)) return; boost::filesystem::directory_iterator end; for( boost::filesystem::directory_iterator itor = boost::filesystem::directory_iterator( path ); itor != end; itor++) if(boost::filesystem::is_regular_file( itor->status() )) if( !itor->path().has_extension() || ((strcasecmp(itor->path().extension().c_str(), ".h")==0) || (strcasecmp(itor->path().extension().c_str(), ".hpp")==0)) ) Add( itor->path().string() ); if( boost::filesystem::is_symlink(path) ) return; // FIXME: better way to deal with gphoto's recursive symlinks? for( boost::filesystem::directory_iterator itor = boost::filesystem::directory_iterator( path ); itor != end; itor++) if(boost::filesystem::is_directory( itor->status() )) Scan( itor->path() ); }
void life_cycle_manager::create_file_backend( boost::filesystem::path file_name, const severity_level severity) { using namespace boost::log; if (file_name.extension() != extension) file_name += extension; auto backend(boost::make_shared<sinks::text_file_backend>( keywords::file_name = file_name.string(), keywords::rotation_size = 200 * 1024 * 1024, keywords::time_based_rotation = sinks::file::rotation_at_time_point(12, 0, 0))); backend->auto_flush(true); typedef sinks::synchronous_sink<sinks::text_file_backend> sink_type; auto sink(boost::make_shared<sink_type>(backend)); sink->set_filter( expressions::attr<severity_level>(severity_attr) >= severity); sink->set_formatter(expressions::format(record_format) % expressions::format_date_time<boost::posix_time::ptime>( time_stamp_attr, time_stamp_format) % expressions::attr<severity_level>(severity_attr) % expressions::attr<std::string>(channel_attr) % expressions::smessage); boost::log::core::get()->add_sink(sink); }
void SystemProcessPath::outputFileInfo( const boost::filesystem::path& rPath ) { std::string br = ""; if(rPath.extension() == ".exe" || rPath.extension() == ".EXE" || rPath.extension() == ".eXE" || rPath.extension() == ".exE" || rPath.extension() == ".eXe" || rPath.extension() == ".Exe") { br = rPath.parent_path().string(); br += "\\"; br += rPath.stem().string(); br += rPath.extension().string(); char bh[64]; sprintf_s(bh,"%d",iflag); stpath = bh; SystemProcessPath::mmmap.insert(std:: make_pair( SystemProcessPath::stpath,std::string(br))); } }
static std::string loadFile (boost::property_tree::ptree &config, const boost::filesystem::path &file) { boost::filesystem::path extension = file.extension(); boost::filesystem::path extension2 = file.stem().extension(); std::string fileName = file.filename().string(); boost::property_tree::ptree readConfig; if (extension2.string() == ".conf") { if (extension.string() == ".json") { boost::property_tree::read_json (file.string(), readConfig); } else if (extension.string() == ".info") { boost::property_tree::read_info (file.string(), readConfig); } else if (extension.string() == ".ini") { boost::property_tree::read_ini (file.string(), readConfig); } else if (extension.string() == ".xml") { boost::property_tree::read_xml (file.string(), readConfig); } else { throw ParseException ("Unknonw file format"); } } else { throw ParseException ("Unknonw file format"); } mergePropertyTrees (config, readConfig); config.put ("configPath", file.parent_path().string() ); fileName = fileName.substr (0, fileName.size() - extension.string().size() ); fileName = fileName.substr (0, fileName.size() - extension2.string().size() ); return fileName; }
void try_run_file(const boost::filesystem::path & cur) { if(cur.extension().native().compare(".py")) { return; } script_file_parser script_file(cur.native()); if(script_file.is_valid()) { boost::filesystem::path work, out; create_directories(cur, work, out); auto parent = cur.parent_path(); auto start = parent.begin(); for(auto p = config::tests.begin(); p != config::tests.end() && *p == *start; ++p, ++start) ; for(; start != parent.end(); ++start) { script_file.add_keyword((*start).native()); } script_file.add_title(cur.stem().native()); if(config::query->evaluate(script_file)) { script_scheduler()->schedule_file(cur, work, out); } } }
bool pathIsMusic(const boost::filesystem::path& path) { std::wstring ext = path.extension().wstring(); if (ext == L".mp3" || ext == L".mp2" || ext == L".mp1" || ext == L".wav" || ext == L".ogg" || ext == L".aiff" || ext == L".flac") return true; return false; }
bool pathIsImage(const boost::filesystem::path& path) { std::wstring ext = path.extension().wstring(); if (ext == L".jpg" || ext == L".jpeg" || ext == L".png") return true; return false; }
void DatasetManager::openFileHelper( boost::filesystem::path aPath, ProgressNotifier::Ptr aProgressNotifier, DatasetID aDatasetId, bool aUseAsCurrent ) { M4D::Imaging::AImage::Ptr image; if ( aPath.extension() == ".dcm" || aPath.extension() == ".DCM" ) { M4D::Dicom::DicomObjSetPtr dicomObjSet = M4D::Dicom::DicomObjSetPtr( new M4D::Dicom::DicomObjSet() ); M4D::Dicom::DcmProvider::LoadSerieThatFileBelongsTo( aPath, aPath.parent_path(), *dicomObjSet, aProgressNotifier ); image = M4D::Dicom::DcmProvider::CreateImageFromDICOM( dicomObjSet ); } else { image = M4D::Imaging::ImageFactory::LoadDumpedImage( aPath.string() ); } if (image) { registerImage( aDatasetId, aPath, image, aUseAsCurrent ); } if( aProgressNotifier ) { aProgressNotifier->finished(); } //mProdconn.PutDataset( image ); }
void write_image( Image_<PixelType, ResourceType>const& output_image, boost::filesystem::path const& pathname ){ // select pgm or ppm if( pathname.extension().native() == ".ppm" ){ // write the image write_ppm_image( output_image.getResource(), pathname ); } else if( pathname.extension().native() == ".pgm" ){ // output must be in PixelGray_u8 write_pgm_image( output_image.getResource(), pathname ); } else{ throw GEO::GeneralException(std::string("Unknown extension (")+pathname.extension().native()+")", std::string(__FILE__), __LINE__); } }
/** * Get the tags based on the directory structure. * * @param path Path to a file. * @return A vector of tags. */ vector<string> Dir_Parse::get_tags(const fs::path path) { vector<string> tags; string str_path = trim_path(path); // Remove everything we don't want. boost::trim_if(str_path, boost::is_any_of("/")); str_path = str_path.substr(0, str_path.find(path.extension().c_str())); // Split and return. boost::split(tags, str_path, boost::is_any_of("/")); return tags; }
void persister:: persist(const sml::model& m, const boost::filesystem::path& p) const { const std::string extension(p.extension().string()); if (extension != sml_xml_extension) { BOOST_LOG_SEV(lg, error) << unsupported_extension << extension; BOOST_THROW_EXCEPTION( persister_error(unsupported_extension + extension)); } using dogen::utility::serialization::xml_serialize; xml_serialize<model>(p, m); }
void dynamic_shader_format::load_shader(boost::filesystem::path const& filename) { std::string extension = filename.extension().string(); bool parse_outputs = false; if ((extension.compare(".fs") == 0) || (extension.compare(".frag") == 0)) { obj::shader_base::create_shader< fshd::type::gl_fragment_shader >(); parse_outputs = true; } else if ((extension.compare(".vs") == 0) || (extension.compare(".vert") == 0)) { obj::shader_base::create_shader< fshd::type::gl_vertex_shader >(); } else if ((extension.compare(".gs") == 0) || (extension.compare(".geom") == 0)) { obj::shader_base::create_shader< fshd::type::gl_geometry_shader >(); } else { __gtulu_error() << "Unknown shader extension " << extension << ", please use one of .fs/.frag, .gs/.geom or .vs/.vert."; } std::string source = gu::file::get_contents(filename); obj::shader_base::set_source(source.c_str()); outputs_.clear(); if (parse_outputs) { boost::regex expression("out\\s+(\\S+)\\s+(\\S+);"); boost::regex array_expression("\\s*(\\S+)\\s*\\[(\\S*)\\]\\s*"); boost::sregex_iterator it(source.begin(), source.end(), expression); boost::sregex_iterator end; std::uint32_t id = 0; while (it != end) { std::string type_name = it->str(1); std::string name = it->str(2); std::uint32_t size = 1; boost::sregex_iterator name_it(name.begin(), name.end(), array_expression); boost::sregex_iterator type_it(type_name.begin(), type_name.end(), array_expression); // We've found a static sized output vector, that's really nice... if (name_it != end) { name = name_it->str(1); size = boost::lexical_cast< std::uint32_t >(name_it->str(2)); // We've just found a dynamic sized output vector, what a wonderful idea... } else if (type_it != end) { type_name = type_it->str(1); size = -1; } outputs_.push_back(output_info(id++, name, fout::format::get(type_name), size, -1, -1)); ++it; } } } // load_shader
bool enableBigTIFF(const boost::optional<bool>& wantBig, storage_size_type pixelSize, const boost::filesystem::path& filename, ome::common::Logger& logger) { bool enable = false; // File extension in use. boost::filesystem::path ext = filename.extension(); // Enable BigTIFF if using a "big" file extension. bool extBig = (ext == boost::filesystem::path(".tf2") || ext == boost::filesystem::path(".tf8") || ext == boost::filesystem::path(".btf")); // Enable BigTIFF if the pixel size is sufficiently large. // Multiply by 5% to allow for alignment and TIFF metadata // overhead. bool needBig = (pixelSize + pixelSize/20) > storage_size_type(std::numeric_limits<uint32_t>::max()); if ((wantBig && *wantBig) // BigTIFF explicitly requested. || extBig // BigTIFF file extension used || (!wantBig && needBig)) // BigTIFF unspecified but needed. { enable = true; if (!wantBig && !extBig) // Not set manually { boost::format fmt ("Pixel data size is %1%, but TIFF without BigTIFF " "support enabled has a maximum size of %2%; " "automatically enabling BigTIFF support to prevent potential failure"); fmt % pixelSize % std::numeric_limits<uint32_t>::max(); BOOST_LOG_SEV(logger, ome::logging::trivial::warning) << fmt.str(); } } else if (wantBig && !*wantBig && needBig) // BigTIFF explicitly disabled but needed. { boost::format fmt ("Pixel data size is %1%, but TIFF with BigTIFF " "support disabled has a maximum size of %2%; " "TIFF writing may fail if the limit is exceeded"); fmt % pixelSize % std::numeric_limits<uint32_t>::max(); BOOST_LOG_SEV(logger, ome::logging::trivial::warning) << fmt.str(); } return enable; }
aiExport::Formats::const_iterator aiExport::findFormat( const boost::filesystem::path & path ) { const std::string extension = path.extension().string(); Formats::const_iterator format; for( format = m_formats.begin(); format != m_formats.end(); ++format ) { if( format->extension == extension ) { break; } } return format; }
/* * Process the file specified in parameter : * If the file is a markdown file, then it is rendered. Then, the result or the * file is copied in the output directory. */ void Site::output_processing(const bfs::path& file) { if (file.extension() == ".md") { std::cout << file.string() << " is a .md file."; //Page md_page(file); //md_page.render(); //md_page.save_to_file(output_page(file)); } else { std::cout << file.string() << " is not a .md file."; //file.copy(output_path(file)) } std::cout << std::endl; }
AssetManager::AssetLoader AssetManager::FindLoader(const boost::filesystem::path& path) { if(path.has_extension() == false) { return AssetLoader(); } AssetLoaderMap::iterator it = m_loaders.find(path.extension().string()); if(it != m_loaders.end()) { return it->second; } return AssetLoader(); }
void Compile(bool isRebuild, const slbuild::config::build_conf& bc, fs::path p, std::time_t bin_time) { if(!isRebuild){ auto src_time=fs::last_write_time(p); if(bin_time>src_time)return; } std::string ext=p.extension().string(); slbuild::utility::replace(ext, ".", ""); auto cc_itr=bc.compilers.find(ext); if(cc_itr==bc.compilers.end())return; std::system((bc.compilers.at(ext)+" -o obj/"+p.stem().string()+"_"+ext+".obj "+inc_and_lib()+" -c "+p.filename().string()).c_str()); }
/** * Check if filename is supported by GDAL */ bool isValidExtension( const boost::filesystem::path& filename ){ // get extension std::string extension = filename.extension().native(); // check for NITF if( ( extension == ".ntf" ) || ( extension == ".nitf" ) || ( extension == ".NTF" ) || ( extension == ".NITF" ) ){ return true; } return false; }
void run_file(const boost::filesystem::path & cur) { if(cur.extension().native().compare(".py")) { return; } script_file_parser script_file(cur.native()); if(script_file.is_valid()) { boost::filesystem::path work, out; create_directories(cur, work, out); script_scheduler()->schedule_file(cur, work, out); } }
FileFormat getFileFormatAndThrowIfUnknown(const boost::filesystem::path& fileName) { auto extension = fileName.extension().string(); if(!extension.empty()){ extension = extension.substr(1); } if(extension == "xml"){ return XML; } else if(extension == "ini") { return INI; } else if(extension == "json") { return JSON; } else if(extension == "info") { return INFO; } throw PropertyTree::InvalidFormatException("File " + fileName.string() + " has unknown format (extension=" + extension + " not in {ini,json,xml})!"); }
void ConvertFiles() { Safir::Dob::Typesystem::BinarySerialization bin; boost::filesystem::path storagePath = GetStorageDirectory(); for (boost::filesystem::directory_iterator it (storagePath); it != boost::filesystem::directory_iterator(); ++it) { const boost::filesystem::path path = it->path(); const EntityIdAndHandlerId id = Filename2EntityIdAndHandlerId(*it); if (path.extension() == ".bin") { const size_t fileSize = static_cast<size_t>(boost::filesystem::file_size(path)); if (fileSize == 0) { continue; } bin.resize(fileSize); size_t numBytesRead = 0; boost::filesystem::ifstream file(path, std::ios::in | std::ios::binary); while (file.good()) { file.read(&bin[0] + numBytesRead,4096); numBytesRead += static_cast<size_t>(file.gcount()); } if(fileSize != numBytesRead) { throw Safir::Dob::Typesystem::SoftwareViolationException(L"Stupid error in file reading, probably", __WFILE__, __LINE__); } file.close(); const Safir::Dob::Typesystem::ObjectPtr object = Safir::Dob::Typesystem::Serialization::ToObject(bin); const std::wstring xml = Safir::Dob::Typesystem::Serialization::ToXml(object); boost::filesystem::path xmlFileName(path); xmlFileName.replace_extension(".xml"); boost::filesystem::wofstream xmlFile(xmlFileName); xmlFile << xml; } } }
void ScintillaEditor::enumerateColorSchemesInPath(ScintillaEditor::colorscheme_set_t &result_set, const fs::path path) { const auto color_schemes = path / "color-schemes" / "editor"; if (fs::exists(color_schemes) && fs::is_directory(color_schemes)) { for (const auto& dirEntry : boost::make_iterator_range(fs::directory_iterator{color_schemes}, {})) { if (!fs::is_regular_file(dirEntry.status())) continue; const auto &path = dirEntry.path(); if (!(path.extension() == ".json")) continue; auto colorScheme = std::make_shared<EditorColorScheme>(path); if (colorScheme->valid()) { result_set.emplace(colorScheme->index(), colorScheme); } } } }
std::string MimeIconAssociation::name(const std::string& mimeType, const boost::filesystem::path& filename) { auto extension = filename.extension(); if (mimeType == "application/zip" || mimeType == "application/vnd.ms-office") { if (extension == "xlsx" || extension == "xltx") { return "spreadsheet"; } if (extension == "ppsx" || extension == "potx" || extension == "pptx" || extension == "sldx") { return "presentation"; } if (extension == "docx" || extension == "dotx") { return "document"; } } auto iconName = mimeType; iconName.replace(iconName.begin(), iconName.end(), "/", "-"); { const auto it = _data.find(iconName); if (it != _data.end()) { return it->second; } } { iconName = "gnome-mime-" + iconName; const auto it = _data.find(iconName); if (it != _data.end()) { return it->second; } } auto video = std::string("video"); auto audio = std::string("audio"); if (video.compare(0, video.size(), mimeType) == 0) { return "videos"; } if (audio.compare(0, audio.size(), mimeType) == 0) { return "music"; } return "none"; }
ScriptProperties::ScriptProperties(const boost::filesystem::path &file) { if (file.extension() != ".sql") { THROW(boost::format("Invalid file extension (should be .sql): %1%") % file.string()); } const std::string stem = file.stem().string(); const std::string targetDbVersionNum = stem.substr(0, versionLength); try { targetDbVersion = ::stringToNumber(targetDbVersionNum); } HANDLE_RETHROW(boost::format("Script file name should begin with a number (%1% digits): %2%") % size_t(versionLength) % file.string()); if (stem.size() < (versionLength + 1) || (stem[versionLength] != '_')) { THROW(boost::format("Number in a script file name has to begin with an underscore (_): %1%") % file.string()); } name = stem.substr(versionLength + 1); }
void plugin_manager_t::load_plugin( const boost::filesystem::path& p) { // TODO: add more error handling. if( p.extension() == ".so") { std::string fname = p.filename().string(); if( plugin_names_.find( fname) != plugin_names_.end()) return; /* std::auto_ptr<boost::extensions::shared_library> lib( new boost::extensions::shared_library( filesystem::file_string( p), true)); if( lib->open()) { boost::function<rdk_error_t( const rdk_app_info_t&)> f = lib->get<rdk_error_t, const rdk_app_info_t&>( "register_ramen_plugin"); if( f) { rdk_error_t err = f( app_info_); if( err == rdk_no_err) { plugins_.push_back( lib); plugin_names_.insert( fname); return; } else std::cerr << "error while loading plugin " << filesystem::file_string( p) << "\n"; } else std::cerr << "couldn't find register function in plugin " << filesystem::file_string( p) << "\n"; } else { std::cerr << "couldn't open plugin " << filesystem::file_string( p) << ".\n"; std::cerr << "dlerr = " << dlerror() << "\n\n"; } */ } }
void ConvertFiles() { Safir::Dob::Typesystem::BinarySerialization bin; boost::filesystem::path storagePath = GetStorageDirectory(); for (boost::filesystem::directory_iterator it (storagePath); it != boost::filesystem::directory_iterator(); ++it) { const boost::filesystem::path path = it->path(); const EntityIdAndHandlerId id = Filename2EntityIdAndHandlerId(*it); if (path.extension() == ".bin") { const size_t fileSize = static_cast<size_t>(boost::filesystem::file_size(path)); if (fileSize == 0) { continue; } bin.resize(fileSize); boost::filesystem::ifstream file(path, std::ios::in | std::ios::binary); file.read(&bin[0],fileSize); const Safir::Dob::Typesystem::ObjectPtr object = Safir::Dob::Typesystem::Serialization::ToObject(bin); const std::string xml = Safir::Dob::Typesystem::Utilities::ToUtf8 (Safir::Dob::Typesystem::Serialization::ToXml(object)); boost::filesystem::path xmlFileName(path); xmlFileName.replace_extension(".xml"); boost::filesystem::ofstream xmlFile(xmlFileName); xmlFile << xml; xmlFile.close(); //make the file world read-writeable using namespace boost::filesystem; permissions(path, owner_read | owner_write | group_read | group_write | others_read | others_write ); } } }
CPsfArchive::PsfArchivePtr CPsfArchive::CreateFromPath(const boost::filesystem::path& filePath) { auto extension = filePath.extension().string(); PsfArchivePtr result; if(!strcmp(extension.c_str(), ".zip")) { result = std::make_unique<CPsfZipArchive>(); } #ifdef RAR_SUPPORT else if(!strcmp(extension.c_str(), ".rar")) { result = std::make_unique<CPsfRarArchive>(); } #endif else { throw std::runtime_error("Unsupported archive type."); } result->Open(filePath); return result; }
GraphDef* GraphDef_LoadDir(World *inWorld, const bfs::path& dirname, GraphDef *inList) { boost::system::error_code ec; bfs::recursive_directory_iterator rditer(dirname, bfs::symlink_option::recurse, ec); if (ec) { scprintf( "*** ERROR: open directory failed '%s'\n", SC_Codecvt::path_to_utf8_str(dirname).c_str() ); return inList; } while (rditer != bfs::end(rditer)) { const bfs::path path = *rditer; if (bfs::is_directory(path)) { if (SC_Filesystem::instance().shouldNotCompileDirectory(path)) rditer.no_push(); else ; // do nothing; recursion will happen automatically } else if (path.extension() == ".scsyndef") { // ordinary file inList = GraphDef_Load(inWorld, path, inList); } else { // ignore file, wasn't a synth def } rditer.increment(ec); if (ec) { scprintf( "*** ERROR: Could not iterate on '%s': %s\n", SC_Codecvt::path_to_utf8_str(path).c_str(), ec.message().c_str() ); return inList; } } return inList; }
void parser_filepath(const vrString& filePath, vrString& strParentPath, vrString& strFileName, vrString& strStem, vrString& strExtension) { const fs::path p1 = filePath; strParentPath = p1.parent_path().string(); strFileName = p1.filename().string(); strExtension = p1.extension().string(); strStem = p1.stem().string(); }