bool Houses::SaveContainer(xmlNodePtr nodeitem, Container* ccontainer) { xmlNodePtr pn,nn; std::stringstream sb; if (ccontainer->size() != 0) { pn = xmlNewNode(NULL,(const xmlChar*)"inside"); for(int i = ccontainer->size()-1; i >= 0; i--) { Item * citem = ccontainer->getItem(i); nn = citem->serialize(); Container* in_container = dynamic_cast<Container*>(citem); if (in_container) SaveContainer(nn,in_container); xmlAddChild(pn, nn); } xmlAddChild(nodeitem, pn); } return true; }
//--------------------------------------------------------------------------- void __fastcall TFormCreateDoc::ButtonSaveClick(TObject *Sender) { if (!SaveDialog1->Execute()) return; SaveContainer(m_doctext,SaveDialog1->FileName.c_str()); }
bool ASSISTANT::Document::WriteLSD(LPCTSTR filename, bool bChangeFilename) { WCHAR *wszFilename = ASSISTANT::ConvertTCharToWChar(filename); FILE *datei = _wfopen(wszFilename, L"wb"); if (wszFilename) delete wszFilename; if (datei) { // Write Unicode BOMs BYTE bom1 = 0xFF; BYTE bom2 = 0xFE; fwrite(&bom1, 1, 1, datei); fwrite(&bom2, 1, 1, datei); CString csSgmlString; CString csName = containerName; StringManipulation::TransformForSgml(csName, csSgmlString); WCHAR *wszName = ASSISTANT::ConvertTCharToWChar(csSgmlString); CString csKeywords = scorm.GetKeywords(); StringManipulation::TransformForSgml(csKeywords, csSgmlString); WCHAR *wszKeywords = ASSISTANT::ConvertTCharToWChar(csSgmlString); CString csAuthor = scorm.GetAuthor(); StringManipulation::TransformForSgml(csAuthor, csSgmlString); WCHAR *wszAuthor = ASSISTANT::ConvertTCharToWChar(csSgmlString); CString csCreator = scorm.GetCreator(); StringManipulation::TransformForSgml(csCreator, csSgmlString); WCHAR *wszCreator = ASSISTANT::ConvertTCharToWChar(csSgmlString); fwprintf(datei, L"<ASSISTANT codepage=\"%d\" name=\"%s\" author=\"%s\" creator=\"%s\" keywords=\"%s\">\n", GetCodepage(), wszName, wszAuthor, wszCreator, wszKeywords); if (wszName) delete wszName; if (wszAuthor) delete wszAuthor; if (wszCreator) delete wszCreator; if (wszKeywords) delete wszKeywords; CString ssDocumentPath = filename; ASSISTANT::GetPath(ssDocumentPath); SaveContainer(datei, ssDocumentPath, 1, true); fwprintf(datei, L"</ASSISTANT>\n"); fclose(datei); if (bChangeFilename) m_csDocumentPath = ssDocumentPath; return true; } return false; }
bool Houses::SaveHouseItems(Game* game) { std::string filename = g_config.DATA_DIR + "houseitems.xml"; std::stringstream sb; xmlDocPtr doc; xmlNodePtr root, tileNode, itemNode; xmlMutexLock(xmlmutex); doc = xmlNewDoc((const xmlChar*)"1.0"); doc->children = xmlNewDocNode(doc, NULL, (const xmlChar*)"houseitems", NULL); root = doc->children; for (size_t i = 0; i < houses.size(); i++) { for (size_t j = 0; j < houses[i]->tiles.size(); j++) { Position& pos = houses[i]->tiles[j]; Tile *housetile = game->getTile(pos.x, pos.y, pos.z); bool firstItem = true; for (int i = housetile->getThingCount(); i >= 0; i--) { Item* item = dynamic_cast<Item*>(housetile->getThingByStackPos(i)); if (item && !item->isNotMoveable()) { if (firstItem) { tileNode = xmlNewNode(NULL, (const xmlChar*)"tile"); sb << pos.x; xmlSetProp(tileNode, (const xmlChar*) "x", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << pos.y; xmlSetProp(tileNode, (const xmlChar*) "y", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << pos.z; xmlSetProp(tileNode, (const xmlChar*) "z", (const xmlChar*)sb.str().c_str()); sb.str(""); firstItem = false; } itemNode = item->serialize(); Container *container = dynamic_cast<Container*>(item); if (container) SaveContainer(itemNode, container); xmlAddChild(tileNode, itemNode); } } if (!firstItem) xmlAddChild(root, tileNode); } } if (xmlSaveFile(filename.c_str(), doc)) { xmlFreeDoc(doc); xmlMutexUnlock(xmlmutex); return true; } else { std::cout << "Could not save " << filename << "!" << std::endl; xmlFreeDoc(doc); xmlMutexUnlock(xmlmutex); return false; } }