Index: /XmlTools2/trunk/XmlTools.pro
===================================================================
--- /XmlTools2/trunk/XmlTools.pro	(revision 925)
+++ /XmlTools2/trunk/XmlTools.pro	(revision 926)
@@ -21,5 +21,6 @@
     multidimvar.cpp \
     utilxmltools.cpp \
-    xmlfilter.cpp
+    xmlfilter.cpp \
+    optionsparser.cpp
 
 HEADERS += main.h \
@@ -31,5 +32,6 @@
     multidimvar.h \
     utilxmltools.h \
-    xmlfilter.h
+    xmlfilter.h \
+    optionsparser.h
 
 OTHER_FILES +=
Index: /XmlTools2/trunk/main.cpp
===================================================================
--- /XmlTools2/trunk/main.cpp	(revision 925)
+++ /XmlTools2/trunk/main.cpp	(revision 926)
@@ -6,234 +6,10 @@
     QCoreApplication app(argc, argv);
 
+    // Set application parameters
     QCoreApplication::setApplicationName(GlobalVars::AppName);
     QCoreApplication::setApplicationVersion(GlobalVars::AppVersion);
 
-    QCommandLineParser parser;
-    parser.setApplicationDescription("Additional documentation can be found at: http://wiki.oni2.net/XmlTools");
-
-    XmlTools *myXmlTools;
-    QString filesWildCard, patchFilesWildCard, forceTargetFilesWildcard;
-    QString currentVal, newVal, diffOldNewVal, positions;
-    QString xPathExpression;
-    XmlFilter filters; // Filters
-
-    bool noBackups=false;
-    bool noVerbose=false;
-
-    QCommandLineOption addValuesOption(QStringList() << "a" << "add-values", "Add values to a set of XML elements.");
-    QCommandLineOption removeValuesOption(QStringList() << "remove-values", "Removes values from a set of XML elements.");
-    QCommandLineOption replaceValueOption(QStringList() << "replace-value", "Replaces 1 value in a set of XML elements.");
-    QCommandLineOption replaceAllValuesOption(QStringList() << "replace-all-values", "Replaces all values in a set of XML elements.");
-    QCommandLineOption updateElementsOption(QStringList() << "u" << "update-elements", "Updates all values in a set of XML elements.");
-    QCommandLineOption invertElementsOption(QStringList() << "i" << "invert-elements", "Inverts a set of XML elements.");
-
-    QCommandLineOption currentValOption(QStringList() << "c" << "current-val", "Current value(s) [use space as separator].","current-val");
-    QCommandLineOption newValOption(QStringList() << "n" << "new-val", "New value(s) [use space as separator].","new-val");
-    QCommandLineOption diffOldNewValueOption(QStringList() << "d" << "diff-old-new-val", "Difference between old and new value.","diff-old-new-val");
-    QCommandLineOption positionsValueOption(QStringList() << "positions", "Positions [use space as separator] [0-index based].","positions");
-
-    QCommandLineOption filesOption(QStringList() << "f" << "files", "XML files to process [wildcards supported].", "files");
-    QCommandLineOption patchFilesOption(QStringList() << "p" << "patch-files" , "Patch files to process [wildcards supported].", "patch-files");
-    QCommandLineOption forceTargetFilesOption(QStringList() << "force-target-files" , "Force the patch-files operation in the specified XML files. [wildcards supported].", "force-target-files");
-    QCommandLineOption elementNameOption(QStringList() << "e" << "element-name", "Name of the XML element(s) where processing will occur.", "element-name");
-    QCommandLineOption parentElementNameOption(QStringList() << "parent-element-name", "Name of the XML parent element of <element-name> [used as filter].", "parent-element-name");
-    QCommandLineOption attributeNameOption("attribute-name", "Attribute name of <element-name>  [used as filter].", "attribute-name");
-    QCommandLineOption attributeValueOption("attribute-value", "Attribute value of <attribute-name>  [used as filter].", "attribute-value");
-    QCommandLineOption xPathExpressionOption(QStringList() << "x" << "xpath-expression", "XPath 1.0 expression to select elements where processing will occur.", "xpath-expression");
-    QCommandLineOption noBackupsOption(QStringList()  << "no-backups", "No backups [faster processing].");
-    QCommandLineOption noVerboseOption(QStringList()  << "no-verbose", "Reduce the number of text messages output [faster processing].");
-
-    parser.addOption(addValuesOption);
-    parser.addOption(removeValuesOption);
-    parser.addOption(replaceValueOption);
-    parser.addOption(replaceAllValuesOption);
-    parser.addOption(updateElementsOption);
-    parser.addOption(invertElementsOption);
-
-    parser.addOption(currentValOption);
-    parser.addOption(newValOption);
-    parser.addOption(diffOldNewValueOption);
-    parser.addOption(positionsValueOption);
-
-    parser.addOption(filesOption);
-    parser.addOption(patchFilesOption);
-    parser.addOption(forceTargetFilesOption);
-    parser.addOption(elementNameOption);
-    parser.addOption(parentElementNameOption);
-    parser.addOption(attributeNameOption);
-    parser.addOption(attributeValueOption);
-    parser.addOption(xPathExpressionOption);
-    parser.addOption(noBackupsOption);
-    parser.addOption(noVerboseOption);
-
-    parser.addVersionOption();
-    parser.addHelpOption();
-
-    // Process the actual command line arguments given by the user
-    parser.process(app);
-
-    // If no arguments show help option
-    if(app.arguments().size()==1){
-        parser.showHelp();
-    }
-
-    // Check if the user doesn't want backups (it boosts XmlTools peformance, lower disk output)
-    if(parser.isSet(noBackupsOption)){
-        noBackups=true;
-    }
-
-    // Check if the user doesn't want verbose mode (it boosts XmlTools peformance, lower std output)
-    if(parser.isSet(noVerboseOption)){
-        noVerbose=true;
-    }
-
-    // Get patch files wildcard if available
-    if(parser.isSet(patchFilesOption)){
-        patchFilesWildCard=parser.value(patchFilesOption);
-
-        // Never reached
-        //        if(patchFilesWildCard==""){
-        //            UtilXmlTools::displayErrorMessage("Parameter Parsing", "patch-files option requires 1 value: <patch-files> the patch files to process (wildcards supported).");
-        //        }
-
-        forceTargetFilesWildcard=parser.value(forceTargetFilesOption);
-
-
-        XmlPatch myXmlPatch(patchFilesWildCard,forceTargetFilesWildcard,noBackups,noVerbose);
-        myXmlPatch.readAndProcessPatchFile(); // beging file patch processing
-
-        return 0;
-    }
-
-    if(!parser.isSet(elementNameOption) && !parser.isSet(xPathExpressionOption)){
-        UtilXmlTools::displayErrorMessage("Parameter Parsing","element-name option or xpath-expression option is required if not using patch-files option.");
-    }
-    else if(parser.isSet(elementNameOption) && parser.isSet(xPathExpressionOption)){
-        UtilXmlTools::displayErrorMessage("Parameter Parsing","element-name option and xpath-expression options cannot be used simultaneously.");
-    }
-
-    // Get element name if available
-    if(parser.isSet(elementNameOption)){
-        filters.setElementName(parser.value(elementNameOption));
-    }
-
-    // Get xpath expression if available
-    if(parser.isSet(xPathExpressionOption)){
-        xPathExpression=parser.value(xPathExpressionOption);
-    }
-
-    // Get current value(s) if avaialabe
-    if(parser.isSet(currentValOption)){
-        currentVal=parser.value(currentValOption);
-    }
-
-    // Get new value(s) if avaialabe
-    if(parser.isSet(newValOption)){
-        newVal=parser.value(newValOption);
-    }
-
-    // Get difference between old and new value if avaialabe
-    if(parser.isSet(diffOldNewValueOption)){
-        diffOldNewVal=parser.value(diffOldNewValueOption);
-    }
-
-    // Get positions if avaialabe
-    if(parser.isSet(positionsValueOption)){
-        positions=parser.value(positionsValueOption);
-    }
-
-    // Get parent element name if available
-    if(parser.isSet(parentElementNameOption)){
-        filters.setParentElementName(parser.value(parentElementNameOption));
-    }
-
-    // Get attribute name if available
-    if(parser.isSet(attributeNameOption)){
-        filters.setAttributeName(parser.value(attributeNameOption));
-    }
-
-    // Get attribute value if available
-    if(parser.isSet(attributeValueOption)){
-        filters.setAttributeValue(parser.value(attributeValueOption));
-    }
-
-    // Check attribute filters
-    if(filters.getAttributeName()!="" && filters.getAttributeValue()==""){
-        UtilXmlTools::displayErrorMessage("Parameter Parsing","attribute-value option is required if using attribute-name option.");
-    }
-
-    if(filters.getAttributeValue()!="" && filters.getAttributeName()==""){
-        UtilXmlTools::displayErrorMessage("Parameter Parsing","attribute-name option is required if using attribute-value option.");
-    }
-
-    // Get files wildcard if available
-    if(parser.isSet(filesOption)){
-        filesWildCard=parser.value(filesOption);
-    }
-    else{
-        UtilXmlTools::displayErrorMessage("Parameter Parsing", "files option requires 1 value: <files> the XML files to process (wildcards supported).");
-    }
-
-    if(parser.isSet(elementNameOption)){
-        myXmlTools=new XmlTools(filesWildCard,filters,noBackups,noVerbose);
-    }
-    else{
-        myXmlTools=new XmlTools(filesWildCard,xPathExpression,noBackups,noVerbose);
-    }
-
-
-    // Users wants an add-option?
-    if(parser.isSet(addValuesOption)){
-
-        if(newVal==""){
-            UtilXmlTools::displayErrorMessage("Parameter Parsing", "add-value option requires 1 value: <new-val> the new values to add (space separated).");
-        }
-
-        myXmlTools->addValues(newVal);
-    }
-    else if(parser.isSet(removeValuesOption)){ // Or remove-values option?
-
-        if(currentVal==""){
-            UtilXmlTools::displayErrorMessage("Parameter Parsing","remove-values option requires 1 value: <current-val> the current values to remove (space separated).");
-        }
-
-        myXmlTools->removeValues(currentVal);
-    }
-    else if(parser.isSet(replaceValueOption)){ // Or replace-value option?
-
-        if(currentVal=="" || newVal==""){
-            UtilXmlTools::displayErrorMessage("Parameter Parsing","replace-value option requires 2 values: <current-val> the current value and <new-val> the new value.");
-        }
-
-        myXmlTools->replaceValue(currentVal,newVal);
-    }
-    else if(parser.isSet(replaceAllValuesOption)){ // Or replace-all-values option?
-
-        if(newVal=="" && positions==""){
-            UtilXmlTools::displayErrorMessage("Parameter Parsing","replace-all-values option requires 1 value: <new-val> the new value.\n" +
-                                              Util::toQString("It has also 1 optional value: <positions> the positions to replace (space separated and 0-index based)."));
-        }
-
-        myXmlTools->replaceAll(newVal,positions);
-    }
-    else if(parser.isSet(updateElementsOption)){ // Or update-elements option?
-
-        if(diffOldNewVal==""){
-            UtilXmlTools::displayErrorMessage("Parameter Parsing","update-elements option requires 1 value: <diff-old-new-val> the difference between one current element "+
-                                              Util::toQString("value and one new element value (current value and new value must have the same position)."));
-        }
-
-        myXmlTools->updateElements(diffOldNewVal);
-    }
-    else if(parser.isSet(invertElementsOption)){ // Or invert-elements option?
-        myXmlTools->invertElements();
-    }
-    else{
-        UtilXmlTools::displayErrorMessage("Parameter Parsing","One operation is required to XmlTools continue. Possible operations are:\n"+
-                                          Util::toQString("--patch-files\n--add-values\n--remove-values\n--replace-value\n--replace-all-values\n--update-elements\n--invert-elements"));
-    }
-
-    //delete myXmlTools;
-    //std::cout << "Started" << std::endl;
+    OptionsParser myParser(app.arguments());
+    myParser.parse();
 
     //app.exec();
