Changeset 923
- Timestamp:
- Feb 3, 2014, 4:42:14 PM (11 years ago)
- Location:
- XmlTools2/trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
XmlTools2/trunk/main.cpp
r920 r923 19 19 20 20 bool noBackups=false; 21 bool noVerbose=false; 21 22 22 23 QCommandLineOption addValuesOption(QStringList() << "a" << "add-values", "Add values to a set of XML elements."); … … 41 42 QCommandLineOption xPathExpressionOption(QStringList() << "x" << "xpath-expression", "XPath 1.0 expression to select elements where processing will occur.", "xpath-expression"); 42 43 QCommandLineOption noBackupsOption(QStringList() << "no-backups", "No backups [faster processing]."); 44 QCommandLineOption noVerboseOption(QStringList() << "no-verbose", "Reduce the number of text messages output [faster processing]."); 43 45 44 46 parser.addOption(addValuesOption); … … 63 65 parser.addOption(xPathExpressionOption); 64 66 parser.addOption(noBackupsOption); 67 parser.addOption(noVerboseOption); 65 68 66 69 parser.addVersionOption(); … … 78 81 if(parser.isSet(noBackupsOption)){ 79 82 noBackups=true; 83 } 84 85 // Check if the user doesn't want verbose mode (it boosts XmlTools peformance, lower std output) 86 if(parser.isSet(noVerboseOption)){ 87 noVerbose=true; 80 88 } 81 89 … … 92 100 93 101 94 XmlPatch myXmlPatch(patchFilesWildCard,forceTargetFilesWildcard,noBackups );102 XmlPatch myXmlPatch(patchFilesWildCard,forceTargetFilesWildcard,noBackups,noVerbose); 95 103 myXmlPatch.readAndProcessPatchFile(); // beging file patch processing 96 104 … … 168 176 169 177 if(parser.isSet(elementNameOption)){ 170 myXmlTools=new XmlTools(filesWildCard,filters,noBackups );178 myXmlTools=new XmlTools(filesWildCard,filters,noBackups,noVerbose); 171 179 } 172 180 else{ 173 myXmlTools=new XmlTools(filesWildCard,xPathExpression,noBackups );181 myXmlTools=new XmlTools(filesWildCard,xPathExpression,noBackups,noVerbose); 174 182 } 175 183 -
XmlTools2/trunk/readme.txt
r920 r923 20 20 ---------------------------------- 21 21 22 -Update a xml node (for example, to reposition an OBAN animation or adjust pelvis height for a TRAM).22 -Update all values in a set of XML elements. (e.g., to reposition an OBAN animation or adjust pelvis height for a TRAM). 23 23 24 -Invert a xml node (for example, invert an OBAN animation).24 -Inverts a set of XML elements. (e.g., invert an OBAN animation). 25 25 26 -Add new values to XML elements (for example, add the 'unkillable' flag to some characters in a level).26 -Add new values to a set of XML elements (e.g., add the 'unkillable' flag to some characters in a level). 27 27 28 -Remove values from XML elements (for example, remove boss shields from characters in a level).28 -Remove values from a set of XML elements (e.g., remove boss shields from characters in a level). 29 29 30 -Replace values in XML elements (for example, increase the health of characters by replacing the old HP value).30 -Replace values in a set XML elements (e.g., increase the health of characters by replacing the old HP value). 31 31 32 32 -Patch file support allows the modder to list multiple commands in a file, to all be performed at once. … … 62 62 Change Log: 63 63 ---------------------------------- 64 2.0, 25-01-201464 2.0, 04-02-2014 65 65 -Rewrite XmlTools fom the scratch from C# to C++ in order to increase (much!) the performance of the program 66 -The program now uses the following libraries: Qt5, pugixml, 67 Qt5 Google V8 javascript engine and jsxml js library 68 -The commands were simplified (they now use the unix like syntax) 66 -The program now uses the following libraries: Qt5, pugixml and jsxml js library 67 -The commands were simplified (they now use unix like syntax) 69 68 -Update node operation (old updatechainvalues) it now receives the DIFFERENCE between the old value 70 69 and the new value instead of the new value 71 70 -Update node operation (old updatechainvalues) relation parameter was removed 72 71 -The program now only edits files with .xml extension 72 -The program now only reads patches files with .patch or .oni-patch extensions 73 73 -The patch files now have a XmlTools minimum version 74 -The program now only reads patches files with .patch or .oni-patch extensions 75 -Some patch files operations were renamed: 76 ADDTO -> ADD_INSIDE_NODE 77 REMOVE -> REMOVE_NODE 78 CUSTOMCODE -> CUSTOM_CODE 74 -Some patch files operations were renamed and some extra arguments added 79 75 -Added option to select xml elements by attribute name and value 80 -Added option to select xml elements by XPath 1.0 (should reduce the need of javascript) 76 -Added option to select xml elements by XPath 1.0 (should reduce further the need of javascript) 77 -The insertion of xml via patch now support multiple nodes inside <xml></xml> tags -
XmlTools2/trunk/util.cpp
r920 r923 171 171 QString pathNormalized; 172 172 QStringList nameWildCard; // entryList requires a QStringList 173 QStringList resultFiles; // result files with absolute path 173 174 int endOfPathIdx; 174 175 QDir directory; … … 181 182 pathNormalized=Util::normalizePath(wildcard); // Convert slashes to work in both mac and windows 182 183 183 if(pathNormalized.contains("/")){ 184 if(pathNormalized.contains("/")){ // If contains full path 184 185 endOfPathIdx=Util::indexOfBackward(pathNormalized,"/"); // get last slash 185 186 … … 189 190 190 191 directory=QDir(pathNormalized); 191 192 return directory.entryList(nameWildCard); 193 } 194 195 nameWildCard << wildcard; 196 197 return directory.entryList(nameWildCard); 198 } 199 200 } 192 } 193 else{ // if relative 194 nameWildCard << wildcard; 195 } 196 197 foreach (QFileInfo fileInfo, directory.entryInfoList(nameWildCard)){ 198 resultFiles << fileInfo.absoluteFilePath(); 199 } 200 201 return resultFiles; 202 } 203 204 } -
XmlTools2/trunk/utilxmltools.cpp
r920 r923 43 43 } 44 44 45 void backupFile(const QString &file ){45 void backupFile(const QString &file, bool verboseEnabled){ 46 46 if(!QFile::exists(file+".bak")){ 47 47 if(!Util::backupFile(file)){ … … 51 51 } 52 52 else{ 53 std::cout << "Backup file '" << file.toLatin1().constData() << "'' already exists. Skipping..." << std::endl; 53 if(verboseEnabled){ 54 std::cout << "Backup file '" << file.toLatin1().constData() << "'' already exists. Skipping..." << std::endl; 55 } 54 56 } 55 57 } -
XmlTools2/trunk/utilxmltools.h
r920 r923 12 12 QStringList getAllXmlFilesByWildcard(const QString &wildcard); 13 13 QStringList getAllPatchFilesByWildcard(const QString &wildcard); 14 void backupFile(const QString &file );14 void backupFile(const QString &file, bool verboseEnabled); 15 15 void getAllNamedElements(pugi::xml_node &node, QList<pugi::xml_node> &result, XmlFilter &filters); 16 16 void getAllXpathElements(const QString &xPathExpression, pugi::xml_document &doc, QList<pugi::xml_node> &result); … … 22 22 //// inline functions 23 23 24 inline void loadXmlFile(const QString &file, pugi::xml_document &document, pugi::xml_node &rootNode, bool backupsEnabled, const QString &operationForErrorMessage){24 inline void loadXmlFile(const QString &file, pugi::xml_document &document, pugi::xml_node &rootNode, bool backupsEnabled, bool verboseEnabled, const QString &operationForErrorMessage){ 25 25 26 26 pugi::xml_parse_result result = document.load_file(file.toLatin1().constData()); … … 28 28 29 29 if(result.status==pugi::status_ok){ 30 std::cout << "File '" << file.toLatin1().constData() << "' loaded with sucess." << std::endl; 30 if(verboseEnabled){ 31 std::cout << "File '" << file.toLatin1().constData() << "' loaded with sucess." << std::endl; 32 } 31 33 } 32 34 else{ … … 35 37 36 38 if(backupsEnabled){ 37 UtilXmlTools::backupFile(file ); // bake a backup of the file.39 UtilXmlTools::backupFile(file,verboseEnabled); // bake a backup of the file. 38 40 } 39 41 -
XmlTools2/trunk/xmlpatch.cpp
r920 r923 1 1 #include "xmlpatch.h" 2 2 3 XmlPatch::XmlPatch(QString patchFilesWildcard, QString forceTargetFilesWildcard, bool noBackups )3 XmlPatch::XmlPatch(QString patchFilesWildcard, QString forceTargetFilesWildcard, bool noBackups, bool noVerbose) 4 4 { 5 5 this->patchFilesToProcess=UtilXmlTools::getAllPatchFilesByWildcard(patchFilesWildcard); 6 6 this->forceTargetFilesWildcard=forceTargetFilesWildcard; 7 7 this->backupsEnabled=!noBackups; 8 this->verboseEnabled=!noVerbose; 8 9 9 10 if(forceTargetFilesWildcard!=""){ … … 66 67 for(int i=0; i<filesToProcess.size(); i++){ 67 68 68 UtilXmlTools::loadXmlFile(filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, "@ADD_INSIDE_NODES");69 UtilXmlTools::loadXmlFile(filesToProcess[i],this->document,this->rootNode,this->backupsEnabled,this->verboseEnabled,"@ADD_INSIDE_NODES"); 69 70 70 71 // Check how the element will be fetched via element name or xpath expression … … 97 98 98 99 for(int j=0; j<nodesToInsertion.size(); j++){ 99 nodesToInsertion[j].prepend_copy(newNode.first_child()); // append the new node 100 } 101 100 for (pugi::xml_node currNodeToInsert = newNode.first_child(); currNodeToInsert; currNodeToInsert = currNodeToInsert.next_sibling()) 101 { 102 nodesToInsertion[j].append_copy(currNodeToInsert); // append the new node 103 } 104 105 } 102 106 103 107 UtilXmlTools::saveXmlFile(filesToProcess[i],this->document, "@ADD_INSIDE_NODES"); 108 109 nodesToInsertion.clear(); 104 110 } 105 111 … … 122 128 for(int i=0; i<filesToProcess.size(); i++){ 123 129 124 UtilXmlTools::loadXmlFile(filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, "@REMOVE_NODES");130 UtilXmlTools::loadXmlFile(filesToProcess[i],this->document,this->rootNode,this->backupsEnabled,this->verboseEnabled,"@REMOVE_NODES"); 125 131 126 132 // Check how the element will be fetched via element name or xpath expression … … 173 179 174 180 UtilXmlTools::saveXmlFile(filesToProcess[i],this->document, "@REMOVE_NODES"); 181 182 nodesToDeletion.clear(); 175 183 } 176 184 … … 243 251 244 252 if(this->backupsEnabled){ 245 UtilXmlTools::backupFile(filesToProcess[i] );253 UtilXmlTools::backupFile(filesToProcess[i], this->verboseEnabled); 246 254 } 247 255 -
XmlTools2/trunk/xmlpatch.h
r920 r923 7 7 { 8 8 public: 9 XmlPatch(QString patchFilesWildcard, QString forceTargetFilesWildcard ="", bool backupsEnabled=true);9 XmlPatch(QString patchFilesWildcard, QString forceTargetFilesWildcard, bool backupsEnabled, bool noVerbose); 10 10 void readAndProcessPatchFile(); 11 11 private: … … 14 14 pugi::xml_document document; 15 15 pugi::xml_node rootNode; 16 bool backupsEnabled ;16 bool backupsEnabled, verboseEnabled; 17 17 QString getPatchParameterValue(const QString& line, QString parameter); 18 18 void insertNodesOperation(const QString &xmlString, XmlFilter &filters, const QString &xPathExpression, const QString &filesWildcard=""); -
XmlTools2/trunk/xmltools.cpp
r920 r923 2 2 3 3 // Filters constructor 4 XmlTools::XmlTools(QString filesWildcard, XmlFilter filter, bool noBackups )4 XmlTools::XmlTools(QString filesWildcard, XmlFilter filter, bool noBackups, bool noVerbose) 5 5 { 6 6 this->filesToProcess=UtilXmlTools::getAllXmlFilesByWildcard(filesWildcard); 7 7 this->filters=filter; 8 8 this->backupsEnabled=!noBackups; 9 this->verboseEnabled=!noVerbose; 9 10 10 11 if(this->filesToProcess.isEmpty()){ … … 14 15 15 16 // XPath constructor 16 XmlTools::XmlTools(QString filesWildcard, QString xPathExpression, bool noBackups )17 XmlTools::XmlTools(QString filesWildcard, QString xPathExpression, bool noBackups, bool noVerbose) 17 18 { 18 19 this->filesToProcess=UtilXmlTools::getAllXmlFilesByWildcard(filesWildcard); 19 20 this->xPathExpression=xPathExpression; 20 21 this->backupsEnabled=!noBackups; 22 this->verboseEnabled=!noVerbose; 21 23 } 22 24 … … 30 32 QList<pugi::xml_node> elements; 31 33 32 UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, "add-values");34 UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled,this->verboseEnabled,"add-values"); 33 35 34 36 newValuesList=Util::qStringListFromSpacedString(newValues); … … 71 73 bool elementChanged=false; 72 74 73 UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, "remove-values");75 UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, this->verboseEnabled, "remove-values"); 74 76 75 77 // Check how the elements will be fetched via element name or xpath expression … … 118 120 bool elementChanged=false; 119 121 120 UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, "replace-value");122 UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, this->verboseEnabled, "replace-value"); 121 123 122 124 // Check how the elements will be fetched via element name or xpath expression … … 158 160 QList<pugi::xml_node> elements; 159 161 160 UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, "replace-all");162 UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, this->verboseEnabled, "replace-all"); 161 163 162 164 // Check how the elements will be fetched via element name or xpath expression … … 198 200 MultiDimVar newXmlValue(0); // value that will update currValue 199 201 200 UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, "update-elements");202 UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled,this->verboseEnabled, "update-elements"); 201 203 202 204 // Check how the elements will be fetched via element name or xpath expression … … 242 244 // Process all XmlFiles 243 245 for(int i=0; i<this->filesToProcess.size(); i++){ 244 UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, "invert-elements");246 UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, this->verboseEnabled, "invert-elements"); 245 247 246 248 QList<pugi::xml_node> elements; -
XmlTools2/trunk/xmltools.h
r920 r923 25 25 { 26 26 public: 27 XmlTools(QString filesWildcard, XmlFilter filter, bool noBackups );28 XmlTools(QString filesWildcard, QString xPathExpression, bool noBackups );27 XmlTools(QString filesWildcard, XmlFilter filter, bool noBackups, bool noVerbose); 28 XmlTools(QString filesWildcard, QString xPathExpression, bool noBackups, bool noVerbose); 29 29 void addValues(QString newValues); 30 30 void removeValues(QString valuesToRemove); … … 40 40 QString xPathExpression; 41 41 XmlFilter filters; 42 bool backupsEnabled ;42 bool backupsEnabled, verboseEnabled; 43 43 }; 44 44
Note:
See TracChangeset
for help on using the changeset viewer.