/** * Writes the daventure data into the given file. * * @param folderName * Folder where to write the data * @param adventureData * Adventure data to write in the file * @param valid * True if the adventure is valid (can be executed in the * engine), false otherwise * @return True if the operation was succesfully completed, false otherwise */ public static bool writeData(string folderName, AdventureDataControl adventureData, bool valid) { bool dataSaved = false; // Create the necessary elements for building the DOM doc = new XmlDocument(); // Delete the previous XML files in the root of the project dir //DirectoryInfo projectFolder = new DirectoryInfo(folderName); //if (projectFolder.Exists) //{ // foreach (FileInfo file in projectFolder.GetFiles()) // { // file.Delete(); // } // foreach (DirectoryInfo dir in projectFolder.GetDirectories()) // { // dir.Delete(true); // } //} // Add the special asset files // TODO AssetsController.addSpecialAssets(); /** ******* START WRITING THE DESCRIPTOR ********* */ // Pick the main node for the descriptor XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "no"); //XmlDocumentType typeDescriptor = doc.CreateDocumentType("game-descriptor", "SYSTEM", "descriptor.dtd", null); doc.AppendChild(declaration); //doc.AppendChild(typeDescriptor); if (!valid) { DOMWriterUtility.DOMWrite(doc, adventureData, new DescriptorDOMWriter.InvalidAdventureDataControlParam()); } else { DOMWriterUtility.DOMWrite(doc, adventureData); } doc.Save(folderName + "/descriptor.xml"); /** ******** END WRITING THE DESCRIPTOR ********** */ /** ******* START WRITING THE CHAPTERS ********* */ // Write every chapter //XmlDocumentType typeChapter; int chapterIndex = 1; foreach (Chapter chapter in adventureData.getChapters()) { doc = new XmlDocument(); declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "no"); //typeChapter = doc.CreateDocumentType("eAdventure", "SYSTEM", "eadventure.dtd", null); doc.AppendChild(declaration); //doc.AppendChild(typeChapter); DOMWriterUtility.DOMWrite(doc, chapter); doc.Save(folderName + "/chapter" + chapterIndex++ + ".xml"); } /** ******** END WRITING THE CHAPTERS ********** */ /** ******* START WRITING THE METADATA ********* */ // Pick the main node for the descriptor var metadata = adventureData.getImsCPMetadata(); if (metadata != null) { var xmlMetadata = SerializeToXmlElement(new XmlDocument(), metadata); doc = new XmlDocument(); xmlMetadata = MetadataUtility.CleanXMLGarbage(doc, xmlMetadata); doc.AppendChild(xmlMetadata); doc.Save(folderName + "/imscpmetadata.xml"); } /** ******** END WRITING THE CHAPTERS ********** */ dataSaved = true; return(dataSaved); }