Index: /XmlTools2/trunk/main.h
===================================================================
--- /XmlTools2/trunk/main.h	(revision 925)
+++ /XmlTools2/trunk/main.h	(revision 926)
@@ -1,6 +1,4 @@
 #ifndef MAIN_H
 #define MAIN_H
-
-#include "xmlpatch.h"
 
 #ifdef __MINGW32__
@@ -11,10 +9,10 @@
 unsigned long _CRT_glob = 0; // Magic variable to disable wildcards expansion in mingw
 // in our case fixes param parser crashes on windows
+
+#include "optionsparser.h"
+
 #endif
 
 int main(int argc, char *argv[]);
 
-void invert(std::string elementName, std::string parElementName);
-
-
 #endif // MAIN_H
Index: /XmlTools2/trunk/readme.txt
===================================================================
--- /XmlTools2/trunk/readme.txt	(revision 925)
+++ /XmlTools2/trunk/readme.txt	(revision 926)
@@ -62,5 +62,5 @@
 Change Log:
 ----------------------------------
-2.0, 04-02-2014
+2.0, 05-02-2014
 -Rewrite XmlTools fom the scratch from C# to C++ in order to increase (much!) the performance of the program
 -The program now uses the following libraries: Qt5, pugixml and jsxml js library
@@ -76,2 +76,3 @@
 -Added option to select xml elements by XPath 1.0 (should reduce further the need of javascript)
 -The insertion of xml via patch now support multiple nodes inside <xml></xml> tags
