IniFilePtr IniFile::ConstructFromFile(vfs::Path filename) { // Start parsing std::ifstream iniFile(filename.toString().c_str()); if (!iniFile) { Logger::warning( "[IniFile]: Cannot open file " + filename.toString() ); return IniFilePtr(); } return ConstructFromStream(iniFile); }
void IniFile::ExportToFile(vfs::Path file, const std::string& headerComments) const { std::ofstream stream(file.toString().c_str()); if (!headerComments.empty()) { // Split the header text into lines and export it as INI comment std::vector<std::string> lines = StringHelper::split( headerComments, "\n" ); for (std::size_t i = 0; i < lines.size(); ++i) { stream << "# " << lines[i] << std::endl; } // add some additional line break after the header stream << std::endl; } for (Sections::const_iterator i = _settings.begin(); i != _settings.end(); ++i) { stream << "[" << i->first << "]" << std::endl; for (Options::const_iterator kv = i->second.begin(); kv != i->second.end(); ++kv) { stream << kv->key << " = " << kv->value << std::endl; } stream << std::endl; } }
VariantMap SaveAdapter::load( const vfs::Path& filename ) { Logger::warning( "SaveAdapter: try load model from " + filename.toString() ); NFile f = NFile::open( filename ); return load( f ); }
bool Addon::open(vfs::Path path) { # ifdef CAESARIA_PLATFORM_WIN _d->library = ::LoadLibraryA(path.toString().c_str()); # else _d->library = ::dlopen(path.toString().c_str(), RTLD_LAZY); # endif if( _d->library != 0 ) { _d->isOpened = true; _d->funcInit = _d->initFunction<addonInitFunctor>( "initialize" ); _d->funcGetVersion = _d->initFunction<addonGetVersionFunctor>( "getVersion" ); _d->funcGetLevel = _d->initFunction<addonGetLevelFunctor>( "getLevel" ); } return _d->isOpened; }
void PictureBank::Impl::loadAtlas(const vfs::Path& filePath) { if( !filePath.exist() ) { Logger::warning( "PictureBank: cant find atlas " + filePath.toString() ); return; } VariantMap info = config::load( filePath ); vfs::Path texturePath = info.get( "texture" ).toString(); vfs::NFile file = vfs::NFile::open( texturePath ); Picture mainTexture; if( file.isOpen() ) { mainTexture = PictureLoader::instance().load( file ); } else { Logger::warning( "PictureBank: load atlas failed for texture" + texturePath.toString() ); mainTexture = Picture::getInvalid(); } //SizeF mainRectSize = mainTexture.size().toSizeF(); if( !info.empty() ) { VariantMap items = info.get( framesSection ).toMap(); for( auto& i : items ) { VariantList rInfo = i.second.toList(); Picture pic = mainTexture; Point start( rInfo.get( 0 ).toInt(), rInfo.get( 1 ).toInt() ); Size size( rInfo.get( 2 ).toInt(), rInfo.get( 3 ).toInt() ); pic.setOriginRect( Rect( start, size ) ); setPicture( i.first, pic ); } } }
void PictureInfoBank::initialize(vfs::Path filename) { Logger::warning( "PictureInfoBank: start load offsets from " + filename.toString() ); VariantMap m = config::load( filename ); foreach( it, m ) { Variant v = it->second; Logger::warning( "Set offset for " + it->first ); if( v.type() == Variant::Map ) { VariantMap vm = v.toMap(); int startIndex = vm[ "start" ]; int stopIndex = vm[ "stop" ]; std::string rc = vm[ "rc" ].toString(); Point offset = vm[ "offset" ].toPoint(); _d->setRange( rc.empty() ? it->first : rc, startIndex, stopIndex, offset ); } else if( v.type() == Variant::List ) { VariantList vl = v.toList(); _d->setOne( it->first, vl.get( idxIndex ), vl.get( idxXOffset ), vl.get( idxYOffset ) ); } }
void Game::Impl::initFontCollection( vfs::Path resourcePath ) { Logger::warning( "Game: load fonts" ); std::string fontname = SETTINGS_STR( font ); FontCollection::instance().initialize( resourcePath.toString(), fontname ); }