void Context::saveCfgFile(const UknString& name) { ConfigParserPtr configParser = ConfigParser::MakeEmptyParser(CPT_XML); if(configParser) { configParser->beginNode(L"cfg"); configParser->beginNode(L"graphics"); configParser->setInt(L"width", mCfg.render_cfg.width); configParser->setInt(L"height", mCfg.render_cfg.height); configParser->setInt(L"top", mCfg.render_cfg.top); configParser->setInt(L"left", mCfg.render_cfg.left); configParser->setBool(L"show_mouse", mCfg.render_cfg.show_mouse); configParser->setBool(L"full_screen", mCfg.render_cfg.full_screen); configParser->setBool(L"resizable", mCfg.render_cfg.resizable); configParser->setInt(L"sample_count", mCfg.render_cfg.sample_count); configParser->setInt(L"sample_quality", mCfg.render_cfg.sample_quality); configParser->setString(L"color_fmt", element_format_to_string(mCfg.render_cfg.color_fmt)); configParser->setString(L"depth_stencil_fmt", element_format_to_string(mCfg.render_cfg.depth_stencil_fmt)); configParser->toNode(L"/cfg"); configParser->beginNode(L"plugins"); if(!mCfg.graphic_factory_name.empty()) configParser->setString(L"graphic_factory", mCfg.graphic_factory_name); } UknString formattedString = configParser->writeToString(); ResourcePtr resource = ResourceLoader::Instance().createFileResource(name); if(resource) { resource->getResourceStream()->write((const uint8*)formattedString.data(), formattedString.size()); } }
bool LocalizedStringTableLoader::Load(const UknString& file, LocalizedStringTable& stringTable) { ukn::ConfigParserPtr parser = ukn::ConfigParser::MakeParser(ukn::ResourceLoader::Instance().loadResource(file)); if(parser && parser->toNode(L"strings")) { parser->toFirstChild(); do { UknString lanName = parser->getCurrentNodeName(); if(!lanName.empty()) { stringTable.addLanguage(lanName); parser->toFirstChild(); do { UknString stringId = parser->getCurrentNodeName(); if(!stringId.empty()) { UknString value = parser->getString(L"value"); stringTable.addString(lanName, stringId, value); } } while(parser->toNextChild()); parser->toParent(); } } while(parser->toNextChild()); return true; } return false; }
bool Font::deserialize(const ConfigParserPtr& config) { mGlyphs.clear(); if(config && config->toNode(L"font")) { UknString font_name = config->getString(L"name"); if(!font_name.empty()) { UknString fullFontPath = Path::CheckAndGetFontPath(font_name); if(fullFontPath.empty()) { log_error(L"ukn::Font::deserialize: error finding font name " + font_name); return false; } ResourcePtr fontResource = ResourceLoader::Instance().loadResource(fullFontPath); if(fontResource && fontResource->getResourceStream()) { bool result = mFace->load(fontResource); if(result) { mGlyphs.resize(mFace->face->num_glyphs); for(int i = 0; i < mFace->face->num_glyphs; ++i) { mGlyphs[i].size = mFontSize; mGlyphs[i].face = &mFace->face; } } } } mEnableShadow = config->getBool(L"shadow", false); mEnableStroke = config->getBool(L"stroke", false); if(config->getBool(L"bold", false)) { this->setFTStyle(FT_STYLE_FLAG_BOLD); } if(config->getBool(L"italic", false)) { this->setFTStyle(FT_STYLE_FLAG_ITALIC); } mShadowXOffset = config->getInt(L"shadow_offset_x", 0); mShadowYOffset = config->getInt(L"shadow_offset_y", 0); mStrokeWidth = config->getInt(L"stroke_width", 0); mFontSize = config->getInt(L"size", 14); mFontName = font_name; config->toParent(); return true; } return false; }
bool LocalizedStringTableLoader::Save(const UknString& file, const LocalizedStringTable& stringTable) { ukn::ConfigParserPtr parser = ukn::ConfigParser::MakeEmptyParser(ukn::CPT_XML); if(parser) { parser->beginNode(L"strings"); for(LocalizedStringTable::LanguageMap::const_iterator it = stringTable.begin(), end = stringTable.end(); it != end; ++it) { parser->beginNode(it->first); const StringMap& stringMap = it->second; for(StringMap::StringMapCont::const_iterator it = stringMap.begin(), end = stringMap.end(); it != end; ++it) { parser->beginNode(it->first); parser->setString(L"value", it->second); parser->endNode(); // String->first; } parser->endNode(); } parser->endNode(); UknString content = parser->writeToString(); FILE* pfile = fopen(string::WStringToString(file).c_str(), "w+"); if(!pfile) return false; fwrite(content.c_str(), 1, content.size(), pfile); fclose(pfile); return true; } return false; }