+-Added exclusive option for AEI which allows AEI to pass a list of .oni-patches to process
Index: /XmlTools2/trunk/util.h
===================================================================
--- /XmlTools2/trunk/util.h	(revision 925)
+++ /XmlTools2/trunk/util.h	(revision 926)
@@ -6,4 +6,5 @@
 #include <QString>
 #include <QStringList>
+#include <QRegExp>
 #include <iostream> // cout, cin etc.
 
@@ -50,4 +51,15 @@
 }
 
+inline QStringList QStringToArgsArray(const QString &args){
+    QStringList result;
+    result=Util::substring(args," ");
+
+    for(int i=0; i<result.size(); i++){
+        result[i].remove('"'); // remove quotes, they are not necessary as we had already splited the spaces
+    }
+
+    return result;
+}
+
 }
 
Index: /XmlTools2/trunk/xmlpatch.cpp
===================================================================
--- /XmlTools2/trunk/xmlpatch.cpp	(revision 925)
+++ /XmlTools2/trunk/xmlpatch.cpp	(revision 926)
@@ -100,5 +100,5 @@
             for (pugi::xml_node currNodeToInsert = newNode.first_child(); currNodeToInsert; currNodeToInsert = currNodeToInsert.next_sibling())
             {
-               nodesToInsertion[j].append_copy(currNodeToInsert); // append the new node
+                nodesToInsertion[j].append_copy(currNodeToInsert); // append the new node
             }
 
