Changeset 923


Ignore:
Timestamp:
Feb 3, 2014, 4:42:14 PM (11 years ago)
Author:
s10k
Message:

XmlTools2
added --no-verbose mode
The insertion of xml via patch now support multiple nodes inside <xml></xml> tags

Location:
XmlTools2/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • XmlTools2/trunk/main.cpp

    r920 r923  
    1919
    2020    bool noBackups=false;
     21    bool noVerbose=false;
    2122
    2223    QCommandLineOption addValuesOption(QStringList() << "a" << "add-values", "Add values to a set of XML elements.");
     
    4142    QCommandLineOption xPathExpressionOption(QStringList() << "x" << "xpath-expression", "XPath 1.0 expression to select elements where processing will occur.", "xpath-expression");
    4243    QCommandLineOption noBackupsOption(QStringList()  << "no-backups", "No backups [faster processing].");
     44    QCommandLineOption noVerboseOption(QStringList()  << "no-verbose", "Reduce the number of text messages output [faster processing].");
    4345
    4446    parser.addOption(addValuesOption);
     
    6365    parser.addOption(xPathExpressionOption);
    6466    parser.addOption(noBackupsOption);
     67    parser.addOption(noVerboseOption);
    6568
    6669    parser.addVersionOption();
     
    7881    if(parser.isSet(noBackupsOption)){
    7982        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;
    8088    }
    8189
     
    92100
    93101
    94         XmlPatch myXmlPatch(patchFilesWildCard,forceTargetFilesWildcard,noBackups);
     102        XmlPatch myXmlPatch(patchFilesWildCard,forceTargetFilesWildcard,noBackups,noVerbose);
    95103        myXmlPatch.readAndProcessPatchFile(); // beging file patch processing
    96104
     
    168176
    169177    if(parser.isSet(elementNameOption)){
    170         myXmlTools=new XmlTools(filesWildCard,filters,noBackups);
     178        myXmlTools=new XmlTools(filesWildCard,filters,noBackups,noVerbose);
    171179    }
    172180    else{
    173         myXmlTools=new XmlTools(filesWildCard,xPathExpression,noBackups);
     181        myXmlTools=new XmlTools(filesWildCard,xPathExpression,noBackups,noVerbose);
    174182    }
    175183
  • XmlTools2/trunk/readme.txt

    r920 r923  
    2020----------------------------------
    2121
    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).
    2323
    24 -Invert a xml node (for example, invert an OBAN animation).
     24-Inverts a set of XML elements. (e.g., invert an OBAN animation).
    2525
    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).
    2727
    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).
    2929
    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).
    3131
    3232-Patch file support allows the modder to list multiple commands in a file, to all be performed at once.
     
    6262Change Log:
    6363----------------------------------
    64 2.0, 25-01-2014
     642.0, 04-02-2014
    6565-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)
    6968-Update node operation (old updatechainvalues) it now receives the DIFFERENCE between the old value
    7069and the new value instead of the new value
    7170-Update node operation (old updatechainvalues) relation parameter was removed
    7271-The program now only edits files with .xml extension
     72-The program now only reads patches files with .patch or .oni-patch extensions
    7373-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
    7975-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  
    171171    QString pathNormalized;
    172172    QStringList nameWildCard; // entryList requires a QStringList
     173    QStringList resultFiles; // result files with absolute path
    173174    int endOfPathIdx;
    174175    QDir directory;
     
    181182    pathNormalized=Util::normalizePath(wildcard); // Convert slashes to work in both mac and windows
    182183
    183     if(pathNormalized.contains("/")){
     184    if(pathNormalized.contains("/")){ // If contains full path
    184185        endOfPathIdx=Util::indexOfBackward(pathNormalized,"/"); // get last slash
    185186
     
    189190
    190191        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  
    4343}
    4444
    45 void backupFile(const QString &file){
     45void backupFile(const QString &file, bool verboseEnabled){
    4646    if(!QFile::exists(file+".bak")){
    4747        if(!Util::backupFile(file)){
     
    5151    }
    5252    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        }
    5456    }
    5557}
  • XmlTools2/trunk/utilxmltools.h

    r920 r923  
    1212QStringList getAllXmlFilesByWildcard(const QString &wildcard);
    1313QStringList getAllPatchFilesByWildcard(const QString &wildcard);
    14 void backupFile(const QString &file);
     14void backupFile(const QString &file, bool verboseEnabled);
    1515void getAllNamedElements(pugi::xml_node &node, QList<pugi::xml_node> &result, XmlFilter &filters);
    1616void getAllXpathElements(const QString &xPathExpression, pugi::xml_document &doc, QList<pugi::xml_node> &result);
     
    2222//// inline functions
    2323
    24 inline void loadXmlFile(const QString &file, pugi::xml_document &document, pugi::xml_node &rootNode, bool backupsEnabled, const QString &operationForErrorMessage){
     24inline void loadXmlFile(const QString &file, pugi::xml_document &document, pugi::xml_node &rootNode, bool backupsEnabled, bool verboseEnabled, const QString &operationForErrorMessage){
    2525
    2626    pugi::xml_parse_result result = document.load_file(file.toLatin1().constData());
     
    2828
    2929    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        }
    3133    }
    3234    else{
     
    3537
    3638    if(backupsEnabled){
    37         UtilXmlTools::backupFile(file); // bake a backup of the file.
     39        UtilXmlTools::backupFile(file,verboseEnabled); // bake a backup of the file.
    3840    }
    3941
  • XmlTools2/trunk/xmlpatch.cpp

    r920 r923  
    11#include "xmlpatch.h"
    22
    3 XmlPatch::XmlPatch(QString patchFilesWildcard, QString forceTargetFilesWildcard, bool noBackups)
     3XmlPatch::XmlPatch(QString patchFilesWildcard, QString forceTargetFilesWildcard, bool noBackups, bool noVerbose)
    44{
    55    this->patchFilesToProcess=UtilXmlTools::getAllPatchFilesByWildcard(patchFilesWildcard);
    66    this->forceTargetFilesWildcard=forceTargetFilesWildcard;
    77    this->backupsEnabled=!noBackups;
     8    this->verboseEnabled=!noVerbose;
    89
    910    if(forceTargetFilesWildcard!=""){
     
    6667    for(int i=0; i<filesToProcess.size(); i++){
    6768
    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");
    6970
    7071        // Check how the element will be fetched via element name or xpath expression
     
    9798
    9899        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        }
    102106
    103107        UtilXmlTools::saveXmlFile(filesToProcess[i],this->document, "@ADD_INSIDE_NODES");
     108
     109        nodesToInsertion.clear();
    104110    }
    105111
     
    122128    for(int i=0; i<filesToProcess.size(); i++){
    123129
    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");
    125131
    126132        // Check how the element will be fetched via element name or xpath expression
     
    173179
    174180        UtilXmlTools::saveXmlFile(filesToProcess[i],this->document, "@REMOVE_NODES");
     181
     182        nodesToDeletion.clear();
    175183    }
    176184
     
    243251
    244252        if(this->backupsEnabled){
    245             UtilXmlTools::backupFile(filesToProcess[i]);
     253            UtilXmlTools::backupFile(filesToProcess[i], this->verboseEnabled);
    246254        }
    247255
  • XmlTools2/trunk/xmlpatch.h

    r920 r923  
    77{
    88public:
    9     XmlPatch(QString patchFilesWildcard, QString forceTargetFilesWildcard="", bool backupsEnabled=true);
     9    XmlPatch(QString patchFilesWildcard, QString forceTargetFilesWildcard, bool backupsEnabled, bool noVerbose);
    1010    void readAndProcessPatchFile();
    1111private:
     
    1414    pugi::xml_document document;
    1515    pugi::xml_node rootNode;
    16     bool backupsEnabled;
     16    bool backupsEnabled, verboseEnabled;
    1717    QString getPatchParameterValue(const QString& line, QString parameter);
    1818    void insertNodesOperation(const QString &xmlString, XmlFilter &filters, const QString &xPathExpression, const QString &filesWildcard="");
  • XmlTools2/trunk/xmltools.cpp

    r920 r923  
    22
    33// Filters constructor
    4 XmlTools::XmlTools(QString filesWildcard, XmlFilter filter, bool noBackups)
     4XmlTools::XmlTools(QString filesWildcard, XmlFilter filter, bool noBackups, bool noVerbose)
    55{
    66    this->filesToProcess=UtilXmlTools::getAllXmlFilesByWildcard(filesWildcard);
    77    this->filters=filter;
    88    this->backupsEnabled=!noBackups;
     9    this->verboseEnabled=!noVerbose;
    910
    1011    if(this->filesToProcess.isEmpty()){
     
    1415
    1516// XPath constructor
    16 XmlTools::XmlTools(QString filesWildcard, QString xPathExpression, bool noBackups)
     17XmlTools::XmlTools(QString filesWildcard, QString xPathExpression, bool noBackups, bool noVerbose)
    1718{
    1819    this->filesToProcess=UtilXmlTools::getAllXmlFilesByWildcard(filesWildcard);
    1920    this->xPathExpression=xPathExpression;
    2021    this->backupsEnabled=!noBackups;
     22    this->verboseEnabled=!noVerbose;
    2123}
    2224
     
    3032        QList<pugi::xml_node> elements;
    3133
    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");
    3335
    3436        newValuesList=Util::qStringListFromSpacedString(newValues);
     
    7173        bool elementChanged=false;
    7274
    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");
    7476
    7577        // Check how the elements will be fetched via element name or xpath expression
     
    118120        bool elementChanged=false;
    119121
    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");
    121123
    122124        // Check how the elements will be fetched via element name or xpath expression
     
    158160        QList<pugi::xml_node> elements;
    159161
    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");
    161163
    162164        // Check how the elements will be fetched via element name or xpath expression
     
    198200        MultiDimVar newXmlValue(0); // value that will update currValue
    199201
    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");
    201203
    202204        // Check how the elements will be fetched via element name or xpath expression
     
    242244    // Process all XmlFiles
    243245    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");
    245247
    246248        QList<pugi::xml_node> elements;
  • XmlTools2/trunk/xmltools.h

    r920 r923  
    2525{
    2626public:
    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);
    2929    void addValues(QString newValues);
    3030    void removeValues(QString valuesToRemove);
     
    4040    QString xPathExpression;
    4141    XmlFilter filters;
    42     bool backupsEnabled;
     42    bool backupsEnabled, verboseEnabled;
    4343};
    4444
Note: See TracChangeset for help on using the changeset viewer.