void CSoundAnimation::save() { // File stream COFile file; vector<NLMISC::CSheetId> sounds; // Open the file if (!file.open(_Filename.c_str())) { throw NLMISC::Exception("Can't open the file for writing"); } // Create the XML stream COXml output; // Init if (output.init (&file, "1.0")) { xmlDocPtr xmlDoc = output.getDocument(); // Create the first node xmlNodePtr root = xmlNewDocNode (xmlDoc, NULL, (const xmlChar*)"SOUNDANIMATION", NULL); xmlDocSetRootElement (xmlDoc, root); vector<CSoundAnimMarker*>::iterator iter; for (iter = _Markers.begin(); iter != _Markers.end(); iter++) { CSoundAnimMarker* marker = (*iter); set<string>::iterator iter; char s[64]; smprintf(s, 64, "%f", marker->getTime()); xmlNodePtr markerNode = xmlNewChild (root, NULL, (const xmlChar*)"MARKER", NULL); xmlSetProp (markerNode, (const xmlChar*) "time", (const xmlChar*) s); marker->getSounds(sounds); vector<NLMISC::CSheetId>::iterator iter2; for (iter2 = sounds.begin(); iter2 != sounds.end(); iter2++) { xmlNodePtr soundNode = xmlNewChild ( markerNode, NULL, (const xmlChar*)"SOUND", NULL ); xmlSetProp (soundNode, (const xmlChar*)"name", (const xmlChar*)iter2->toString().c_str() /*CStringMapper::unmap(*iter2).c_str()*/); } sounds.clear(); } // Flush the stream, write all the output file output.flush (); } // Close the file file.close (); _Dirty = false; }
/** Generate list of spell */ static void generateSpellList(CConfigFile &cf, const std::string &sheetName) { CConfigFile::CVar *spellList = cf.getVarPtr("spell_list"); if (!spellList) { nlwarning("Can't read spell list"); return; } COFile f; if (!f.open(sheetName, false, true)) { nlwarning("Can't write %s", sheetName.c_str()); return; } try { COXml xmlStreamOut; xmlStreamOut.init(&f); xmlStreamOut.xmlPush("FORM"); IStream &xmlStream = xmlStreamOut; xmlStream.xmlPush("STRUCT"); xmlStream.xmlPushBegin("ARRAY"); xmlStream.xmlSetAttrib("Name"); std::string name = "List"; xmlStream.serial(name); xmlStream.xmlPushEnd(); for(uint k = 0; k < (uint) spellList->size(); ++k) { std::vector<std::string> result; NLMISC::splitString(spellList->asString(k), "|", result); if (result.size() < 2) { nlwarning("Should provide at list spell name and id"); } xmlStream.xmlPush("STRUCT"); writeAtom(xmlStream, "ID", result[1]); writeAtom(xmlStream, "SheetBaseName", result[0]); xmlStream.xmlPop(); } xmlStream.xmlPop(); // STRUCT xmlStream.xmlPop(); // FORM } catch(const EStream &) { nlwarning("Cant write %s", sheetName.c_str()); } }
// --------------------------------------------------------------------------- void CGeorgesImpl::MakeTyp( const std::string& filename, TType type, TUI ui, const std::string& _min, const std::string& _max, const std::string& _default, const std::vector< std::pair< std::string, std::string > >* const _pvpredef ) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); // Create a type CType t; t.Type = (CType::TType)type; t.UIType = (CType::TUI)ui; t.Min= _min; t.Max = _max; t.Default = _default; if (_pvpredef) { t.Definitions.resize (_pvpredef->size ()); uint i; for (i=0; i<_pvpredef->size (); i++) { t.Definitions[i].Label = (*_pvpredef)[i].first; t.Definitions[i].Value = (*_pvpredef)[i].second; } } // Save the type COFile output; if (output.open (filename)) { try { // XML stream COXml outputXml; outputXml.init (&output); // Write t.write (outputXml.getDocument ()); } catch (Exception &e) { nlwarning ("Error during writing file '%s' : ", filename.c_str (), e.what ()); } } else { nlwarning ("Can't open the file %s for writing", filename.c_str ()); } }
// --------------------------------------------------------------------------- void CGeorgesImpl::createInstanceFile (const std::string &_sxFullnameWithoutExt, const std::string &_dfnname) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CFormLoader formLoader; CFormDfn *dfn = formLoader.loadFormDfn (_dfnname.c_str(), false); if (!dfn) { char msg[512]; smprintf (msg, 512, "Can't load DFN '%s'", _dfnname); theApp.outputError (msg); return; } NLMISC::CSmartPtr<NLGEORGES::UForm> Form = new CForm; std::string fullName; fullName = _sxFullnameWithoutExt + "."; int i = 0; if (_dfnname[i] == '.') ++i; for (; i < (int)_dfnname.size(); ++i) { if (_dfnname[i] == '.') break; fullName += _dfnname[i]; } ((CFormElmStruct*)&Form->getRootNode ())->build (dfn); COFile f; COXml ox; if (f.open (fullName)) { ox.init(&f); ((NLGEORGES::CForm*)((UForm*)Form))->write (ox.getDocument(), _sxFullnameWithoutExt.c_str ()); ox.flush(); f.close(); } else { char msg[512]; smprintf (msg, 512, "Can't write '%s'", fullName); theApp.outputError (msg); return; } }
/* * Save a Reference index file */ bool CRefIndex::save(const string& filename) { COFile reffile; COXml oxml; if (!reffile.open(filename) || !oxml.init(&reffile)) return false; try { serial(oxml); } catch (const Exception&) { return false; } return true; }
/* * Save State */ bool CDatabaseState::save(CRefIndex& ref) { COFile f; COXml oxml; string filename = fileName(ref); if (!f.open(filename) || !oxml.init(&f)) return false; try { serial(oxml); } catch (const Exception&) { return false; } return true; }
/* * Save the ranges into a data file */ void CRangeMirrorManager::saveRanges() { try { COFile file; if ( file.open( RANGE_MANAGER_BACKUP_FILE ) ) { COXml output; if ( output.init( &file, "1.0" ) ) { output.serialCont( _RangeListByDataSet ); output.flush(); } file.close(); } else throw EFileNotOpened( RANGE_MANAGER_BACKUP_FILE ); } catch ( Exception& e ) { nlwarning( "Can't save ranges: %s", e.what() ); } }
// write that spell as a sheet void writeSheet(const std::string &sheetName) { COFile f; if (!f.open(sheetName, false, true)) { nlwarning("Can't write %s", sheetName.c_str()); return; } try { COXml xmlStreamOut; xmlStreamOut.init(&f); xmlStreamOut.xmlPushBegin("FORM"); IStream &xmlStream = xmlStreamOut; /* std::string revision = "$revision$"; xmlStream.xmlSerial(revision, "Revision"); std::string state = "modified"; xmlStream.xmlSerial(state, "State"); */ xmlStream.xmlSetAttrib("Revision"); std::string revision = "$revision$"; xmlStream.serial(revision); xmlStream.xmlSetAttrib("State"); std::string state = "modified"; xmlStream.serial(state); xmlStream.xmlPushEnd(); // write parent list for(uint k = 0; k < Parents.size(); ++k) { xmlStream.xmlPushBegin("PARENT"); xmlStream.xmlSetAttrib("Filename"); xmlStream.serial(Parents[k]); xmlStream.xmlPushEnd(); xmlStream.xmlPop(); } if (!Projectile.empty() || !Impact.empty()) { xmlStream.xmlPush("STRUCT"); if (!Projectile.empty()) { xmlStream.xmlPushBegin("STRUCT"); xmlStream.xmlSetAttrib("Name"); std::string name = "Projectile"; xmlStream.serial(name); xmlStream.xmlPushEnd(); Projectile.serial(xmlStream); xmlStream.xmlPop(); } if (!Impact.empty()) { xmlStream.xmlPushBegin("STRUCT"); xmlStream.xmlSetAttrib("Name"); std::string name = "Impact"; xmlStream.serial(name); xmlStream.xmlPushEnd(); Impact.serial(xmlStream); xmlStream.xmlPop(); } xmlStream.xmlPop(); } else { xmlStream.xmlPush("STRUCT"); xmlStream.xmlPop(); } xmlStream.xmlPop(); } catch(const EStream &) { nlwarning("Cant write %s", sheetName.c_str()); } }
//----------------------------------------------- // dump : // Create a file with information to debug. //----------------------------------------------- void dump(const std::string &name) { // Write information to start as the version COFile fStart; if(fStart.open(name + "_start.rec", false, false)) { CVectorD currentPos = UserEntity->pos(); fStart.serialVersion(RecordVersion); fStart.serial(currentPos); // Close the File. fStart.close(); } else nlwarning("dump: cannot open/create the file '%s_start.rec'.", name.c_str()); // Write the DB IngameDbMngr.write(name + "_db.rec"); // Open the file. COFile f; if(f.open(name + ".rec", false, false)) { // Dump entities. EntitiesMngr.dump(f); // Dump Client CFG. ClientCfg.serial(f); // Close the File. f.close(); } else nlwarning("dump: cannot open/create the file '%s.rec'.", name.c_str()); // Open the file. if(f.open(name + ".xml", false, true)) { // Create the XML stream COXml output; // Init if(output.init (&f, "1.0")) { // Open the XML Dump. output.xmlPush("XML"); // Dump Client CFG. ClientCfg.serial(output); // Dump entities. EntitiesMngr.dumpXML(output); // Close the XML Dump. output.xmlPop(); // Flush the stream, write all the output file output.flush(); } else nlwarning("dump: cannot initialize '%s.xml'.", name.c_str()); // Close the File. f.close(); } else nlwarning("dump: cannot open/create the file '%s.xml'.", name.c_str()); }// dump //
BOOL CGeorgesEditDoc::OnSaveDocument(LPCTSTR lpszPathName) { // Get focus CWnd *focus = CWnd::GetFocus (); ::SetFocus (NULL); // Open the filt COFile file; if (file.open (lpszPathName)) { try { // Xml stream COXml xmlStream; xmlStream.init (&file); if (isType()) { nlassert (Type != NULL); // Write the file // Modified ? if (IsModified ()) { Type->Header.MinorVersion++; flushValueChange (); } Type->write (xmlStream.getDocument (), theApp.Georges4CVS); modify (NULL, NULL, false); flushValueChange (); UpdateAllViews (NULL); return TRUE; } else if (isDfn ()) { nlassert (Dfn != NULL); // Write the file if (IsModified ()) { Dfn->Header.MinorVersion++; flushValueChange (); } Dfn->write (xmlStream.getDocument (), lpszPathName, theApp.Georges4CVS); modify (NULL, NULL, false); UpdateAllViews (NULL); return TRUE; } else { nlassert (Form != NULL); // Write the file if (IsModified ()) { ((CForm*)(UForm*)Form)->Header.MinorVersion++; flushValueChange (); } ((CForm*)(UForm*)Form)->write (xmlStream.getDocument (), lpszPathName, theApp.Georges4CVS); if (strcmp (xmlStream.getErrorString (), "") != 0) { char message[512]; smprintf (message, 512, "Error while saving file: %s", xmlStream.getErrorString ()); theApp.outputError (message); } modify (NULL, NULL, false); flushValueChange (); UpdateAllViews (NULL); // Get the left view CView* pView = getLeftView (); return TRUE; } } catch (Exception &e) { char message[512]; smprintf (message, 512, "Error while loading file: %s", e.what()); theApp.outputError (message); return FALSE; } } else { char message[512]; smprintf (message, 512, "Can't open the file %s for writing.", lpszPathName); theApp.outputError (message); return FALSE; } // Set focus focus->SetFocus (); return FALSE; //return CDocument::OnSaveDocument(lpszPathName); }