@@ -188,27 +188,24 @@
 void XmlPatch::executeCommandOperation(const QString &commandString){
 
-    QProcess newXmlToolsInstance;
-    QString resultOutput;
-
     // Avoid infinite fork loops
-    if(commandString.contains(" -p ") || commandString.contains(" --patch-files ")){
+    if(commandString.contains("-p ") || commandString.contains("--patch-files ")){
         UtilXmlTools::displayErrorMessage("@COMMAND","Use of --patch-files option is not allowed inside a patch file");
     }
 
-    newXmlToolsInstance.start(GlobalVars::AppExecutable + " " + commandString);
-    newXmlToolsInstance.waitForFinished(-1); // wait for new instance to finish
-
-    resultOutput=newXmlToolsInstance.readAll();
-
-    if(newXmlToolsInstance.exitCode()!=0){
-        UtilXmlTools::displayErrorMessage("@COMMAND", "An error ocurred:\n" + resultOutput);
-        exit(1);
+    // Reserved to AEI
+    if(commandString.contains("--aei-patch-files-list ")){
+        UtilXmlTools::displayErrorMessage("@COMMAND","Use of --aei-patch-files-list option is not allowed inside a patch file");
     }
 
     std::cout << "@COMMAND patch operation output:\n"
-              << "########################################################################\n"
-              << resultOutput.toLatin1().constData()
-              << "########################################################################"
-              << std::endl;
+    << "########################################################################"
+    << std::endl;
+
+    OptionsParser myParser(Util::QStringToArgsArray(commandString));
+    myParser.parse();
+
+    std::cout
+    << "########################################################################"
+    << std::endl;
 
     UtilXmlTools::displaySuccessMessage(1,"@COMMAND");
@@ -426,5 +423,21 @@
         else if(line.startsWith("@COMMAND")){
 
-            command=getPatchParameterValue(line,"Arguments");
+            command=GlobalVars::AppExecutable;
+
+            // Append files if forced to
+            if(!this->forceTargetFilesWildcard.isEmpty()){
+                command+=" --files '"+this->forceTargetFilesWildcard+"' ";
+            }
+
+            command+=" "+getPatchParameterValue(line,"Options");
+
+            // Add --no-backups and --no-verbose if patch was called with that arguments
+            if(!this->backupsEnabled){
+                command.append(" --no-backups");
+            }
+
+            if(!this->verboseEnabled){
+                command.append(" --no-verbose");
+            }
 
             command.replace("'","\""); //replace apostrophe by quotes, to avoid problems
@@ -433,4 +446,5 @@
 
             command.clear();
+            filesWildcard.clear();
         }
         else if(line.startsWith("@CUSTOM_CODE")){
Index: /XmlTools2/trunk/xmlpatch.h
===================================================================
--- /XmlTools2/trunk/xmlpatch.h	(revision 925)
+++ /XmlTools2/trunk/xmlpatch.h	(revision 926)
@@ -3,9 +3,10 @@
 
 #include "xmltools.h"
+#include "optionsparser.h"
 
 class XmlPatch
 {
 public:
-    XmlPatch(QString patchFilesWildcard, QString forceTargetFilesWildcard, bool backupsEnabled, bool noVerbose);
+    XmlPatch(QString patchFilesWildcard, QString forceTargetFilesWildcard, bool noBackups, bool noVerbose);
     void readAndProcessPatchFile();
 private:
