Exemplo n.º 1
0
size_t IOFactory::loadFile( std::list<Chunk> &ret, const boost::filesystem::path &filename, std::string suffix_override, std::string dialect )
{
	FileFormatList formatReader;
	formatReader = getFileFormatList( filename.file_string(), suffix_override, dialect );
	const size_t nimgs_old = ret.size();   // save number of chunks
	const std::string with_dialect = dialect.empty() ?
									 std::string( "" ) : std::string( " with dialect \"" ) + dialect + "\"";

	if ( formatReader.empty() ) {
		if( !boost::filesystem::exists( filename ) ) {
			LOG( Runtime, error ) << util::MSubject( filename )
								  << " does not exist as file, and no suitable plugin was found to generate data from "
								  << ( suffix_override.empty() ? std::string( "that name" ) : std::string( "the suffix \"" ) + suffix_override + "\"" );
		} else if( suffix_override.empty() ) {
			LOG( Runtime, error ) << "No plugin found to read " << filename.file_string() << with_dialect;
		} else {
			LOG( Runtime, error ) << "No plugin supporting the requested suffix " << suffix_override << with_dialect << " was found";
		}
	} else {
		BOOST_FOREACH( FileFormatList::const_reference it, formatReader ) {
			LOG( ImageIoDebug, info )
					<< "plugin to load file" << with_dialect << " " << util::MSubject( filename ) << ": " << it->getName();

			try {
				return it->load( ret, filename.file_string(), dialect );
			} catch ( std::runtime_error &e ) {
				LOG( Runtime, formatReader.size() > 1 ? warning : error )
						<< "Failed to load " <<  filename << " using " <<  it->getName() << with_dialect << " ( " << e.what() << " )";
			}
		}
		LOG_IF( boost::filesystem::exists( filename ) && formatReader.size() > 1, Runtime, error ) << "No plugin was able to load: "   << util::MSubject( filename ) << with_dialect;
	}
Exemplo n.º 2
0
size_t IOFactory::loadFile( std::list<Chunk> &ret, const boost::filesystem::path &filename, util::istring suffix_override, util::istring dialect )
{
	FileFormatList formatReader;
	formatReader = getFileFormatList( filename.string(), suffix_override, dialect );
	const util::istring with_dialect = dialect.empty() ?
									   util::istring( "" ) : util::istring( " with dialect \"" ) + dialect + "\"";

	if ( formatReader.empty() ) {
		if( !boost::filesystem::exists( filename ) ) {
			LOG( Runtime, error ) << util::MSubject( filename )
								  << " does not exist as file, and no suitable plugin was found to generate data from "
								  << ( suffix_override.empty() ? util::istring( "that name" ) : util::istring( "the suffix \"" ) + suffix_override + "\"" );
		} else if( suffix_override.empty() ) {
			LOG( Runtime, error ) << "No plugin found to read " << filename << with_dialect;
		} else {
			LOG( Runtime, error ) << "No plugin supporting the requested suffix " << suffix_override << with_dialect << " was found";
		}
	} else {
		BOOST_FOREACH( FileFormatList::const_reference it, formatReader ) {
			LOG( ImageIoDebug, info )
					<< "plugin to load file" << with_dialect << " " << util::MSubject( filename ) << ": " << it->getName();

			try {
				int loaded=it->load( ret, filename.native(), dialect, m_feedback );
				BOOST_FOREACH( Chunk & ref, ret ) {
					if ( ! ref.hasProperty( "source" ) )
						ref.setPropertyAs( "source", filename.native() );
				}
				return loaded;
			} catch ( std::runtime_error &e ) {
				if( suffix_override.empty() ) {
					LOG( Runtime, formatReader.size() > 1 ? warning : error )
							<< "Failed to load " <<  filename << " using " <<  it->getName() << with_dialect << " ( " << e.what() << " )";
				} else {
					LOG( Runtime, warning )
							<< "The enforced format " << it->getName()  << " failed to read " << filename << with_dialect
							<< " ( " << e.what() << " ), maybe it just wasn't the right format";
				}
			}
		}
		LOG_IF( boost::filesystem::exists( filename ) && formatReader.size() > 1, Runtime, error ) << "No plugin was able to load: "   << util::MSubject( filename ) << with_dialect;
	}