Beispiel #1
0
 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::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;
 }