| 1 |
#include "converter.h" |
| 2 |
|
| 3 |
Converter::Converter(QString AppDir, Logger *myLogger, QStringList *myData) |
| 4 |
{ |
| 5 |
this->AppDir=AppDir; |
| 6 |
this->myLogger=myLogger; |
| 7 |
this->myData=myData; |
| 8 |
} |
| 9 |
|
| 10 |
void Converter::run() |
| 11 |
{ |
| 12 |
this->processHasKilled=false; |
| 13 |
this->myProcess = new QProcess(); |
| 14 |
QString result = QString(); |
| 15 |
QString errorMessage = ""; |
| 16 |
int numErrors=0; |
| 17 |
|
| 18 |
this->myLogger->writeString("Setting working dir. to "+this->AppDir+"."); |
| 19 |
myProcess->setWorkingDirectory(this->AppDir); // Set working directory (for work with AEI2/Mac OS) |
| 20 |
|
| 21 |
if(this->myData->size()!=1){ |
| 22 |
emit setupPB(this->myData->size()); |
| 23 |
} |
| 24 |
else{ |
| 25 |
emit setupPB(0); //Intermitent bar, we don't have any estimation when the task is done |
| 26 |
} |
| 27 |
|
| 28 |
for(int i=0; i<this->myData->size(); i++){ |
| 29 |
|
| 30 |
QString commands=this->myData->at(i); |
| 31 |
QString commandToExec; |
| 32 |
|
| 33 |
int currentIndex=0, nextIndex=0; |
| 34 |
|
| 35 |
while(true){ |
| 36 |
nextIndex=commands.indexOf(GlobalVars::OniSplitProcSeparator,currentIndex+1); |
| 37 |
|
| 38 |
commandToExec=commands.mid(currentIndex,(nextIndex-currentIndex)); |
| 39 |
this->myProcess->start(Util::getOniSplitExeName() +" "+commandToExec); |
| 40 |
this->myProcess->waitForFinished(-1); |
| 41 |
|
| 42 |
if(this->processHasKilled){ // If the process has killed there's no need to proceed with reading output or process more commands |
| 43 |
delete this->myProcess; //delete object and make pointer invalid |
| 44 |
this->myData->clear(); //clean list |
| 45 |
emit conversionAborted(); |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
result=this->myProcess->readAllStandardError(); |
| 50 |
|
| 51 |
if(!result.isEmpty()){ //if(!result.startsWith("Importing",Qt::CaseSensitive) && !result.startsWith("Importing",Qt::CaseSensitive)){ //case sensitive is faster |
| 52 |
//catch exception |
| 53 |
myLogger->writeString("Oni Split Error: \n"+this->myData->at(i)+"\n"+result); |
| 54 |
errorMessage=result; |
| 55 |
numErrors++; |
| 56 |
} |
| 57 |
|
| 58 |
if(nextIndex==-1){ //we got to the end, stop proccessing commands |
| 59 |
break; |
| 60 |
} |
| 61 |
currentIndex=nextIndex+1; //update currentIndex +1 for start after the separator |
| 62 |
} |
| 63 |
|
| 64 |
emit taskDone(); |
| 65 |
} |
| 66 |
|
| 67 |
delete this->myProcess; //delete object and make pointer invalid |
| 68 |
this->myData->clear(); //clean list |
| 69 |
|
| 70 |
//let's cut it a bit, complete error is in log file. |
| 71 |
if(errorMessage.size()>600){ |
| 72 |
//limit it at 400 characters (not counting the warning at the begin) |
| 73 |
errorMessage.remove(299,errorMessage.size()-600); |
| 74 |
errorMessage.insert(299,"\n \t ... \n"); |
| 75 |
errorMessage.insert(0,"This error was been shortened. \nSee the complete error at Vago log file.\n\n"); |
| 76 |
} |
| 77 |
|
| 78 |
emit resultConversion(errorMessage,numErrors); |
| 79 |
} |
| 80 |
|
| 81 |
// Kill the process if requested |
| 82 |
void Converter::terminateCurrProcess(){ |
| 83 |
this->myProcess->kill(); |
| 84 |
this->processHasKilled=true; |
| 85 |
this->myLogger->writeString("Received signal to kill current OniSplit operation (user requested)."); |
| 86 |
} |