| 1 |
#include "converter.h" |
| 2 |
|
| 3 |
Converter::Converter(Logger *myLogger, QStringList *myData) |
| 4 |
{ |
| 5 |
this->myLogger=myLogger; |
| 6 |
this->myData=myData; |
| 7 |
} |
| 8 |
|
| 9 |
void Converter::run() |
| 10 |
{ |
| 11 |
QProcess *myProcess = new QProcess(); |
| 12 |
QString result = QString(); |
| 13 |
QString errorMessage = ""; |
| 14 |
int numErrors=0; |
| 15 |
|
| 16 |
if(this->myData->size()!=1){ |
| 17 |
emit setupPB(this->myData->size()); |
| 18 |
} |
| 19 |
else{ |
| 20 |
emit setupPB(0); //Intermitent bar, we don't have any estimation when the task is done |
| 21 |
} |
| 22 |
|
| 23 |
//myProcess->setProcessChannelMode(QProcess::MergedChannels); //we want both stdout and stderr |
| 24 |
|
| 25 |
for(int i=0; i<this->myData->size(); i++){ |
| 26 |
|
| 27 |
QString commands=this->myData->at(i); |
| 28 |
QString commandToExec; |
| 29 |
|
| 30 |
int currentIndex=0, nextIndex=0; |
| 31 |
|
| 32 |
while(true){ |
| 33 |
nextIndex=commands.indexOf(GlobalVars::OniSplitProcSeparator,currentIndex+1); |
| 34 |
|
| 35 |
commandToExec=commands.mid(currentIndex,(nextIndex-currentIndex)); |
| 36 |
myProcess->start(GlobalVars::OniSplitExeName+" "+commandToExec); |
| 37 |
myProcess->waitForFinished(-1); |
| 38 |
result=myProcess->readAllStandardError(); |
| 39 |
|
| 40 |
if(!result.isEmpty()){ //if(!result.startsWith("Importing",Qt::CaseSensitive) && !result.startsWith("Importing",Qt::CaseSensitive)){ //case sensitive is faster |
| 41 |
//catch exception |
| 42 |
myLogger->writeString("Oni Split Error: \n"+this->myData->at(i)+"\n"+result); |
| 43 |
errorMessage=result; |
| 44 |
numErrors++; |
| 45 |
} |
| 46 |
|
| 47 |
if(nextIndex==-1){ //we got to the end, stop proccessing commands |
| 48 |
break; |
| 49 |
} |
| 50 |
currentIndex=nextIndex+1; //update currentIndex +1 for start after the separator |
| 51 |
} |
| 52 |
|
| 53 |
emit taskDone(); |
| 54 |
} |
| 55 |
|
| 56 |
delete myProcess; //delete object and make pointer invalid |
| 57 |
this->myData->clear(); //clean list |
| 58 |
|
| 59 |
//let's cut it a bit, complete error is in log file. |
| 60 |
if(errorMessage.size()>600){ |
| 61 |
//limit it at 400 characters (not counting the warning at the begin) |
| 62 |
errorMessage.remove(299,errorMessage.size()-600); |
| 63 |
errorMessage.insert(299,"\n \t ... \n"); |
| 64 |
errorMessage.insert(0,"This error was been shortened. \nSee the complete error at Vago log file.\n\n"); |
| 65 |
} |
| 66 |
|
| 67 |
emit resultConversion(errorMessage,numErrors); |
| 68 |
} |
| 69 |
|